mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-18 05:18:39 +08:00
feat(webpack): default tsconfig.json if not found
This commit is contained in:
41
packages/webpack5/scripts/jest.utils.ts
Normal file
41
packages/webpack5/scripts/jest.utils.ts
Normal file
@ -0,0 +1,41 @@
|
||||
let mockedPaths = new Set([]);
|
||||
|
||||
export let fsExistsSyncSpy: jest.SpiedFunction<any>;
|
||||
|
||||
export function mockExistsSync() {
|
||||
const fs = require('fs');
|
||||
const original = fs.existsSync;
|
||||
fsExistsSyncSpy = jest.spyOn(fs, 'existsSync');
|
||||
|
||||
fsExistsSyncSpy.mockImplementation((path) => {
|
||||
if (mockedPaths.has(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return original.call(fs, path);
|
||||
});
|
||||
}
|
||||
|
||||
export function restoreExistsSync() {
|
||||
if (fsExistsSyncSpy) {
|
||||
fsExistsSyncSpy.mockRestore();
|
||||
}
|
||||
}
|
||||
|
||||
export function setHasTSConfig(value: boolean = true) {
|
||||
if (value) {
|
||||
mockedPaths.add('__jest__/tsconfig.json');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
mockedPaths.delete('__jest__/tsconfig.json');
|
||||
}
|
||||
|
||||
export function addMockFile(path: string) {
|
||||
mockedPaths.add(path);
|
||||
|
||||
return () => {
|
||||
mockedPaths.delete(path);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user