-
Notifications
You must be signed in to change notification settings - Fork 378
/
schematic.runner.spec.ts
50 lines (39 loc) 路 1.5 KB
/
schematic.runner.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import * as path from 'path';
const withSep = (route: string) =>
path.resolve(route.split('/').join(path.sep));
const existsSyncTrueForPathMock = (pathToExist: string) => {
pathToExist = withSep(pathToExist);
return (pathToCheck: string) => pathToCheck === pathToExist;
};
const getModulePathsMock = (fullPath: string) => {
const moduleLoaderPaths: string[] = [];
const fullPathBits = fullPath.split(path.sep);
while (--fullPathBits.length !== 0) {
if (fullPathBits[fullPathBits.length - 1] === 'node_modules') {
continue;
}
const modulePath = [...fullPathBits, 'node_modules'].join(path.sep);
moduleLoaderPaths.push(modulePath);
}
return () => moduleLoaderPaths;
};
describe('SchematicRunner', () => {
describe('Mocking Checks', () => {
describe('existsSyncTrueForPathMock', () => {
it('it should return true only for one specific path', () => {
const truePath = withSep('/this/path/exists');
const wrongPath = withSep('/this/path/doesnt/exist');
const existsSync = existsSyncTrueForPathMock(truePath);
expect(existsSync(truePath)).toBe(true);
expect(existsSync(wrongPath)).toBe(false);
});
});
describe('getModulePathsMock', () => {
it('it should return the same array as the module.paths module-local field', () => {
const realModulePath = module.paths;
const mockedModulePath = getModulePathsMock(__filename)();
expect(mockedModulePath).toEqual(realModulePath);
});
});
});
});