mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat: support workspace configs
This commit is contained in:
@@ -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);
|
||||
});
|
||||
@@ -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 }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user