Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 26d529e

Browse filesBrowse files
cjihrigMylesBorins
authored andcommitted
test: cover vm.runInNewContext()
There is currently one if branch missing coverage in lib/vm.js. This commit adds a test to cover the case where the third argument to runInNewContext() is a string. PR-URL: #16906 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
1 parent 6c57399 commit 26d529e
Copy full SHA for 26d529e

File tree

Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-0
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-vm-run-in-new-context.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,23 @@ const fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} });
7373
global.gc();
7474
fn();
7575
// Should not crash
76+
77+
{
78+
// Verify that providing a custom filename as a string argument works.
79+
const code = 'throw new Error("foo");';
80+
const file = 'test_file.vm';
81+
82+
assert.throws(() => {
83+
vm.runInNewContext(code, {}, file);
84+
}, (err) => {
85+
const lines = err.stack.split('\n');
86+
87+
assert.strictEqual(lines[0].trim(), `${file}:1`);
88+
assert.strictEqual(lines[1].trim(), code);
89+
// Skip lines[2] and lines[3]. They're just a ^ and blank line.
90+
assert.strictEqual(lines[4].trim(), 'Error: foo');
91+
assert.strictEqual(lines[5].trim(), `at ${file}:1:7`);
92+
// The rest of the stack is uninteresting.
93+
return true;
94+
});
95+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.