forked from chaijs/chai
-
Notifications
You must be signed in to change notification settings - Fork 0
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
(chaijs#1609)
* 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. * fix: support throwing of unusual errors Adds support for throwing things like `undefined`, functions, etc. * chore: upgrade check-error
- Loading branch information
Showing
7 changed files
with
83 additions
and
13 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
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
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,34 @@ | ||
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); | ||
} | ||
); | ||
} | ||
}); | ||
}); |
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