Skip to content

Commit 2021ea1

Browse files
Muhsin Abdul-Musawwirevanlucas
Muhsin Abdul-Musawwir
authored andcommitted
test: refactored context type err message to regex
PR-URL: #12596 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1a4bf43 commit 2021ea1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/parallel/test-vm-context.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ assert.strictEqual('lala', context.thing);
2525
// Issue GH-227:
2626
assert.throws(function() {
2727
vm.runInNewContext('', null, 'some.js');
28-
}, TypeError);
28+
}, /^TypeError: sandbox must be an object$/);
2929

3030
// Issue GH-1140:
3131
console.error('test runInContext signature');
@@ -41,9 +41,18 @@ assert.ok(gh1140Exception,
4141
'expected exception from runInContext signature test');
4242

4343
// GH-558, non-context argument segfaults / raises assertion
44-
[undefined, null, 0, 0.0, '', {}, []].forEach(function(e) {
45-
assert.throws(function() { script.runInContext(e); }, TypeError);
46-
assert.throws(function() { vm.runInContext('', e); }, TypeError);
44+
const nonContextualSandboxErrorMsg =
45+
/^TypeError: contextifiedSandbox argument must be an object\.$/;
46+
const contextifiedSandboxErrorMsg =
47+
/^TypeError: sandbox argument must have been converted to a context\.$/;
48+
[
49+
[undefined, nonContextualSandboxErrorMsg],
50+
[null, nonContextualSandboxErrorMsg], [0, nonContextualSandboxErrorMsg],
51+
[0.0, nonContextualSandboxErrorMsg], ['', nonContextualSandboxErrorMsg],
52+
[{}, contextifiedSandboxErrorMsg], [[], contextifiedSandboxErrorMsg]
53+
].forEach((e) => {
54+
assert.throws(() => { script.runInContext(e[0]); }, e[1]);
55+
assert.throws(() => { vm.runInContext('', e[0]); }, e[1]);
4756
});
4857

4958
// Issue GH-693:

0 commit comments

Comments
 (0)