Skip to content

Commit 8044b83

Browse files
Muhsin Abdul-MusawwirMylesBorins
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 32f905a commit 8044b83

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
@@ -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:sandboxmustbeanobject$/);
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+
constnonContextualSandboxErrorMsg=
45+
/^TypeError:contextifiedSandboxargumentmustbeanobject\.$/;
46+
constcontextifiedSandboxErrorMsg=
47+
/^TypeError:sandboxargumentmusthavebeenconvertedtoacontext\.$/;
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)