|
| 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