Skip to content

Commit

Permalink
build: create temporary script for symbol extractor tests (#38819)
Browse files Browse the repository at this point in the history
Creates a temporary script to running all symbol extractor tests.

PR Close #38819
  • Loading branch information
josephperrott authored and AndrewKushnir committed Sep 14, 2020
1 parent 2bdfb14 commit dc4f858
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(dev-infra|packages|modules|scripts|tools)/**/*.+(js|ts)\"",
"public-api:check": "node goldens/public-api/manage.js test",
"public-api:update": "node goldens/public-api/manage.js accept",
"symbol-extractor:check": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js test",
"symbol-extractor:update": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js accept",
"ts-circular-deps": "ts-node --transpile-only -- dev-infra/ts-circular-dependencies/index.ts --config ./packages/circular-deps-test.conf.js",
"ts-circular-deps:check": "yarn -s ts-circular-deps check",
"ts-circular-deps:approve": "yarn -s ts-circular-deps approve",
Expand Down
14 changes: 11 additions & 3 deletions packages/core/test/bundling/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# Bundle

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

```
yarn bazel run --config=ivy //packages/core/test/bundling/cyclic_import:symbol_test.accept
yarn bazel run --config=ivy //packages/core/test/bundling/hello_world:symbol_test.accept
yarn bazel run --config=ivy //packages/core/test/bundling/injection:symbol_test.accept
yarn bazel run --config=ivy //packages/core/test/bundling/todo:symbol_test.accept
```
```

## Running all symbol tests
To run all symbol tests with one command, you can use the following scripts:

```
yarn run symbol-extractor:check
yarn run symbol-extractor:update
```
68 changes: 68 additions & 0 deletions tools/symbol-extractor/run_all_symbols_extractor_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @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
*/

// TODO(josephperrott): migrate golden testing to ng-dev toolset
const {spawnSync} = require('child_process');
const minimist = require('minimist');
const path = require('path');

// Remove all command line flags from the arguments.
const argv = minimist(process.argv.slice(2));
// The command the user would like to run, either 'accept' or 'test'
const USER_COMMAND = argv._[0];
// The shell command to query for all tests.
// Bazel targets for testing goldens
process.stdout.write('Gathering all symbol extractor targets');
const ALL_TEST_TARGETS =
spawnSync(
'yarn',
[
'-s', 'bazel', 'query', '--output', 'label',
`kind(nodejs_test, ...) intersect attr("tags", "symbol_extractor", ...)`
],
{encoding: 'utf8', shell: true, cwd: path.resolve(__dirname, '../..')})
.stdout.trim()
.split('\n')
.map(line => line.trim());
process.stdout.clearLine();
process.stdout.cursorTo(0);
// Bazel targets for generating goldens
const ALL_ACCEPT_TARGETS = ALL_TEST_TARGETS.map(test => `${test}.accept`);

/** Run the provided bazel commands on each provided target individually. */
function runBazelCommandOnTargets(command, targets, present) {
for (const target of targets) {
process.stdout.write(`${present}: ${target}`);
const commandResult =
spawnSync('yarn', ['-s', 'bazel', command, '--config=ivy', target], {encoding: 'utf8'});
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (commandResult.status) {
console.error(`Failed ${command}: ${target}`);
console.group();
console.error(commandResult.stdout || commandResult.stderr);
console.groupEnd();
} else {
console.info(`Successful ${command}: ${target}`);
}
}
}

switch (USER_COMMAND) {
case 'accept':
runBazelCommandOnTargets('run', ALL_ACCEPT_TARGETS, 'Running');
break;
case 'test':
runBazelCommandOnTargets('test', ALL_TEST_TARGETS, 'Testing');
break;
default:
console.warn('Invalid command provided.');
console.warn();
console.warn(`Run this script with either "accept" and "test"`);
break;
}

0 comments on commit dc4f858

Please sign in to comment.