From 4a075e885faa391c1ebe0575da25f953efd96a42 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 22 Mar 2018 10:37:43 -0700 Subject: [PATCH] test: display a diff when example_apckage.spec.ts fails to ease debugging (#22933) PR Close #22933 --- package.json | 2 ++ .../bazel/test/ng_package/example_package.spec.ts | 14 ++++++++++++-- yarn.lock | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5613fdfb9f..ef732dfd26 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/bazel/test/ng_package/example_package.spec.ts b/packages/bazel/test/ng_package/example_package.spec.ts index 570cbdfc1e..05a6b6804a 100644 --- a/packages/bazel/test/ng_package/example_package.spec.ts +++ b/packages/bazel/test/ng_package/example_package.spec.ts @@ -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 - `); + `); }); }); } diff --git a/yarn.lock b/yarn.lock index bf1f30cb6f..8c6d86215a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"