Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding additional error details for asserts. #16116

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions test/parallel/test-vm-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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({}, {});
Expand Down