MCPcopy
hub / github.com/angular/angular / createTestSupportFor

Function createTestSupportFor

packages/compiler-cli/test/test_support.ts:40–119  ·  view source on GitHub ↗
(basePath: string)

Source from the content-addressed store, hash-verified

38}
39
40function createTestSupportFor(basePath: string) {
41 // Typescript uses identity comparison on `paths` and other arrays in order to determine
42 // if program structure can be reused for incremental compilation, so we reuse the default
43 // values unless overridden, and freeze them so that they can't be accidentally changed somewhere
44 // in tests.
45 const defaultCompilerOptions = {
46 basePath,
47 'experimentalDecorators': true,
48 'skipLibCheck': true,
49 'strict': true,
50 'strictPropertyInitialization': false,
51 'types': Object.freeze([] as string[]) as string[],
52 'outDir': path.resolve(basePath, 'built'),
53 'rootDir': basePath,
54 'declaration': true,
55 'target': ts.ScriptTarget.ES2015,
56 'newLine': ts.NewLineKind.LineFeed,
57 'module': ts.ModuleKind.NodeNext,
58 'moduleResolution': ts.ModuleResolutionKind.NodeNext,
59 'lib': Object.freeze([
60 path.resolve(basePath, 'node_modules/typescript/lib/lib.es6.d.ts'),
61 ]) as string[],
62 'paths': Object.freeze({'@angular/*': ['./node_modules/@angular/*']}) as {
63 [index: string]: string[];
64 },
65 };
66
67 return {
68 // We normalize the basePath into a posix path, so that multiple assertions which compare
69 // paths don't need to normalize the path separators each time.
70 basePath: normalizeSeparators(basePath),
71 write,
72 writeFiles,
73 createCompilerOptions,
74 shouldExist,
75 shouldNotExist,
76 };
77
78 function ensureDirExists(absolutePathToDir: string) {
79 if (fs.existsSync(absolutePathToDir)) {
80 if (!fs.statSync(absolutePathToDir).isDirectory()) {
81 throw new Error(`'${absolutePathToDir}' exists and is not a directory.`);
82 }
83 } else {
84 const parentDir = path.dirname(absolutePathToDir);
85 ensureDirExists(parentDir);
86 fs.mkdirSync(absolutePathToDir);
87 }
88 }
89
90 function write(fileName: string, content: string) {
91 const absolutePathToFile = path.resolve(basePath, fileName);
92 ensureDirExists(path.dirname(absolutePathToFile));
93 fs.writeFileSync(absolutePathToFile, content);
94 }
95
96 function writeFiles(...mockDirs: {[fileName: string]: string}[]) {
97 mockDirs.forEach((dir) => {

Callers 1

setupFunction · 0.85

Calls 2

normalizeSeparatorsFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…