🐛 Bug: esm-utils (mocha.addFile) should support URL #4993
Labels
area: node.js
command-line-or-Node.js-specific
status: accepting prs
Mocha can use your help with this one!
type: bug
a defect, confirmed by a maintainer
Prerequisites
faq
labelnode_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
According to the official Node.js documentation, ES modules are resolved and cached as URLs. However,
esm-utils
does not support loading files from a URL.Reference: https://nodejs.org/docs/latest-v18.x/api/esm.html#urls
Steps to Reproduce
npm init -y
(make sure to use a recent version of Node >= 18)npm i mocha@10.2.0 --save
type": "module"
inpackage.json
index.js
suite.js
node index.js
Using
.mjs
extension does fail as well:Expected behavior:
Mocha should be able to load ES modules from URL (
file://
).Actual behavior:
Module is not found :(
Reproduces how often:
100%
Versions
mocha --version
andnode_modules/.bin/mocha --version
: 10.2.0node --version
: v18.16.1Additional Information
It should also support query parameters and fragments. That's particularly useful when you want to load a test suite more than once:
Otherwise, the file will be loaded only on the first
mocha
instance:Please note that
mocha.dispose
,mocha.unloadFiles
has no effect (as mentioned in the JSDoc):Thanks!
The text was updated successfully, but these errors were encountered: