diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/sequential/test-inspector-contexts.js | 128 |
1 files changed, 105 insertions, 23 deletions
diff --git a/test/sequential/test-inspector-contexts.js b/test/sequential/test-inspector-contexts.js index c7db962f2a..6ad02edeb1 100644 --- a/test/sequential/test-inspector-contexts.js +++ b/test/sequential/test-inspector-contexts.js @@ -6,7 +6,7 @@ const common = require('../common'); common.skipIfInspectorDisabled(); const { strictEqual } = require('assert'); -const { runInNewContext } = require('vm'); +const { createContext, runInNewContext } = require('vm'); const { Session } = require('inspector'); const session = new Session(); @@ -18,13 +18,13 @@ function notificationPromise(method) { async function testContextCreatedAndDestroyed() { console.log('Testing context created/destroyed notifications'); - const mainContextPromise = - notificationPromise('Runtime.executionContextCreated'); - - session.post('Runtime.enable'); - let contextCreated = await mainContextPromise; { - const { name } = contextCreated.params.context; + const mainContextPromise = + notificationPromise('Runtime.executionContextCreated'); + + session.post('Runtime.enable'); + const contextCreated = await mainContextPromise; + const { name, origin, auxData } = contextCreated.params.context; if (common.isSunOS || common.isWindows) { // uv_get_process_title() is unimplemented on Solaris-likes, it returns // an empy string. On the Windows CI buildbots it returns "Administrator: @@ -34,29 +34,111 @@ async function testContextCreatedAndDestroyed() { } else { strictEqual(`${process.argv0}[${process.pid}]`, name); } + strictEqual(origin, '', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, true, + JSON.stringify(contextCreated)); + } + + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + runInNewContext('1 + 1'); + + const contextCreated = await vmContextCreatedPromise; + const { id, name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'VM Context 1', + JSON.stringify(contextCreated)); + strictEqual(origin, '', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + + strictEqual(contextDestroyed.params.executionContextId, id, + JSON.stringify(contextDestroyed)); + } + + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + runInNewContext('1 + 1', {}, { + contextName: 'Custom context', + contextOrigin: 'https://origin.example' + }); + + const contextCreated = await vmContextCreatedPromise; + const { name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'Custom context', + JSON.stringify(contextCreated)); + strictEqual(origin, 'https://origin.example', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); } - const secondContextCreatedPromise = - notificationPromise('Runtime.executionContextCreated'); + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); + + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); + + createContext({}, { origin: 'https://nodejs.org' }); + + const contextCreated = await vmContextCreatedPromise; + const { name, origin, auxData } = contextCreated.params.context; + strictEqual(name, 'VM Context 2', + JSON.stringify(contextCreated)); + strictEqual(origin, 'https://nodejs.org', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); + + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + } - let contextDestroyed = null; - session.once('Runtime.executionContextDestroyed', - (notification) => contextDestroyed = notification); + { + const vmContextCreatedPromise = + notificationPromise('Runtime.executionContextCreated'); - runInNewContext('1 + 1', {}); + let contextDestroyed = null; + session.once('Runtime.executionContextDestroyed', + (notification) => contextDestroyed = notification); - contextCreated = await secondContextCreatedPromise; - strictEqual('VM Context 1', - contextCreated.params.context.name, - JSON.stringify(contextCreated)); + createContext({}, { name: 'Custom context 2' }); - // GC is unpredictable... - while (!contextDestroyed) - global.gc(); + const contextCreated = await vmContextCreatedPromise; + const { name, auxData } = contextCreated.params.context; + strictEqual(name, 'Custom context 2', + JSON.stringify(contextCreated)); + strictEqual(auxData.isDefault, false, + JSON.stringify(contextCreated)); - strictEqual(contextCreated.params.context.id, - contextDestroyed.params.executionContextId, - JSON.stringify(contextDestroyed)); + // GC is unpredictable... + while (!contextDestroyed) + global.gc(); + } } async function testBreakpointHit() { |