MCPcopy Create free account
hub / github.com/angular/components / createTestCaseSetup

Function createTestCaseSetup

src/cdk/schematics/testing/test-case-setup.ts:65–114  ·  view source on GitHub ↗
(
  migrationName: string,
  collectionPath: string,
  inputFiles: string[],
)

Source from the content-addressed store, hash-verified

63}
64
65export async function createTestCaseSetup(
66 migrationName: string,
67 collectionPath: string,
68 inputFiles: string[],
69) {
70 const runner = new SchematicTestRunner('schematics', collectionPath);
71
72 let logOutput = '';
73 runner.logger.subscribe(entry => (logOutput += `${entry.message}\n`));
74 const {appTree, writeFile} = await createFileSystemTestApp(runner);
75
76 patchDevkitTreeToExposeTypeScript(appTree);
77
78 // Write each test-case input to the file-system. This is necessary because otherwise
79 // TypeScript compiler API won't be able to pick up the test cases.
80 inputFiles.forEach(inputFilePath => {
81 const inputTestName = basename(inputFilePath, extname(inputFilePath));
82 const relativePath = `projects/cdk-testing/src/test-cases/${inputTestName}.ts`;
83 const inputContent = readFileContent(inputFilePath);
84
85 writeFile(relativePath, inputContent);
86 });
87
88 const testAppTsconfigPath = 'projects/cdk-testing/tsconfig.app.json';
89 // Parse TypeScript configuration files with JSONC (like the CLI does) as the
90 // config files could contain comments or trailing commas
91 const testAppTsconfig = parse(appTree.readContent(testAppTsconfigPath), [], {
92 allowTrailingComma: true,
93 });
94
95 // include all TypeScript files in the project. Otherwise all test input
96 // files won't be part of the program and cannot be migrated.
97 testAppTsconfig.include.push('src/**/*.ts');
98
99 writeFile(testAppTsconfigPath, JSON.stringify(testAppTsconfig, null, 2));
100
101 const runFixers = async function () {
102 // Patch "executePostTasks" to do nothing. This is necessary since
103 // we cannot run the node install task in unit tests. Rather we just
104 // assert that certain async post tasks are scheduled.
105 // TODO(devversion): RxJS version conflicts between angular-devkit and our dev deps.
106 runner.engine.executePostTasks = () => EMPTY as any;
107
108 await runner.runSchematic(migrationName, {}, appTree);
109
110 return {logOutput};
111 };
112
113 return {runner, appTree, writeFile, runFixers};
114}
115
116/**
117 * Resolves all test cases for specified path using Bazel's runfile manifest. Note that we

Callers 1

defineJasmineTestCasesFunction · 0.85

Calls 5

createFileSystemTestAppFunction · 0.85
readFileContentFunction · 0.85
writeFileFunction · 0.85
pushMethod · 0.65

Tested by

no test coverage detected