Skip to content

Commit

Permalink
refactor(compiler-cli): add script to update all golden partial files (
Browse files Browse the repository at this point in the history
…angular#39989)

The golden files for the partial compliance tests need to be updated
with individual Bazel run invocations, which is not very ergonomic when
a large number of golden files need to updated. This commit adds a
script to query the Bazel targets that update the goldens and then runs
those targets sequentially.

PR Close angular#39989
  • Loading branch information
JoostK authored and mhevery committed Dec 8, 2020
1 parent b8714c3 commit 3ec2807
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/compiler-cli/test/compliance/README.md
Expand Up @@ -185,6 +185,11 @@ bazel run //packages/compiler-cli/test/compliance/test_cases:<path/to/test_case>
where to replace `<path/to/test_case>` with the path (relative to `test_cases`) of the directory
that contains the `GOLDEN_PARTIAL.js` to update.

To update all golden partial files, the following command can be run:

```sh
node packages/compiler-cli/test/compliance/update_all_goldens.js
```

## Debugging test-cases

Expand Down
35 changes: 35 additions & 0 deletions packages/compiler-cli/test/compliance/update_all_goldens.js
@@ -0,0 +1,35 @@
#!/usr/bin/env node
/**
* @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
*/

// tslint:disable:no-console
const {exec} = require('shelljs');

process.stdout.write('Gathering all partial golden update targets');
const queryCommand =
`yarn -s bazel query --output label 'filter('golden.update', kind(nodejs_binary, //packages/compiler-cli/test/compliance/test_cases:*))'`;
const allUpdateTargets =
exec(queryCommand, {silent: true}).trim().split('\n').map(test => test.trim());
process.stdout.clearLine();
process.stdout.cursorTo(0);

for (const [index, target] of allUpdateTargets.entries()) {
const progress = `${index + 1} / ${allUpdateTargets.length}`;
process.stdout.write(`[${progress}] Running: ${target}`);
const commandResult = exec(`yarn -s bazel run ${target}`, {silent: true});
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (commandResult.code) {
console.error(`[${progress}] Failed run: ${target}`);
console.group();
console.error(commandResult.stdout || commandResult.stderr);
console.groupEnd();
} else {
console.log(`[${progress}] Successful run: ${target}`);
}
}

0 comments on commit 3ec2807

Please sign in to comment.