Skip to content

Commit

Permalink
test: test vm.runInNewContext() filename option
Browse files Browse the repository at this point in the history
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 <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
bnoordhuis authored and danbev committed Apr 5, 2019
1 parent 2c49e8b commit f13733d
Showing 1 changed file with 6 additions and 6 deletions.
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

0 comments on commit f13733d

Please sign in to comment.