aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-vm-run-in-new-context.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2017-11-09 15:36:04 -0500
committercjihrig <cjihrig@gmail.com>2017-11-10 12:54:05 -0500
commit6f02da255f803719cda330f69213ad9a11ef4b04 (patch)
tree00322afce9da20ae56c408e291fa312bcdcf7d4b /test/parallel/test-vm-run-in-new-context.js
parent8e814fcf3aa82ddf796a4714c43bed26381e6883 (diff)
downloadandroid-node-v8-6f02da255f803719cda330f69213ad9a11ef4b04.tar.gz
android-node-v8-6f02da255f803719cda330f69213ad9a11ef4b04.tar.bz2
android-node-v8-6f02da255f803719cda330f69213ad9a11ef4b04.zip
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: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test/parallel/test-vm-run-in-new-context.js')
-rw-r--r--test/parallel/test-vm-run-in-new-context.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/parallel/test-vm-run-in-new-context.js b/test/parallel/test-vm-run-in-new-context.js
index 2dc9cc5bea..082682f843 100644
--- a/test/parallel/test-vm-run-in-new-context.js
+++ b/test/parallel/test-vm-run-in-new-context.js
@@ -73,3 +73,23 @@ const fn = vm.runInNewContext('(function() { obj.p = {}; })', { obj: {} });
global.gc();
fn();
// Should not crash
+
+{
+ // Verify that providing a custom filename as a string argument works.
+ const code = 'throw new Error("foo");';
+ const file = 'test_file.vm';
+
+ assert.throws(() => {
+ vm.runInNewContext(code, {}, file);
+ }, (err) => {
+ const lines = err.stack.split('\n');
+
+ assert.strictEqual(lines[0].trim(), `${file}: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`);
+ // The rest of the stack is uninteresting.
+ return true;
+ });
+}