Skip to content

Commit 79a1240

Browse files
weswighamAndy
authored and
Andy
committed
Revert merge pull request #20429 (removing chai) (#20654)
* Revert "Merge pull request #20429 from Microsoft/unchai" This reverts commit 66ec938, reversing changes made to 37a4056. * Update lockfile
1 parent edb9e97 commit 79a1240

33 files changed

+448
-430
lines changed

Diff for: Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ compileFile(
795795
/*prereqs*/[builtLocalDirectory, tscFile, tsserverLibraryFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
796796
/*prefixes*/[],
797797
/*useBuiltCompiler:*/ true,
798-
/*opts*/ { types: ["node", "mocha"], lib: "es6" });
798+
/*opts*/ { types: ["node", "mocha", "chai"], lib: "es6" });
799799

800800
var internalTests = "internal/";
801801

Diff for: package-lock.json

+137-82
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@types/browserify": "latest",
33+
"@types/chai": "latest",
3334
"@types/colors": "latest",
3435
"@types/convert-source-map": "latest",
3536
"@types/del": "latest",
@@ -52,6 +53,7 @@
5253
"xml2js": "^0.4.19",
5354
"browser-resolve": "^1.11.2",
5455
"browserify": "latest",
56+
"chai": "latest",
5557
"convert-source-map": "latest",
5658
"del": "latest",
5759
"gulp": "3.X",

Diff for: src/harness/fourslash.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ namespace FourSlash {
297297
const host = new Utils.MockParseConfigHost(baseDir, /*ignoreCase*/ false, this.inputFiles);
298298

299299
const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles.get(configFileName));
300-
assert(configJsonObj.config !== undefined);
300+
assert.isTrue(configJsonObj.config !== undefined);
301301

302302
const { options, errors } = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir);
303303

@@ -443,7 +443,7 @@ namespace FourSlash {
443443

444444
public goToEachMarker(action: () => void) {
445445
const markers = this.getMarkers();
446-
assert(markers.length !== 0);
446+
assert(markers.length);
447447
for (const marker of markers) {
448448
this.goToMarker(marker);
449449
action();
@@ -452,7 +452,7 @@ namespace FourSlash {
452452

453453
public goToEachRange(action: () => void) {
454454
const ranges = this.getRanges();
455-
assert(ranges.length !== 0);
455+
assert(ranges.length);
456456
for (const range of ranges) {
457457
this.goToRangeStart(range);
458458
action();
@@ -799,7 +799,7 @@ namespace FourSlash {
799799
}
800800

801801
const entries = this.getCompletionListAtCaret().entries;
802-
assert(items.length <= entries.length, `Amount of expected items in completion list [ ${items.length} ] is greater than actual number of items in list [ ${entries.length} ]`);
802+
assert.isTrue(items.length <= entries.length, `Amount of expected items in completion list [ ${items.length} ] is greater than actual number of items in list [ ${entries.length} ]`);
803803
ts.zipWith(entries, items, (entry, item) => {
804804
assert.equal(entry.name, item, `Unexpected item in completion list`);
805805
});
@@ -953,7 +953,7 @@ namespace FourSlash {
953953
public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string, tags?: ts.JSDocTagInfo[]) {
954954
const details = this.getCompletionEntryDetails(entryName);
955955

956-
assert.isDefined(details, "no completion entry available");
956+
assert(details, "no completion entry available");
957957

958958
assert.equal(ts.displayPartsToString(details.displayParts), expectedText, this.assertionMessageAtLastKnownMarker("completion entry details text"));
959959

@@ -1088,7 +1088,7 @@ namespace FourSlash {
10881088

10891089
public verifyRangesReferenceEachOther(ranges?: Range[]) {
10901090
ranges = ranges || this.getRanges();
1091-
assert(ranges.length !== 0);
1091+
assert(ranges.length);
10921092
for (const range of ranges) {
10931093
this.verifyReferencesOf(range, ranges);
10941094
}
@@ -1374,6 +1374,7 @@ Actual: ${stringify(fullActual)}`);
13741374

13751375
public verifyCurrentParameterIsVariable(isVariable: boolean) {
13761376
const signature = this.getActiveSignatureHelpItem();
1377+
assert.isOk(signature);
13771378
assert.equal(isVariable, signature.isVariadic);
13781379
}
13791380

@@ -2024,7 +2025,7 @@ Actual: ${stringify(fullActual)}`);
20242025
const implementations = this.languageService.getImplementationAtPosition(this.activeFile.fileName, this.currentCaretPosition);
20252026

20262027
if (negative) {
2027-
assert(implementations && implementations.length > 0, "Expected at least one implementation but got 0");
2028+
assert.isTrue(implementations && implementations.length > 0, "Expected at least one implementation but got 0");
20282029
}
20292030
else {
20302031
assert.isUndefined(implementations, "Expected implementation list to be empty but implementations returned");
@@ -3128,7 +3129,7 @@ Actual: ${stringify(fullActual)}`);
31283129

31293130
if (spanIndex !== undefined) {
31303131
const span = this.getTextSpanForRangeAtIndex(spanIndex);
3131-
assert(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + entryId));
3132+
assert.isTrue(TestState.textSpansEqual(span, item.replacementSpan), this.assertionMessageAtLastKnownMarker(stringify(span) + " does not equal " + stringify(item.replacementSpan) + " replacement span for " + entryId));
31323133
}
31333134

31343135
assert.equal(item.hasAction, hasAction);

Diff for: src/harness/harness.ts

+16-58
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,18 @@
2323
/// <reference path="virtualFileSystem.ts" />
2424
/// <reference types="node" />
2525
/// <reference types="mocha" />
26+
/// <reference types="chai" />
27+
2628

2729
// Block scoped definitions work poorly for global variables, temporarily enable var
2830
/* tslint:disable:no-var-keyword */
2931

30-
function assert(expr: boolean, msg?: string | (() => string)): void {
31-
if (!expr) {
32-
throw new Error(typeof msg === "string" ? msg : msg());
33-
}
34-
}
35-
namespace assert {
36-
export function isFalse(expr: boolean, msg = "Expected value to be false."): void {
37-
assert(!expr, msg);
38-
}
39-
export function equal<T>(a: T, b: T, msg?: string): void {
40-
assert(a === b, msg || (() => `Expected to be equal:\nExpected:\n${JSON.stringify(a)}\nActual:\n${JSON.stringify(b)}`));
41-
}
42-
export function notEqual<T>(a: T, b: T, msg = "Expected values to not be equal."): void {
43-
assert(a !== b, msg);
44-
}
45-
export function isDefined(x: {} | null | undefined, msg = "Expected value to be defined."): void {
46-
assert(x !== undefined && x !== null, msg);
47-
}
48-
export function isUndefined(x: {} | null | undefined, msg = "Expected value to be undefined."): void {
49-
assert(x === undefined, msg);
50-
}
51-
export function deepEqual<T>(a: T, b: T, msg?: string): void {
52-
assert(isDeepEqual(a, b), msg || (() => `Expected values to be deeply equal:\nExpected:\n${JSON.stringify(a, undefined, 4)}\nActual:\n${JSON.stringify(b, undefined, 4)}`));
53-
}
54-
export function lengthOf(a: ReadonlyArray<{}>, length: number, msg = "Expected length to match."): void {
55-
assert(a.length === length, msg);
56-
}
57-
export function throws(cb: () => void, msg = "Expected callback to throw"): void {
58-
let threw = false;
59-
try {
60-
cb();
61-
}
62-
catch {
63-
threw = true;
64-
}
65-
assert(threw, msg);
66-
}
67-
68-
function isDeepEqual<T>(a: T, b: T): boolean {
69-
if (a === b) {
70-
return true;
71-
}
72-
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
73-
return false;
74-
}
75-
const aKeys = Object.keys(a).sort();
76-
const bKeys = Object.keys(b).sort();
77-
return aKeys.length === bKeys.length && aKeys.every((key, i) => bKeys[i] === key && isDeepEqual((a as any)[key], (b as any)[key]));
78-
}
79-
}
32+
// this will work in the browser via browserify
33+
var _chai: typeof chai = require("chai");
34+
var assert: typeof _chai.assert = _chai.assert;
35+
// chai's builtin `assert.isFalse` is featureful but slow - we don't use those features,
36+
// so we'll just overwrite it as an alterative to migrating a bunch of code off of chai
37+
assert.isFalse = (expr, msg) => { if (expr as any as boolean !== false) throw new Error(msg); };
8038
declare var __dirname: string; // Node-specific
8139
var global: NodeJS.Global = <any>Function("return this").call(undefined);
8240

@@ -389,8 +347,8 @@ namespace Utils {
389347
return;
390348
}
391349

392-
assert(!!array1, "array1");
393-
assert(!!array2, "array2");
350+
assert(array1, "array1");
351+
assert(array2, "array2");
394352

395353
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
396354

@@ -413,8 +371,8 @@ namespace Utils {
413371
return;
414372
}
415373

416-
assert(!!node1, "node1");
417-
assert(!!node2, "node2");
374+
assert(node1, "node1");
375+
assert(node2, "node2");
418376
assert.equal(node1.pos, node2.pos, "node1.pos !== node2.pos");
419377
assert.equal(node1.end, node2.end, "node1.end !== node2.end");
420378
assert.equal(node1.kind, node2.kind, "node1.kind !== node2.kind");
@@ -444,8 +402,8 @@ namespace Utils {
444402
return;
445403
}
446404

447-
assert(!!array1, "array1");
448-
assert(!!array2, "array2");
405+
assert(array1, "array1");
406+
assert(array2, "array2");
449407
assert.equal(array1.pos, array2.pos, "array1.pos !== array2.pos");
450408
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
451409
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
@@ -1301,7 +1259,7 @@ namespace Harness {
13011259

13021260
function findResultCodeFile(fileName: string) {
13031261
const sourceFile = result.program.getSourceFile(fileName);
1304-
assert.isDefined(sourceFile, "Program has no source file with name '" + fileName + "'");
1262+
assert(sourceFile, "Program has no source file with name '" + fileName + "'");
13051263
// Is this file going to be emitted separately
13061264
let sourceFileName: string;
13071265
const outFile = options.outFile || options.out;
@@ -1984,7 +1942,7 @@ namespace Harness {
19841942
const data = testUnitData[i];
19851943
if (ts.getBaseFileName(data.name).toLowerCase() === "tsconfig.json") {
19861944
const configJson = ts.parseJsonText(data.name, data.content);
1987-
assert(configJson.endOfFileToken !== undefined);
1945+
assert.isTrue(configJson.endOfFileToken !== undefined);
19881946
let baseDir = ts.normalizePath(ts.getDirectoryPath(data.name));
19891947
if (rootDir) {
19901948
baseDir = ts.getNormalizedAbsolutePath(baseDir, rootDir);

Diff for: src/harness/harnessLanguageService.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ namespace Harness.LanguageService {
176176
*/
177177
public positionToLineAndCharacter(fileName: string, position: number): ts.LineAndCharacter {
178178
const script: ScriptInfo = this.getScriptInfo(fileName);
179-
assert(!!script);
179+
assert.isOk(script);
180+
180181
return ts.computeLineAndCharacterOfPosition(script.getLineMap(), position);
181182
}
182183
}
@@ -378,7 +379,7 @@ namespace Harness.LanguageService {
378379
classification: parseInt(result[i + 1])
379380
};
380381

381-
assert(t.length > 0, "Result length should be greater than 0, got :" + t.length);
382+
assert.isTrue(t.length > 0, "Result length should be greater than 0, got :" + t.length);
382383
position += t.length;
383384
}
384385
const finalLexState = parseInt(result[result.length - 1]);

Diff for: src/harness/sourceMapRecorder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,10 @@ namespace Harness.SourceMapRecorder {
285285
}
286286

287287
export function recordNewSourceFileSpan(sourceMapSpan: ts.SourceMapSpan, newSourceFileCode: string) {
288-
assert(spansOnSingleLine.length === 0 || spansOnSingleLine[0].sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine, "new file source map span should be on new line. We currently handle only that scenario");
288+
assert.isTrue(spansOnSingleLine.length === 0 || spansOnSingleLine[0].sourceMapSpan.emittedLine !== sourceMapSpan.emittedLine, "new file source map span should be on new line. We currently handle only that scenario");
289289
recordSourceMapSpan(sourceMapSpan);
290290

291-
assert(spansOnSingleLine.length === 1);
291+
assert.isTrue(spansOnSingleLine.length === 1);
292292
sourceMapRecorder.WriteLine("-------------------------------------------------------------------");
293293
sourceMapRecorder.WriteLine("emittedFile:" + jsFile.fileName);
294294
sourceMapRecorder.WriteLine("sourceFile:" + sourceMapSources[spansOnSingleLine[0].sourceMapSpan.sourceIndex]);
@@ -331,7 +331,7 @@ namespace Harness.SourceMapRecorder {
331331
function getMarkerId(markerIndex: number) {
332332
let markerId = "";
333333
if (spanMarkerContinues) {
334-
assert(markerIndex === 0);
334+
assert.isTrue(markerIndex === 0);
335335
markerId = "1->";
336336
}
337337
else {

Diff for: src/harness/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"outFile": "../../built/local/run.js",
66
"declaration": false,
77
"types": [
8-
"node", "mocha"
8+
"node", "mocha", "chai"
99
],
1010
"lib": [
1111
"es6",

Diff for: src/harness/unittests/commandLineParsing.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ts {
1212

1313
const parsedErrors = parsed.errors;
1414
const expectedErrors = expectedParsedCommandLine.errors;
15-
assert(parsedErrors.length === expectedErrors.length, `Expected error: ${JSON.stringify(expectedErrors)}. Actual error: ${JSON.stringify(parsedErrors)}.`);
15+
assert.isTrue(parsedErrors.length === expectedErrors.length, `Expected error: ${JSON.stringify(expectedErrors)}. Actual error: ${JSON.stringify(parsedErrors)}.`);
1616
for (let i = 0; i < parsedErrors.length; i++) {
1717
const parsedError = parsedErrors[i];
1818
const expectedError = expectedErrors[i];
@@ -23,7 +23,7 @@ namespace ts {
2323

2424
const parsedFileNames = parsed.fileNames;
2525
const expectedFileNames = expectedParsedCommandLine.fileNames;
26-
assert(parsedFileNames.length === expectedFileNames.length, `Expected fileNames: [${JSON.stringify(expectedFileNames)}]. Actual fileNames: [${JSON.stringify(parsedFileNames)}].`);
26+
assert.isTrue(parsedFileNames.length === expectedFileNames.length, `Expected fileNames: [${JSON.stringify(expectedFileNames)}]. Actual fileNames: [${JSON.stringify(parsedFileNames)}].`);
2727
for (let i = 0; i < parsedFileNames.length; i++) {
2828
const parsedFileName = parsedFileNames[i];
2929
const expectedFileName = expectedFileNames[i];

Diff for: src/harness/unittests/compileOnSave.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace ts.projectSystem {
2525

2626
const actualResultSingleProjectFileNameList = actualResultSingleProject.fileNames.sort();
2727
const expectedResultSingleProjectFileNameList = map(expectedResultSingleProject.files, f => f.path).sort();
28-
assert(
28+
assert.isTrue(
2929
arrayIsEqualTo(actualResultSingleProjectFileNameList, expectedResultSingleProjectFileNameList),
3030
`For project ${actualResultSingleProject.projectFileName}, the actual result is ${actualResultSingleProjectFileNameList}, while expected ${expectedResultSingleProjectFileNameList}`);
3131
}
@@ -563,7 +563,7 @@ namespace ts.projectSystem {
563563
session.executeCommand(compileFileRequest);
564564

565565
const expectedEmittedFileName = "/a/b/f1.js";
566-
assert(host.fileExists(expectedEmittedFileName));
566+
assert.isTrue(host.fileExists(expectedEmittedFileName));
567567
assert.equal(host.readFile(expectedEmittedFileName), `"use strict";\r\nexports.__esModule = true;\r\nfunction Foo() { return 10; }\r\nexports.Foo = Foo;\r\n`);
568568
});
569569

@@ -600,11 +600,11 @@ namespace ts.projectSystem {
600600
session.executeCommand(emitRequest);
601601

602602
const expectedOutFileName = "/a/b/dist.js";
603-
assert(host.fileExists(expectedOutFileName));
603+
assert.isTrue(host.fileExists(expectedOutFileName));
604604
const outFileContent = host.readFile(expectedOutFileName);
605-
assert(outFileContent.indexOf(file1.content) !== -1);
606-
assert(outFileContent.indexOf(file2.content) === -1);
607-
assert(outFileContent.indexOf(file3.content) === -1);
605+
assert.isTrue(outFileContent.indexOf(file1.content) !== -1);
606+
assert.isTrue(outFileContent.indexOf(file2.content) === -1);
607+
assert.isTrue(outFileContent.indexOf(file3.content) === -1);
608608
});
609609

610610
it("should use project root as current directory so that compile on save results in correct file mapping", () => {
@@ -634,19 +634,19 @@ namespace ts.projectSystem {
634634

635635
// Verify js file
636636
const expectedOutFileName = "/root/TypeScriptProject3/TypeScriptProject3/" + outFileName;
637-
assert(host.fileExists(expectedOutFileName));
637+
assert.isTrue(host.fileExists(expectedOutFileName));
638638
const outFileContent = host.readFile(expectedOutFileName);
639639
verifyContentHasString(outFileContent, file1.content);
640640
verifyContentHasString(outFileContent, `//# ${"sourceMappingURL"}=${outFileName}.map`); // Sometimes tools can sometimes see this line as a source mapping url comment, so we obfuscate it a little
641641

642642
// Verify map file
643643
const expectedMapFileName = expectedOutFileName + ".map";
644-
assert(host.fileExists(expectedMapFileName));
644+
assert.isTrue(host.fileExists(expectedMapFileName));
645645
const mapFileContent = host.readFile(expectedMapFileName);
646646
verifyContentHasString(mapFileContent, `"sources":["${inputFileName}"]`);
647647

648648
function verifyContentHasString(content: string, str: string) {
649-
assert(stringContains(content, str), `Expected "${content}" to have "${str}"`);
649+
assert.isTrue(stringContains(content, str), `Expected "${content}" to have "${str}"`);
650650
}
651651
});
652652
});

Diff for: src/harness/unittests/configurationExtension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace ts {
113113
const caseSensitiveHost = new Utils.MockParseConfigHost(caseSensitiveBasePath, /*useCaseSensitiveFileNames*/ true, testContents);
114114

115115
function verifyDiagnostics(actual: Diagnostic[], expected: {code: number, category: DiagnosticCategory, messageText: string}[]) {
116-
assert(expected.length === actual.length, `Expected error: ${JSON.stringify(expected)}. Actual error: ${JSON.stringify(actual)}.`);
116+
assert.isTrue(expected.length === actual.length, `Expected error: ${JSON.stringify(expected)}. Actual error: ${JSON.stringify(actual)}.`);
117117
for (let i = 0; i < actual.length; i++) {
118118
const actualError = actual[i];
119119
const expectedError = expected[i];

0 commit comments

Comments
 (0)