Skip to content

Commit

Permalink
test: refactored context type err message to regex
Browse files Browse the repository at this point in the history
PR-URL: #12596
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Muhsin Abdul-Musawwir authored and evanlucas committed May 2, 2017
1 parent 1a4bf43 commit 2021ea1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions test/parallel/test-vm-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ assert.strictEqual('lala', context.thing);
// Issue GH-227:
assert.throws(function() {
vm.runInNewContext('', null, 'some.js');
}, TypeError);
}, /^TypeError: sandbox must be an object$/);

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

// GH-558, non-context argument segfaults / raises assertion
[undefined, null, 0, 0.0, '', {}, []].forEach(function(e) {
assert.throws(function() { script.runInContext(e); }, TypeError);
assert.throws(function() { vm.runInContext('', e); }, TypeError);
const nonContextualSandboxErrorMsg =
/^TypeError: contextifiedSandbox argument must be an object\.$/;
const contextifiedSandboxErrorMsg =
/^TypeError: sandbox argument must have been converted to a context\.$/;
[
[undefined, nonContextualSandboxErrorMsg],
[null, nonContextualSandboxErrorMsg], [0, nonContextualSandboxErrorMsg],
[0.0, nonContextualSandboxErrorMsg], ['', nonContextualSandboxErrorMsg],
[{}, contextifiedSandboxErrorMsg], [[], contextifiedSandboxErrorMsg]
].forEach((e) => {
assert.throws(() => { script.runInContext(e[0]); }, e[1]);
assert.throws(() => { vm.runInContext('', e[0]); }, e[1]);
});

// Issue GH-693:
Expand Down

0 comments on commit 2021ea1

Please sign in to comment.