From 2e1b45db073555f4f5458c9031aab6b38084c89e Mon Sep 17 00:00:00 2001 From: Vladimir Ilic Date: Mon, 9 Oct 2017 22:02:29 -0700 Subject: [PATCH] test: add details in assertions in test-vm-context PR-URL: https://github.com/nodejs/node/pull/16116 Reviewed-By: James M Snell Reviewed-By: Franziska Hinkelmann Reviewed-By: Gireesh Punathil Reviewed-By: Joyee Cheung --- test/parallel/test-vm-context.js | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-vm-context.js b/test/parallel/test-vm-context.js index 29e3a86fab57a3..4663e29b2cc1b7 100644 --- a/test/parallel/test-vm-context.js +++ b/test/parallel/test-vm-context.js @@ -56,10 +56,10 @@ try { } catch (e) { gh1140Exception = e; assert.ok(/expected-filename/.test(e.stack), - 'expected appearance of filename in Error stack'); + `expected appearance of filename in Error stack: ${e.stack}`); } -assert.ok(gh1140Exception, - 'expected exception from runInContext signature test'); +// This is outside of catch block to confirm catch block ran. +assert.strictEqual(gh1140Exception.toString(), 'Error'); // GH-558, non-context argument segfaults / raises assertion const nonContextualSandboxErrorMsg = @@ -90,18 +90,22 @@ Object.defineProperty(ctx, 'b', { configurable: false }); ctx = vm.createContext(ctx); assert.strictEqual(script.runInContext(ctx), false); -// Error on the first line of a module should -// have the correct line and column number -assert.throws(() => { - vm.runInContext(' throw new Error()', context, { - filename: 'expected-filename.js', - lineOffset: 32, - columnOffset: 123 - }); -}, (err) => { - return /^ \^/m.test(err.stack) && - /expected-filename\.js:33:131/.test(err.stack); -}, 'Expected appearance of proper offset in Error stack'); +// Error on the first line of a module should have the correct line and column +// number. +{ + let stack = null; + assert.throws(() => { + vm.runInContext(' throw new Error()', context, { + filename: 'expected-filename.js', + lineOffset: 32, + columnOffset: 123 + }); + }, (err) => { + stack = err.stack; + return /^ \^/m.test(stack) && + /expected-filename\.js:33:131/.test(stack); + }, `stack not formatted as expected: ${stack}`); +} // https://github.com/nodejs/node/issues/6158 ctx = new Proxy({}, {});