Skip to content

Commit

Permalink
Test suppression of diagnostic events
Browse files Browse the repository at this point in the history
  • Loading branch information
amcasey committed Mar 22, 2018
1 parent 293eb1a commit 5d54dbe
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
89 changes: 86 additions & 3 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ namespace ts.projectSystem {
readonly session: TestSession;
readonly service: server.ProjectService;
readonly host: TestServerHost;
constructor(files: FileOrFolder[]) {
constructor(files: FileOrFolder[], suppressDiagnosticEvents?: boolean) {
this.host = createServerHost(files);
this.session = createSession(this.host, {
canUseEvents: true,
eventHandler: event => this.events.push(event),
suppressDiagnosticEvents,
});
this.service = this.session.getProjectService();
}
Expand Down Expand Up @@ -485,6 +486,12 @@ namespace ts.projectSystem {
checkNthEvent(session, server.toEvent("projectsUpdatedInBackground", { openFiles }), 0, /*isMostRecent*/ true);
}

function checkNoDiagnosticEvents(session: TestSession) {
for (const event of session.events) {
assert.isFalse(event.event.endsWith("Diag"), JSON.stringify(event));
}
}

function checkNthEvent(session: TestSession, expectedEvent: protocol.Event, index: number, isMostRecent: boolean) {
const events = session.events;
assert.deepEqual(events[index], expectedEvent);
Expand Down Expand Up @@ -4074,6 +4081,63 @@ namespace ts.projectSystem {
session.clearMessages();
});

it("suppressed diagnostic events", () => {
const file: FileOrFolder = {
path: "/a.ts",
content: "1 = 2;",
};

const host = createServerHost([file]);
const session = createSession(host, { canUseEvents: true, suppressDiagnosticEvents: true });
const service = session.getProjectService();

session.executeCommandSeq<protocol.OpenRequest>({
command: server.CommandNames.Open,
arguments: { file: file.path, fileContent: file.content },
});

checkNumberOfProjects(service, { inferredProjects: 1 });

host.checkTimeoutQueueLength(0);
checkNoDiagnosticEvents(session);

session.clearMessages();

let expectedSequenceId = session.getNextSeq();

session.executeCommandSeq<protocol.GeterrRequest>({
command: server.CommandNames.Geterr,
arguments: {
delay: 0,
files: [file.path],
}
});

host.checkTimeoutQueueLength(0);
checkNoDiagnosticEvents(session);

checkCompleteEvent(session, 1, expectedSequenceId);

session.clearMessages();

expectedSequenceId = session.getNextSeq();

session.executeCommandSeq<protocol.GeterrForProjectRequest>({
command: server.CommandNames.Geterr,
arguments: {
delay: 0,
file: file.path,
}
});

host.checkTimeoutQueueLength(0);
checkNoDiagnosticEvents(session);

checkCompleteEvent(session, 1, expectedSequenceId);

session.clearMessages();
});

function createDiagnostic(start: protocol.Location, end: protocol.Location, message: DiagnosticMessage, args: ReadonlyArray<string> = []): protocol.Diagnostic {
return { start, end, text: formatStringFromArgs(message.message, args), code: message.code, category: diagnosticCategoryName(message), source: undefined };
}
Expand Down Expand Up @@ -4149,7 +4213,7 @@ namespace ts.projectSystem {
serverEventManager.checkSingleConfigFileDiagEvent(configFile.path, configFile.path);
});

it("are not generated when the config file doesnot include file opened and config file has errors", () => {
it("are not generated when the config file does not include file opened and config file has errors", () => {
const file = {
path: "/a/b/app.ts",
content: "let x = 10"
Expand All @@ -4173,7 +4237,26 @@ namespace ts.projectSystem {
serverEventManager.hasZeroEvent("configFileDiag");
});

it("are not generated when the config file doesnot include file opened and doesnt contain any errors", () => {
it("are not generated when the config file has errors but suppressDiagnosticEvents is true", () => {
const file = {
path: "/a/b/app.ts",
content: "let x = 10"
};
const configFile = {
path: "/a/b/tsconfig.json",
content: `{
"compilerOptions": {
"foo": "bar",
"allowJS": true
}
}`
};
const serverEventManager = new TestServerEventManager([file, configFile], /*suppressDiagnosticEvents*/ true);
openFilesForSession([file], serverEventManager.session);
serverEventManager.hasZeroEvent("configFileDiag");
});

it("are not generated when the config file does not include file opened and doesnt contain any errors", () => {
const file = {
path: "/a/b/app.ts",
content: "let x = 10"
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7256,6 +7256,8 @@ declare namespace ts.server {
*/
canUseEvents: boolean;
eventHandler?: ProjectServiceEventHandler;
/** Has no effect if eventHandler is also specified. */
suppressDiagnosticEvents?: boolean;
throttleWaitMilliseconds?: number;
globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
Expand All @@ -7274,6 +7276,7 @@ declare namespace ts.server {
private hrtime;
protected logger: Logger;
protected canUseEvents: boolean;
private suppressDiagnosticEvents?;
private eventHandler;
constructor(opts: SessionOptions);
private sendRequestCompletedEvent;
Expand All @@ -7289,6 +7292,7 @@ declare namespace ts.server {
private syntacticCheck;
private infoCheck;
private sendDiagnosticsEvent;
/** It is the caller's responsibility to verify that `!this.suppressDiagnosticEvents`. */
private updateErrorCheck;
private cleanProjects;
private cleanup;
Expand Down Expand Up @@ -7817,6 +7821,7 @@ declare namespace ts.server {
useInferredProjectPerProjectRoot: boolean;
typingsInstaller: ITypingsInstaller;
eventHandler?: ProjectServiceEventHandler;
suppressDiagnosticEvents?: boolean;
throttleWaitMilliseconds?: number;
globalPlugins?: ReadonlyArray<string>;
pluginProbeLocations?: ReadonlyArray<string>;
Expand Down Expand Up @@ -7883,6 +7888,7 @@ declare namespace ts.server {
readonly typingsInstaller: ITypingsInstaller;
readonly throttleWaitMilliseconds?: number;
private readonly eventHandler?;
private readonly suppressDiagnosticEvents?;
readonly globalPlugins: ReadonlyArray<string>;
readonly pluginProbeLocations: ReadonlyArray<string>;
readonly allowLocalPluginLoads: boolean;
Expand Down

0 comments on commit 5d54dbe

Please sign in to comment.