Skip to content

Commit 27988bf

Browse files
committed
More updates based on PR feedback
1 parent 65521bc commit 27988bf

3 files changed

Lines changed: 128 additions & 82 deletions

File tree

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,20 @@ namespace ts.projectSystem {
407407
// Update file
408408
if (currentEntry.content !== fileOrFolder.content) {
409409
currentEntry.content = fileOrFolder.content;
410+
currentEntry.fileSize = fileOrFolder.fileSize;
410411
this.invokeFileWatcher(currentEntry.fullPath, FileWatcherEventKind.Changed);
411412
}
412413
}
413414
else {
414415
// TODO: Changing from file => folder
416+
Debug.fail(`Currently ${path} is file and new FS makes it folder which isnt supported yet`);
415417
}
416418
}
417419
else {
418420
// Folder
419421
if (typeof fileOrFolder.content === "string") {
420422
// TODO: Changing from folder => file
423+
Debug.fail(`Currently ${path} is folder and new FS makes it file which isnt supported yet`);
421424
}
422425
else {
423426
// Folder update: Nothing to do.
@@ -778,6 +781,20 @@ namespace ts.projectSystem {
778781
}
779782
}
780783

784+
type ErrorInformation = { diagnosticMessage: DiagnosticMessage, errorTextArguments?: string[] };
785+
function getProtocolDiagnosticMessage({ diagnosticMessage, errorTextArguments = [] }: ErrorInformation) {
786+
return formatStringFromArgs(diagnosticMessage.message, errorTextArguments);
787+
}
788+
789+
function verifyDiagnostics(actual: server.protocol.Diagnostic[], expected: ErrorInformation[]) {
790+
const expectedErrors = expected.map(getProtocolDiagnosticMessage);
791+
assert.deepEqual(actual.map(diag => flattenDiagnosticMessageText(diag.text, "\n")), expectedErrors);
792+
}
793+
794+
function verifyNoDiagnostics(actual: server.protocol.Diagnostic[]) {
795+
verifyDiagnostics(actual, []);
796+
}
797+
781798
describe("tsserver-project-system", () => {
782799
const commonFile1: FileOrFolder = {
783800
path: "/a/b/commonFile1.ts",
@@ -1111,19 +1128,22 @@ namespace ts.projectSystem {
11111128
server.CommandNames.SemanticDiagnosticsSync,
11121129
{ file: file1.path }
11131130
);
1114-
let diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
11151131

11161132
// Two errors: CommonFile2 not found and cannot find name y
1117-
assert.equal(diags.length, 2, diags.map(diag => flattenDiagnosticMessageText(diag.text, "\n")).join("\n"));
1133+
let diags: server.protocol.Diagnostic[] = session.executeCommand(getErrRequest).response;
1134+
verifyDiagnostics(diags, [
1135+
{ diagnosticMessage: Diagnostics.Cannot_find_name_0, errorTextArguments: ["y"] },
1136+
{ diagnosticMessage: Diagnostics.File_0_not_found, errorTextArguments: [commonFile2.path] }
1137+
]);
11181138

11191139
host.reloadFS([file1, commonFile2, libFile]);
11201140
host.runQueuedTimeoutCallbacks();
11211141
checkNumberOfInferredProjects(projectService, 1);
11221142
assert.strictEqual(projectService.inferredProjects[0], project, "Inferred project should be same");
11231143
checkProjectRootFiles(project, [file1.path]);
11241144
checkProjectActualFiles(project, [file1.path, libFile.path, commonFile2.path]);
1125-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
1126-
assert.equal(diags.length, 0);
1145+
diags = session.executeCommand(getErrRequest).response;
1146+
verifyNoDiagnostics(diags);
11271147
});
11281148

11291149
it("should create new inferred projects for files excluded from a configured project", () => {
@@ -3110,15 +3130,18 @@ namespace ts.projectSystem {
31103130
server.CommandNames.SemanticDiagnosticsSync,
31113131
{ file: file1.path }
31123132
);
3113-
let diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3114-
assert.equal(diags.length, 0);
3133+
let diags: server.protocol.Diagnostic[] = session.executeCommand(getErrRequest).response;
3134+
verifyNoDiagnostics(diags);
31153135

31163136
const moduleFileOldPath = moduleFile.path;
31173137
const moduleFileNewPath = "/a/b/moduleFile1.ts";
31183138
moduleFile.path = moduleFileNewPath;
31193139
host.reloadFS([moduleFile, file1]);
31203140
host.runQueuedTimeoutCallbacks();
3121-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3141+
diags = session.executeCommand(getErrRequest).response;
3142+
verifyDiagnostics(diags, [
3143+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
3144+
]);
31223145
assert.equal(diags.length, 1);
31233146

31243147
moduleFile.path = moduleFileOldPath;
@@ -3133,8 +3156,8 @@ namespace ts.projectSystem {
31333156
session.executeCommand(changeRequest);
31343157
host.runQueuedTimeoutCallbacks();
31353158

3136-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3137-
assert.equal(diags.length, 0);
3159+
diags = session.executeCommand(getErrRequest).response;
3160+
verifyNoDiagnostics(diags);
31383161
});
31393162

31403163
it("should restore the states for configured projects", () => {
@@ -3158,22 +3181,24 @@ namespace ts.projectSystem {
31583181
server.CommandNames.SemanticDiagnosticsSync,
31593182
{ file: file1.path }
31603183
);
3161-
let diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3162-
assert.equal(diags.length, 0);
3184+
let diags: server.protocol.Diagnostic[] = session.executeCommand(getErrRequest).response;
3185+
verifyNoDiagnostics(diags);
31633186

31643187
const moduleFileOldPath = moduleFile.path;
31653188
const moduleFileNewPath = "/a/b/moduleFile1.ts";
31663189
moduleFile.path = moduleFileNewPath;
31673190
host.reloadFS([moduleFile, file1, configFile]);
31683191
host.runQueuedTimeoutCallbacks();
3169-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3170-
assert.equal(diags.length, 1);
3192+
diags = session.executeCommand(getErrRequest).response;
3193+
verifyDiagnostics(diags, [
3194+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
3195+
]);
31713196

31723197
moduleFile.path = moduleFileOldPath;
31733198
host.reloadFS([moduleFile, file1, configFile]);
31743199
host.runQueuedTimeoutCallbacks();
3175-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3176-
assert.equal(diags.length, 0);
3200+
diags = session.executeCommand(getErrRequest).response;
3201+
verifyNoDiagnostics(diags);
31773202
});
31783203

31793204
it("should property handle missing config files", () => {
@@ -3239,8 +3264,10 @@ namespace ts.projectSystem {
32393264
server.CommandNames.SemanticDiagnosticsSync,
32403265
{ file: file1.path }
32413266
);
3242-
let diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3243-
assert.equal(diags.length, 1);
3267+
let diags: server.protocol.Diagnostic[] = session.executeCommand(getErrRequest).response;
3268+
verifyDiagnostics(diags, [
3269+
{ diagnosticMessage: Diagnostics.Cannot_find_module_0, errorTextArguments: ["./moduleFile"] }
3270+
]);
32443271

32453272
host.reloadFS([file1, moduleFile]);
32463273
host.runQueuedTimeoutCallbacks();
@@ -3253,8 +3280,8 @@ namespace ts.projectSystem {
32533280
session.executeCommand(changeRequest);
32543281

32553282
// Recheck
3256-
diags = <server.protocol.Diagnostic[]>session.executeCommand(getErrRequest).response;
3257-
assert.equal(diags.length, 0);
3283+
diags = session.executeCommand(getErrRequest).response;
3284+
verifyNoDiagnostics(diags);
32583285
});
32593286
});
32603287

0 commit comments

Comments
 (0)