fix: make promisify working by mocking the entire file-system

This commit is contained in:
Convly 2023-12-14 11:54:11 +01:00
parent f646f9ceda
commit 1f39b5b904
3 changed files with 14 additions and 13 deletions

View File

@ -49,9 +49,11 @@
},
"devDependencies": {
"@strapi/pack-up": "4.15.5",
"@strapi/plugin-upload": "4.15.5",
"@types/jest": "29.5.2",
"eslint-config-custom": "4.15.5",
"tsconfig": "4.15.5"
"tsconfig": "4.15.5",
"memfs": "4.6.0"
},
"engines": {
"node": ">=18.0.0 <=20.x.x",

View File

@ -1,22 +1,20 @@
/* eslint-disable import/first */
import { fs } from 'memfs';
jest.mock('fs', () => fs);
import fse from 'fs-extra';
import type { File } from '@strapi/plugin-upload';
import localProvider from '../index';
jest.mock('fs', () => {
return {
writeFile: jest.fn((_path, _buffer, callback) => callback()),
};
});
jest.mock('fs-extra', () => {
return {
pathExistsSync: jest.fn(() => true),
};
});
describe('Local provider', () => {
beforeAll(() => {
globalThis.strapi = {};
globalThis.strapi.dirs = { static: { public: '' } };
fse.ensureDirSync('uploads');
});
afterAll(() => {

View File

@ -9790,6 +9790,7 @@ __metadata:
resolution: "@strapi/provider-upload-local@workspace:packages/providers/upload-local"
dependencies:
"@strapi/pack-up": "npm:4.15.5"
"@strapi/plugin-upload": "npm:4.15.5"
"@strapi/utils": "npm:4.15.5"
"@types/jest": "npm:29.5.2"
eslint-config-custom: "npm:4.15.5"