From 8f2d82a2ea61eb649145bffdd24244389f7de2be Mon Sep 17 00:00:00 2001 From: Ryan Adolf Date: Sun, 18 Jun 2017 23:00:38 -0700 Subject: [PATCH 1/2] Stop debugging on program end - Fix #11 --- src/nodeDebugAdapter.ts | 10 ++++++++++ test/adapter.test.ts | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nodeDebugAdapter.ts b/src/nodeDebugAdapter.ts index 5dc1183b..ffff0f80 100644 --- a/src/nodeDebugAdapter.ts +++ b/src/nodeDebugAdapter.ts @@ -197,6 +197,16 @@ export class NodeDebugAdapter extends ChromeDebugAdapter { super.commonArgs(args); } + protected hookConnectionEvents(): void { + super.hookConnectionEvents(); + + this.chrome.Runtime.onExecutionContextDestroyed(params => { + if (params.executionContextId === 1) { + this.terminateSession('Program ended'); + } + }); + } + protected async doAttach(port: number, targetUrl?: string, address?: string, timeout?: number): Promise { await super.doAttach(port, targetUrl, address, timeout); this.beginWaitingForDebuggerPaused(); diff --git a/test/adapter.test.ts b/test/adapter.test.ts index eca7af38..dd428b88 100644 --- a/test/adapter.test.ts +++ b/test/adapter.test.ts @@ -58,8 +58,7 @@ suite('Node Debug Adapter etc', () => { }); suite('launch', () => { - // #11 - test.skip('should run program to the end', () => { + test('should run program to the end', () => { const PROGRAM = path.join(DATA_ROOT, 'program.js'); return Promise.all([ From 09fa862419963db02a0d869657fa29371d62c972 Mon Sep 17 00:00:00 2001 From: Ryan Adolf Date: Sun, 18 Jun 2017 23:34:46 -0700 Subject: [PATCH 2/2] Do not run program end test on old Node.js versions --- test/adapter.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/adapter.test.ts b/test/adapter.test.ts index dd428b88..4f7cf547 100644 --- a/test/adapter.test.ts +++ b/test/adapter.test.ts @@ -59,6 +59,11 @@ suite('Node Debug Adapter etc', () => { suite('launch', () => { test('should run program to the end', () => { + if (testSetup.compareSemver(process.version, 'v8.0.0') < 0) { + // Skip test if the node version doesn't emit the Runtime.executionContextDestroyed event + return Promise.resolve(); + } + const PROGRAM = path.join(DATA_ROOT, 'program.js'); return Promise.all([