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

test: test vm.runInNewContext() filename option #27056

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
12 changes: 6 additions & 6 deletions test/parallel/test-vm-run-in-new-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ global.gc();
fn();
// Should not crash

{
// Verify that providing a custom filename as a string argument works.
const filename = 'test_file.vm';
for (const arg of [filename, { filename }]) {
// Verify that providing a custom filename works.
const code = 'throw new Error("foo");';
const file = 'test_file.vm';

assert.throws(() => {
vm.runInNewContext(code, {}, file);
vm.runInNewContext(code, {}, arg);
}, (err) => {
const lines = err.stack.split('\n');

assert.strictEqual(lines[0].trim(), `${file}:1`);
assert.strictEqual(lines[0].trim(), `${filename}:1`);
assert.strictEqual(lines[1].trim(), code);
// Skip lines[2] and lines[3]. They're just a ^ and blank line.
assert.strictEqual(lines[4].trim(), 'Error: foo');
assert.strictEqual(lines[5].trim(), `at ${file}:1:7`);
assert.strictEqual(lines[5].trim(), `at ${filename}:1:7`);
// The rest of the stack is uninteresting.
return true;
});
Expand Down