Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db78d5a

Browse filesBrowse files
committed
add error message test
1 parent 3083937 commit db78d5a
Copy full SHA for db78d5a

1 file changed

+55Lines changed: 55 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/harness/unittests/session.ts‎

Copy file name to clipboardExpand all lines: src/harness/unittests/session.ts
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,61 @@ namespace ts.server {
386386
});
387387
});
388388

389+
describe("exceptions", () => {
390+
const command = "testhandler";
391+
class TestSession extends Session {
392+
lastSent: protocol.Message;
393+
private exceptionRaisingHandler(_request: protocol.Request): { response?: any, responseRequired: boolean } {
394+
f1();
395+
return;
396+
function f1() {
397+
throw new Error("myMessage");
398+
}
399+
}
400+
401+
constructor() {
402+
super({
403+
host: mockHost,
404+
cancellationToken: nullCancellationToken,
405+
useSingleInferredProject: false,
406+
useInferredProjectPerProjectRoot: false,
407+
typingsInstaller: undefined,
408+
byteLength: Utils.byteLength,
409+
hrtime: process.hrtime,
410+
logger: projectSystem.nullLogger,
411+
canUseEvents: true
412+
});
413+
this.addProtocolHandler(command, this.exceptionRaisingHandler);
414+
}
415+
send(msg: protocol.Message) {
416+
this.lastSent = msg;
417+
}
418+
}
419+
420+
it("raised in a protocol handler generate an event", () => {
421+
422+
const session = new TestSession();
423+
424+
const request = {
425+
command,
426+
seq: 0,
427+
type: "request"
428+
};
429+
430+
session.onMessage(JSON.stringify(request));
431+
const lastSent = session.lastSent as protocol.Response;
432+
433+
expect(lastSent).to.contain({
434+
seq: 0,
435+
type: "response",
436+
command,
437+
success: false
438+
});
439+
440+
expect(lastSent.message).has.string("myMessage").and.has.string("f1");
441+
});
442+
});
443+
389444
describe("how Session is extendable via subclassing", () => {
390445
class TestSession extends Session {
391446
lastSent: protocol.Message;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.