feat: support workspace configs

This commit is contained in:
Igor Randjelovic
2021-03-11 16:19:05 +01:00
parent 567a7ed25c
commit 437c3b41f9
12 changed files with 410 additions and 62 deletions

View File

@@ -1,42 +0,0 @@
import dedent from 'ts-dedent';
const mockedFiles: { [path: string]: string } = {};
export function mockFile(path, content) {
const unionFS = require('unionfs').default;
const Volume = require('memfs').Volume;
// reset to fs
unionFS.reset();
// add mocked file
mockedFiles[path] = dedent(content);
// create new volume
const vol = Volume.fromJSON(mockedFiles, '__jest__');
// use the new volume
unionFS.use(vol as any);
}
// a virtual mock for package.json
jest.mock(
'__jest__/package.json',
() => ({
main: 'src/app.js',
devDependencies: {
typescript: '*',
},
}),
{ virtual: true }
);
jest.mock('fs', () => {
const fs = jest.requireActual('fs');
const unionFS = require('unionfs').default;
unionFS.reset = () => {
unionFS.fss = [fs];
};
return unionFS.use(fs);
});

View File

@@ -1,4 +1,3 @@
import './jest.mockFiles';
// we are mocking the cwd for the tests, since webpack needs absolute paths
// and we don't want them in tests
process.cwd = () => '__jest__';
@@ -65,3 +64,15 @@ jest.mock('path', () => {
},
};
});
// a virtual mock for package.json
jest.mock(
'__jest__/package.json',
() => ({
main: 'src/app.js',
devDependencies: {
typescript: '*',
},
}),
{ virtual: true }
);