test: display a diff when example_apckage.spec.ts fails to ease debugging (#22933)

PR Close #22933
This commit is contained in:
Victor Berchet
2018-03-22 10:37:43 -07:00
committed by Matias Niemelä
parent 838a610197
commit 4a075e885f
3 changed files with 22 additions and 2 deletions

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {createPatch} from 'diff';
import * as fs from 'fs';
import * as path from 'path';
@ -49,11 +50,20 @@ if (require.main === module) {
if (actual === expected) {
return;
}
// Compute the patch and strip the header
let patch =
createPatch(goldenFile, expected, actual, 'Golden file', 'Generated file', {context: 5});
const endOfHeader = patch.indexOf('\n', patch.indexOf('\n') + 1) + 1;
patch = patch.substring(endOfHeader);
fail(`example ng_package differs from golden file
Diff:
${patch}
Accept the new golden file:
bazel run ${process.env['BAZEL_TARGET']}.accept
`);
`);
});
});
}