angular/packages/compiler-cli/test/compliance/partial/generate_golden_partial.ts
Paul Gschwendtner 9e3e970dbf test: refactor compiler-cli compliance test to work on windows (#45431)
Recent changes in `rules_nodejs` caused the test case copy file actions
to be transitioned into the `exec` configuration, resulting in much larger
file paths. These paths break on Windows with the shell argument limit, and
with the path limit, causing errors like:

```
ERROR: C:/users/circleci/ng/packages/compiler-cli/test/compliance/test_cases/BUILD.bazel:9:12: Copying file packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/structural_directives_if_directive_def.js failed: (Exit 1): cmd.exe failed: error executing command
  cd /d C:/users/circleci/_bazel_circleci/u4uoan2j/execroot/angular
  SET PATH=C:\Program Files\Git\usr\bin;C:\Program Files\Git\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0
    SET RUNFILES_MANIFEST_ONLY=1
  cmd.exe /C bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\packages\compiler-cli\test\compliance\test_cases\test_cases--1973427149-cmd.bat
The system cannot find the path specified
```

https://app.circleci.com/pipelines/github/angular/angular/44038/workflows/4b530cb2-f232-4e1d-b35a-e6e085151d08/jobs/1140017

PR Close #45431
2022-03-25 12:18:34 -07:00

59 lines
2.1 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system';
import {compileTest, getBuildOutputDirectory, initMockTestFileSystem} from '../test_helpers/compile_test';
import {ComplianceTest, getComplianceTests} from '../test_helpers/get_compliance_tests';
import {PartiallyCompiledFile, renderGoldenPartial} from '../test_helpers/golden_partials';
/**
* Generate the golden partial output for the tests described in the `testConfigPath` config file.
*
* @param testConfigPath Absolute disk path of the `TEST_CASES.json` file that describes the tests.
*/
export function generateGoldenPartial(absTestConfigPath: AbsoluteFsPath): void {
const files: PartiallyCompiledFile[] = [];
const tests = getComplianceTests(absTestConfigPath);
for (const test of tests) {
const fs = initMockTestFileSystem(test.realTestPath);
for (const file of compilePartials(fs, test)) {
files.push(file);
}
}
writeGoldenPartial(files);
}
/**
* Partially compile the source files specified by the given `test`.
*
* @param fs The mock file-system to use when compiling partials.
* @param test The information about the test being compiled.
*/
function* compilePartials(fs: FileSystem, test: ComplianceTest): Generator<PartiallyCompiledFile> {
const builtDirectory = getBuildOutputDirectory(fs);
for (const generatedPath of compileTest(fs, test.inputFiles, test.compilerOptions, {
compilationMode: 'partial',
...test.angularCompilerOptions
}).emittedFiles) {
yield {
path: fs.relative(builtDirectory, generatedPath),
content: fs.readFile(generatedPath),
};
}
}
/**
* Write the partially compiled files to the appropriate output destination.
*
* For now just push the concatenated partial files to standard out.
*
* @param files The partially compiled files.
*/
function writeGoldenPartial(files: PartiallyCompiledFile[]): void {
// tslint:disable-next-line: no-console
console.log(renderGoldenPartial(files));
}