-
-
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.
fix: support some virtual contexts in
toThrow
This adds support for VM situations where we pass a `RegExp` from another process. Note that we don't have a full fix for this stuff until `check-error` also supports `Error` being from another origin.
- Loading branch information
Showing
5 changed files
with
45 additions
and
4 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
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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); | ||
} | ||
); | ||
} | ||
}); | ||
}); |
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