Skip to content

Commit f13733d

Browse files
bnoordhuisdanbev
authored andcommitted
test: test vm.runInNewContext() filename option
The 'filename as a string' case was already being tested. This commit also exercises the 'filename as an option' case. PR-URL: #27056 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent 2c49e8b commit f13733d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/parallel/test-vm-run-in-new-context.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ global.gc();
7272
fn();
7373
// Should not crash
7474

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

8080
assert.throws(() => {
81-
vm.runInNewContext(code, {}, file);
81+
vm.runInNewContext(code, {}, arg);
8282
}, (err) => {
8383
const lines = err.stack.split('\n');
8484

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

0 commit comments

Comments
 (0)