Skip to content

Commit 618b4d5

Browse files
committed
Make the public API unit tests echo out a diff
1 parent 671029c commit 618b4d5

File tree

5 files changed

+15
-242
lines changed

5 files changed

+15
-242
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"chalk": "latest",
6666
"convert-source-map": "latest",
6767
"del": "5.1.0",
68+
"diff": "^4.0.2",
6869
"eslint": "6.8.0",
6970
"eslint-formatter-autolinkable-stylish": "1.1.2",
7071
"eslint-plugin-import": "2.20.2",

src/harness/harnessIO.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,7 @@ namespace Harness {
12931293
export interface BaselineOptions {
12941294
Subfolder?: string;
12951295
Baselinefolder?: string;
1296+
PrintDiff?: true;
12961297
}
12971298

12981299
export function localPath(fileName: string, baselineFolder?: string, subfolder?: string) {
@@ -1347,7 +1348,7 @@ namespace Harness {
13471348
return { expected, actual };
13481349
}
13491350

1350-
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string) {
1351+
function writeComparison(expected: string, actual: string, relativeFileName: string, actualFileName: string, opts?: BaselineOptions) {
13511352
// For now this is written using TypeScript, because sys is not available when running old test cases.
13521353
// But we need to move to sys once we have
13531354
// Creates the directory including its parent if not already present
@@ -1381,7 +1382,14 @@ namespace Harness {
13811382
else {
13821383
IO.writeFile(actualFileName, encodedActual);
13831384
}
1384-
throw new Error(`The baseline file ${relativeFileName} has changed.`);
1385+
if (require && opts && opts.PrintDiff) {
1386+
const Diff = require("diff");
1387+
const patch = Diff.createTwoFilesPatch("Expected", "Actual", expected, actual, "The current baseline", "The new version");
1388+
throw new Error(`The baseline file ${relativeFileName} has changed.\n\n${patch}`);
1389+
}
1390+
else {
1391+
throw new Error(`The baseline file ${relativeFileName} has changed.`);
1392+
}
13851393
}
13861394
}
13871395

@@ -1391,7 +1399,7 @@ namespace Harness {
13911399
throw new Error("The generated content was \"undefined\". Return \"null\" if no baselining is required.\"");
13921400
}
13931401
const comparison = compareToBaseline(actual, relativeFileName, opts);
1394-
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName);
1402+
writeComparison(comparison.expected, comparison.actual, relativeFileName, actualFileName, opts);
13951403
}
13961404

13971405
export function runMultifileBaseline(relativeFileBase: string, extension: string, generateContent: () => IterableIterator<[string, string, number]> | IterableIterator<[string, string]> | null, opts?: BaselineOptions, referencedExtensions?: string[]): void {

src/services/semanticClassification.ts

Lines changed: 0 additions & 237 deletions
This file was deleted.

src/services/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ namespace ts {
255255

256256
/*
257257
* Required for full import and type reference completions.
258-
* These should be unprefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`.
258+
* These should be un-prefixed names. E.g. `getDirectories("/foo/bar")` should return `["a", "b"]`, not `["/foo/bar/a", "/foo/bar/b"]`.
259259
*/
260260
getDirectories?(directoryName: string): string[];
261261

@@ -409,6 +409,7 @@ namespace ts {
409409

410410
getSmartSelectionRange(fileName: string, position: number): SelectionRange;
411411

412+
/** Test */
412413
getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
413414
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined;
414415
getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;

src/testRunner/unittests/publicApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("unittests:: Public APIs", () => {
1010
});
1111

1212
it("should be acknowledged when they change", () => {
13-
Harness.Baseline.runBaseline(api, fileContent);
13+
Harness.Baseline.runBaseline(api, fileContent, { PrintDiff: true });
1414
});
1515

1616
it("should compile", () => {

0 commit comments

Comments
 (0)