Skip to content

Commit 10c24a1

Browse files
burgerboydaddyMylesBorins
authored andcommitted
test: add details in assertions in test-vm-context
PR-URL: #16116 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent cb1d16d commit 10c24a1

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

test/parallel/test-vm-context.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ try {
3535
} catch (e) {
3636
gh1140Exception = e;
3737
assert.ok(/expected-filename/.test(e.stack),
38-
'expected appearance of filename in Error stack');
38+
`expected appearance of filename in Error stack: ${e.stack}`);
3939
}
40-
assert.ok(gh1140Exception,
41-
'expected exception from runInContext signature test');
40+
// This is outside of catch block to confirm catch block ran.
41+
assert.strictEqual(gh1140Exception.toString(), 'Error');
4242

4343
// GH-558, non-context argument segfaults / raises assertion
4444
const nonContextualSandboxErrorMsg =
@@ -69,18 +69,22 @@ Object.defineProperty(ctx, 'b', { configurable: false });
6969
ctx = vm.createContext(ctx);
7070
assert.strictEqual(script.runInContext(ctx), false);
7171

72-
// Error on the first line of a module should
73-
// have the correct line and column number
74-
assert.throws(() => {
75-
vm.runInContext(' throw new Error()', context, {
76-
filename: 'expected-filename.js',
77-
lineOffset: 32,
78-
columnOffset: 123
79-
});
80-
}, (err) => {
81-
return /^ \^/m.test(err.stack) &&
82-
/expected-filename\.js:33:131/.test(err.stack);
83-
}, 'Expected appearance of proper offset in Error stack');
72+
// Error on the first line of a module should have the correct line and column
73+
// number.
74+
{
75+
let stack = null;
76+
assert.throws(() => {
77+
vm.runInContext(' throw new Error()', context, {
78+
filename: 'expected-filename.js',
79+
lineOffset: 32,
80+
columnOffset: 123
81+
});
82+
}, (err) => {
83+
stack = err.stack;
84+
return /^ \^/m.test(stack) &&
85+
/expected-filename\.js:33:131/.test(stack);
86+
}, `stack not formatted as expected: ${stack}`);
87+
}
8488

8589
// https://github.com/nodejs/node/issues/6158
8690
ctx = new Proxy({}, {});

0 commit comments

Comments
 (0)