Skip to content

Commit

Permalink
chore: upgrade check-error
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed May 9, 2024
1 parent 23b4dc2 commit c182e03
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
3 changes: 2 additions & 1 deletion lib/chai/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ export {getOperator} from './getOperator.js';
/**
* Determines if an object is a `RegExp`
* This is used since `instanceof` will not work in virtual contexts
*
* @param {*} obj Object to test
* @return {boolean}
* @returns {boolean}
*/
export function isRegExp(obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"assertion-error": "^2.0.1",
"check-error": "^2.0.0",
"check-error": "^2.1.1",
"deep-eql": "^5.0.1",
"loupe": "^3.1.0",
"pathval": "^2.0.0"
Expand Down
65 changes: 34 additions & 31 deletions test/virtual-machines.js
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);
}
);
}
});
});

0 comments on commit c182e03

Please sign in to comment.