-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
41 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
import vm from 'node:vm'; | ||
import * as chai from '../index.js'; | ||
|
||
const {assert} = chai; | ||
const vmContext = {assert}; | ||
vm.createContext(vmContext); | ||
|
||
function runCodeInVm(code) { | ||
vm.runInContext(code, vmContext); | ||
} | ||
|
||
describe('node virtual machines', function () { | ||
it('throws', function() { | ||
const shouldNotThrow = [ | ||
`assert.throws(function() { throw ''; }, /^$/);`, | ||
`assert.throws(function() { throw new Error('bleepbloop'); });`, | ||
`assert.throws(function() { throw new Error(''); });`, | ||
// TODO (43081j): enable this test once check-error supports | ||
// cross-vm `Error` objects | ||
//`assert.throws(function() { throw new Error('swoosh'); }, /swoosh/);` | ||
]; | ||
|
||
for (const code of shouldNotThrow) { | ||
assert.doesNotThrow( | ||
() => { | ||
runCodeInVm(code); | ||
} | ||
); | ||
} | ||
}); | ||
}); | ||
import vm from 'node:vm'; | ||
import * as chai from '../index.js'; | ||
|
||
const {assert} = chai; | ||
const vmContext = {assert}; | ||
vm.createContext(vmContext); | ||
|
||
/** | ||
* Run the code in a virtual context | ||
* | ||
* @param {string} code Code to run | ||
*/ | ||
function runCodeInVm(code) { | ||
vm.runInContext(code, vmContext); | ||
} | ||
|
||
describe('node virtual machines', function () { | ||
it('throws', function() { | ||
const shouldNotThrow = [ | ||
`assert.throws(function() { throw ''; }, /^$/);`, | ||
`assert.throws(function() { throw new Error('bleepbloop'); });`, | ||
`assert.throws(function() { throw new Error(''); });`, | ||
`assert.throws(function() { throw new Error('swoosh'); }, /swoosh/);` | ||
]; | ||
|
||
for (const code of shouldNotThrow) { | ||
assert.doesNotThrow( | ||
() => { | ||
runCodeInVm(code); | ||
} | ||
); | ||
} | ||
}); | ||
}); |