8000 build: create temporary script for symbol extractor tests (#38819) · angular/angular@dc4f858 · GitHub
[go: up one dir, main page]

Skip to content

Commit dc4f858

Browse files
josephperrottAndrewKushnir
authored andcommitted
build: create temporary script for symbol extractor tests (#38819)
Creates a temporary script to running all symbol extractor tests. PR Close #38819
1 parent 2bdfb14 commit dc4f858

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(dev-infra|packages|modules|scripts|tools)/**/*.+(js|ts)\"",
3636
"public-api:check": "node goldens/public-api/manage.js test",
3737
"public-api:update": "node goldens/public-api/manage.js accept",
38+
"symbol-extractor:check": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js test",
39+
"symbol-extractor:update": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js accept",
3840
"ts-circular-deps": "ts-node --transpile-only -- dev-infra/ts-circular-dependencies/index.ts --config ./packages/circular-deps-test.conf.js",
3941
"ts-circular-deps:check": "yarn -s ts-circular-deps check",
4042
"ts-circular-deps:approve": "yarn -s ts-circular-deps approve",

packages/core/test/bundling/README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
# Bundle
22

33
## `js_expected_symbol_test`
4-
This folder contains tests which assert that most of the code is tree shaken away.
5-
This is asserted by keeping gold files of all symbols which are expected to be retained.
4+
This folder contains tests which assert that most of the code is tree shaken away.
5+
This is asserted by keeping gold files of all symbols which are expected to be retained.
66
When doing renaming it is often necessary to update the gold files, to do so use these commands:
77

88
```
99
yarn bazel run --config=ivy //packages/core/test/bundling/cyclic_import:symbol_test.accept
1010
yarn bazel run --config=ivy //packages/core/test/bundling/hello_world:symbol_test.accept
1111
yarn bazel run --config=ivy //packages/core/test/bundling/injection:symbol_test.accept
1212
yarn bazel run --config=ivy //packages/core/test/bundling/todo:symbol_test.accept
13-
```
13+
```
14+
15+
## Running all symbol tests
16+
To run all symbol tests with one command, you can use the following scripts:
17+
18+
```
19+
yarn run symbol-extractor:check
20+
yarn run symbol-extractor:update
21+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
// TODO(josephperrott): migrate golden testing to ng-dev toolset
10+
const {spawnSync} = require('child_process');
11+
const minimist = require('minimist');
12+
const path = require('path');
13+
14+
// Remove all command line flags from the arguments.
15+
const argv = minimist(process.argv.slice(2));
16+
// The command the user would like to run, either 'accept' or 'test'
17+
const USER_COMMAND = argv._[0];
18+
// The shell command to query for all tests.
19+
// Bazel targets for testing goldens
20+
process.stdout.write('Gathering all symbol extractor targets');
21+
const ALL_TEST_TARGETS =
22+
spawnSync(
23+
'yarn',
24+
[
25+
'-s', 'bazel', 'query', '--output', 'label',
26+
`kind(nodejs_test, ...) intersect attr("tags", "symbol_extractor", ...)`
27+
],
28+
{encoding: 'utf8', shell: true, cwd: path.resolve(__dirname, '../..')})
29+
.stdout.trim()
30+
.split('\n')
31+
.map(line => line.trim());
32+
process.stdout.clearLine();
33+
process.stdout.cursorTo(0);
34+
// Bazel targets for generating goldens
35+
const ALL_ACCEPT_TARGETS = ALL_TEST_TARGETS.map(test => `${test}.accept`);
36+
37+
/** Run the provided bazel commands on each provided target individually. */
38+
function runBazelCommandOnTargets(command, targets, present) {
39+
for (const target of targets) {
40+
process.stdout.write(`${present}: ${target}`);
41+
const commandResult =
42+
spawnSync('yarn', ['-s', 'bazel', command, '--config=ivy', target], {encoding: 'utf8'});
43+
process.stdout.clearLine();
44+
process.stdout.cursorTo(0);
45+
if (commandResult.status) {
46+
console.error(`Failed ${command}: ${target}`);
47+
console.group();
48+
console.error(commandResult.stdout || commandResult.stderr);
49+
console.groupEnd();
50+
} else {
51+
console.info(`Successful ${command}: ${target}`);
52+
}
53+
}
54+
}
55+
56+
switch (USER_COMMAND) {
57+
case 'accept':
58+
runBazelCommandOnTargets('run', ALL_ACCEPT_TARGETS, 'Running');
59+
break;
60+
case 'test':
61+
runBazelCommandOnTargets('test', ALL_TEST_TARGETS, 'Testing');
62+
break;
63+
default:
64+
console.warn('Invalid command provided.');
65+
console.warn();
66+
console.warn(`Run this script with either "accept" and "test"`);
67+
break;
68+
}

0 commit comments

Comments
 (0)
0