diff --git a/jest.config.mjs b/jest.config.mjs index e7ee429..8accdac 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -1,3 +1,4 @@ export default { + transform: {}, silent: true } \ No newline at end of file diff --git a/lib/cds-test.js b/lib/cds-test.js index 582fed2..680f78a 100644 --- a/lib/cds-test.js +++ b/lib/cds-test.js @@ -148,22 +148,21 @@ class Test extends require('./axios') { get chai() { if (global.chai) return global.chai const chai = require('chai') - chai.use (require('chai-subset')) const chaip = require('chai-as-promised') chai.use (chaip.default/*v8 on ESM*/ ?? chaip/*v7*/) return chai - function require (mod) { try { return module.require(mod) } catch(e) { - if (e.code === 'MODULE_NOT_FOUND') - throw new Error (`Failed to load required package '${mod}'. Please add it thru:` - + `\n npm add -D chai chai-as-promised chai-subset`, {cause: e}) - else if (e.name === 'SyntaxError') // Jest stumbling over ESM - throw new Error (`Jest failed to load ESM package '${mod}'.` - + `\nDowngrade '${mod}' to the major version before, or use a different test runner like 'node --test'.\n`, {cause: e}) - else if (e.code === 'ERR_REQUIRE_ESM') // node --test on older Node versions - throw new Error (`Failed to load ESM package '${mod}'. This only is supported on Node.js >= 23.` - + `\nUpgrade your Node.js installation or downgrade '${mod}' to the major version before.\n`, {cause: e}) - else throw e - }} + // function require (mod) { try { return _require (mod) } catch(e) { + // if (e.code === 'MODULE_NOT_FOUND') + // throw new Error (`Failed to load required package '${mod}'. Please add it thru:` + // + `\n npm add -D chai chai-as-promised chai-subset`, {cause: e}) + // // else if (e.name === 'SyntaxError') // Jest stumbling over ESM + // // throw new Error (`Jest failed to load ESM package '${mod}'.` + // // + `\nDowngrade '${mod}' to the major version before, or use a different test runner like 'node --test'.\n`, {cause: e}) + // // else if (e.code === 'ERR_REQUIRE_ESM') // node --test on older Node versions + // // throw new Error (`Failed to load ESM package '${mod}'. This only is supported on Node.js >= 23.` + // // + `\nUpgrade your Node.js installation or downgrade '${mod}' to the major version before.\n`, {cause: e}) + // else throw e + // }} } // set expect(x) { super.expect = x } get expect() { return this.chai.expect } diff --git a/package.json b/package.json index 206529d..74bd31b 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ }, "dependencies": { "axios": "^1", - "chai": "^4.4.1", - "chai-as-promised": "^7.1.1", + "chai": "^6", + "chai-as-promised": "^8", "chai-subset": "^1.6.0" }, "peerDependencies": { diff --git a/test/chai.test.js b/test/chai.test.js new file mode 100644 index 0000000..3a30138 --- /dev/null +++ b/test/chai.test.js @@ -0,0 +1,27 @@ +// jest.unstable_shouldLoadAsEsm = ()=>false + +// Requires jest to be run with NODE_OPTIONS="--experimental-vm-modules" +it.skip ('should load chai via dynamic import', async ()=>{ + const chai = await import('chai') + console.log (chai) + chai.expect(chai).to.exist + expect(chai).toBeDefined() +}) + +// Supported by Node 24, but not by jest's monkey-patched require implementation +it.skip ('should load chai via createRequire', async ()=>{ + const chai = require ('chai') + console.log (chai) + chai.expect(chai).to.exist + expect(chai).toBeDefined() +}) + +// Supported by Node 24, but not by jest's monkey-patched createRequire implementation +it.skip ('should load chai via createRequire', async ()=>{ + const { createRequire } = require ('module') + require = createRequire (__filename) + const chai = require ('chai') + console.log (chai) + chai.expect(chai).to.exist + expect(chai).toBeDefined() +}) \ No newline at end of file