You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now teenytest uses synchronous require to load test files. This doesn't work for .mjs (ESM) since module loading/execution is asynchronous. What mocha does is to require first, catch ERR_REQUIRE_ESM, and then attempt import of the file.
Test file:
// example.test.mjsimportassertfrom'assert';classDog{bark(length){returnArray.from({ length },(_,idx)=>`Woof #${idx}`);}}exportfunctionbeforeEach(){this.subject=newDog('Sam');}exportconstbark={once(){assert.deepEqual(this.subject.bark(1),['Woof #0']);},twice(){assert.deepEqual(this.subject.bark(2),['Woof #0','Woof #1']);},};exportconsttag={frontSaysName(){assert.equal(this.subject.tag('front'),'Hi, I am Sam');},backSaysAddress(){assert.equal(this.subject.tag('back'),'And here is my address');},};
Result:
$ teenytest examples/teenytest/test/example.test.mjsinternal/modules/cjs/loader.js:998 throw new ERR_REQUIRE_ESM(filename); ^Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/examples/teenytest/test/example.test.mjs at Module.load (internal/modules/cjs/loader.js:998:11) at Function.Module._load (internal/modules/cjs/loader.js:899:14) at Module.require (internal/modules/cjs/loader.js:1040:19) at require (internal/modules/cjs/helpers.js:72:18) at /path/to/node_modules/teenytest/lib/prepare/modules/load.js:11:22 at arrayMap /path/to/node_modules/lodash/lodash.js:639:23) at Function.map /path/to/node_modules/lodash/lodash.js:9554:14) at module.exports /path/to/node_modules/teenytest/lib/prepare/modules/load.js:9:12) at /path/to/node_modules/teenytest/lib/prepare/modules/index.js:9:7 at arrayMap /path/to/node_modules/lodash/lodash.js:639:23) { code: 'ERR_REQUIRE_ESM'}
The text was updated successfully, but these errors were encountered:
Right now teenytest uses synchronous
require
to load test files. This doesn't work for.mjs
(ESM) since module loading/execution is asynchronous. What mocha does is torequire
first, catchERR_REQUIRE_ESM
, and then attemptimport
of the file.Test file:
Result:
The text was updated successfully, but these errors were encountered: