Closed
Description
Description
custom loaders like ts-node have a really hard time figuring out the mocha "binary"
The binary lacks.js or cjs extensions. Changing the node_modules/.bin/mocha
extension isn't enough.
Steps to Reproduce
- Sandbox: https://codesandbox.io/s/mocha-ts-node-16-ctt5k?file=/package.json
- Open Terminal
- Run
npm run broken-test-npx
or runsource env.sh; mocha test/test.js
OR
npm install ts-node typescript @types/mocha mocha
on atype: "modules"
project.json- Set
export NODE_OPTIONS="--loader ts-node/esm/transpile-only"
- Run
npx mocha test/any-test-at-all.js
Expected behavior:
No errors, tests run.
Actual behavior:
Setting a loader prevents node from running the mocha binary, in any way
$ npm run test # Copies mocha to mocha.js as workaround
3 passing (3ms)
$ npm run test-cjs # Copies mocha to mocha.cjs as workaround
1 passing (2ms)
$ npm run broken-test-npx # Node cant tell what loader to use and errors out
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /sandbox/node_modules/mocha/bin/mocha
$ npm run broken-test-direct # same behavior as before
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /sandbox/node_modules/mocha/bin/mocha
Reproduces how often: 100% of the time
Versions
- The output of mocha: 8.4.0
- The output of
node --version
: 14 (Sandbox) and 16 as well - Your operating system
- name and version: yes
- architecture (32 or 64-bit): 64
- Your shell (e.g., bash, zsh, PowerShell, cmd):
- Your browser and version (if running browser tests):
- Any third-party Mocha-related modules (and their versions):
- Any code transpiler being used (and its version): ts-node loader
Additional Information
Transpile only mode does not make a difference. Extension of tests do not make a difference. As long as the loader boots up, when node proceeds to guess which loader to use, node errors out.
Metadata
Metadata
Assignees
Labels
No labels