2018-02-02 18:08:25 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. 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 * as fs from 'fs';
|
|
|
|
import {SymbolExtractor} from './symbol_extractor';
|
|
|
|
|
2020-03-29 16:29:50 -04:00
|
|
|
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER'] as string);
|
|
|
|
|
2018-02-02 18:08:25 -05:00
|
|
|
if (require.main === module) {
|
|
|
|
const args = process.argv.slice(2) as[string, string];
|
2018-03-21 13:55:14 -04:00
|
|
|
process.exitCode = main(args) ? 0 : 1;
|
2018-02-02 18:08:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLI main method.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* cli javascriptFilePath.js goldenFilePath.json
|
|
|
|
* ```
|
|
|
|
*/
|
2018-03-21 13:55:14 -04:00
|
|
|
function main(argv: [string, string, string] | [string, string]): boolean {
|
2020-03-29 16:29:50 -04:00
|
|
|
const javascriptFilePath = runfiles.resolveWorkspaceRelative(argv[0]);
|
|
|
|
const goldenFilePath = runfiles.resolveWorkspaceRelative(argv[1]);
|
2018-03-21 13:55:14 -04:00
|
|
|
const doUpdate = argv[2] == '--accept';
|
2018-02-02 18:08:25 -05:00
|
|
|
|
|
|
|
const javascriptContent = fs.readFileSync(javascriptFilePath).toString();
|
|
|
|
const goldenContent = fs.readFileSync(goldenFilePath).toString();
|
|
|
|
|
|
|
|
const symbolExtractor = new SymbolExtractor(javascriptFilePath, javascriptContent);
|
|
|
|
|
|
|
|
let passed: boolean = false;
|
|
|
|
if (doUpdate) {
|
|
|
|
fs.writeFileSync(goldenFilePath, JSON.stringify(symbolExtractor.actual, undefined, 2));
|
|
|
|
console.error('Updated gold file:', goldenFilePath);
|
|
|
|
passed = true;
|
|
|
|
} else {
|
|
|
|
passed = symbolExtractor.compareAndPrintError(goldenFilePath, goldenContent);
|
|
|
|
if (!passed) {
|
2019-11-22 15:11:48 -05:00
|
|
|
const ivyEnabled = process.env['angular_ivy_enabled'] == 'True';
|
2018-02-02 18:08:25 -05:00
|
|
|
console.error(`TEST FAILED!`);
|
|
|
|
console.error(` To update the golden file run: `);
|
2019-11-22 15:11:48 -05:00
|
|
|
console.error(
|
|
|
|
` yarn bazel run --config=${ivyEnabled ? 'ivy' : 'view-engine'} ${process.env['TEST_TARGET']}.accept`);
|
2018-02-02 18:08:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return passed;
|
|
|
|
}
|