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

@ -40,6 +40,7 @@
"@types/angularjs": "1.5.14-alpha",
"@types/base64-js": "1.2.5",
"@types/chokidar": "1.7.3",
"@types/diff": "^3.2.2",
"@types/fs-extra": "4.0.2",
"@types/hammerjs": "2.0.35",
"@types/jasmine": "2.2.22-alpha",
@ -64,6 +65,7 @@
"cldrjs": "0.5.0",
"conventional-changelog": "1.1.0",
"cors": "2.8.4",
"diff": "^3.5.0",
"domino": "2.0.1",
"entities": "1.1.1",
"firebase-tools": "3.12.0",

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
`);
`);
});
});
}

View File

@ -91,6 +91,10 @@
dependencies:
"@types/node" "*"
"@types/diff@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-3.2.2.tgz#4d6f45537322a7a420d353a0939513c7e96d14a6"
"@types/events@*":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.1.0.tgz#93b1be91f63c184450385272c47b6496fd028e02"
@ -1959,6 +1963,10 @@ diff@^3.2.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.3.1.tgz#aa8567a6eed03c531fc89d3f711cd0e5259dec75"
diff@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
doctrine@^0.7.2:
version "0.7.2"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-0.7.2.tgz#7cb860359ba3be90e040b26b729ce4bfa654c523"