(chai 5.1.0 from npm, node 18.14.0, v8 10.2.154.23-node.22)
It seems that assert.throws() does not work correctly in vm spawned context.
const vm = require('node:vm');
const context = {};
vm.createContext(context);
setImmediate(runTest);
async function runTest() {
context.chai = await import('chai');
context.chai.assert.throws(() => { throw new Error('aaa.bbb'); }, /bbb/); // OK
vm.runInContext(code, context); // Failure
}
const code = `
chai.assert.throws(() => { throw new Error('aaa.bbb'); }, /bbb/);
`;
Default context assert.throws() work as expected, but vm context assert.throws() asserts where it should pass.