Skip to content

Commit ef6a7cf

Browse files
Muhsin Abdul-Musawwirjasnell
authored andcommitted
test: refactored context type err message to regex
PR-URL: #12596 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 85a4e25 commit ef6a7cf

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/parallel/test-vm-context.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ assert.strictEqual('lala', context.thing);
4646
// Issue GH-227:
4747
assert.throws(function() {
4848
vm.runInNewContext('', null, 'some.js');
49-
}, TypeError);
49+
}, /^TypeError: sandbox must be an object$/);
5050

5151
// Issue GH-1140:
5252
console.error('test runInContext signature');
@@ -62,9 +62,18 @@ assert.ok(gh1140Exception,
6262
'expected exception from runInContext signature test');
6363

6464
// GH-558, non-context argument segfaults / raises assertion
65-
[undefined, null, 0, 0.0, '', {}, []].forEach(function(e) {
66-
assert.throws(function() { script.runInContext(e); }, TypeError);
67-
assert.throws(function() { vm.runInContext('', e); }, TypeError);
65+
const nonContextualSandboxErrorMsg =
66+
/^TypeError: contextifiedSandbox argument must be an object\.$/;
67+
const contextifiedSandboxErrorMsg =
68+
/^TypeError: sandbox argument must have been converted to a context\.$/;
69+
[
70+
[undefined, nonContextualSandboxErrorMsg],
71+
[null, nonContextualSandboxErrorMsg], [0, nonContextualSandboxErrorMsg],
72+
[0.0, nonContextualSandboxErrorMsg], ['', nonContextualSandboxErrorMsg],
73+
[{}, contextifiedSandboxErrorMsg], [[], contextifiedSandboxErrorMsg]
74+
].forEach((e) => {
75+
assert.throws(() => { script.runInContext(e[0]); }, e[1]);
76+
assert.throws(() => { vm.runInContext('', e[0]); }, e[1]);
6877
});
6978

7079
// Issue GH-693:

0 commit comments

Comments
 (0)