summaryrefslogtreecommitdiff
path: root/test/parallel/test-vm-run-in-new-context.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2019-04-02 09:57:15 +0200
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-04-05 05:44:51 +0200
commitf13733d12d69077c9312371a966bef11f01b2816 (patch)
tree1c8e091e1ead50b383e4cc3edbd520d65dee88a9 /test/parallel/test-vm-run-in-new-context.js
parent2c49e8b537a5fba07568c2363ba6a594caa74c17 (diff)
downloadandroid-node-v8-f13733d12d69077c9312371a966bef11f01b2816.tar.gz
android-node-v8-f13733d12d69077c9312371a966bef11f01b2816.tar.bz2
android-node-v8-f13733d12d69077c9312371a966bef11f01b2816.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test/parallel/test-vm-run-in-new-context.js')
-rw-r--r--test/parallel/test-vm-run-in-new-context.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js
index 51577668cf..6e8c42812b 100644
--- a/test/parallel/test-vm-run-in-new-context.js
+++ b/test/parallel/test-vm-run-in-new-context.js
@@ -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;
});