testdouble / testdouble/testdouble.js
td.replaceEsm() without namedExportStubs throws weird error under windows
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 140
- Avg merge
- 22h
- Merged PRs (30d)
- 1
Description
Description
I was evaluating testdouble to do mocking with native ES modules, but I run into a weird error that seems to be a bug.
Issue
it throws
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at new NodeError (internal/errors.js:322:7)
at defaultResolve (internal/modules/esm/resolve.js:814:11)
at resolve (file:///C:/Users/jishi/Documents/source/lovsta/mynewsdesk/node_modules/quibble/lib/quibble.mjs:12:25)
at resolve (file:///C:/Users/jishi/Documents/source/lovsta/mynewsdesk/node_modules/quibble/lib/quibble.mjs:28:12)
at Loader.resolve (internal/modules/esm/loader.js:89:40)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
at Loader.import (internal/modules/esm/loader.js:177:28)
at importModuleDynamically (internal/modules/cjs/loader.js:1028:27)
at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
at Object.exports.importOriginalModule (node_modules\quibble\lib\esm-import-functions.js:22:74)
at Function.esmImportWithPath (node_modules\quibble\lib\quibble.js:128:41)
at Object.replaceEsModule (node_modules\testdouble\lib\replace\module\index.js:39:50)
at Module.replaceEsm (node_modules\testdouble\lib\replace\index.js:23:21)
at Context.<anonymous> (file:///C:/Users/jishi/Documents/source/lovsta/mynewsdesk/test/acceptance/sync.mjs:6:14)
at processImmediate (internal/timers.js:464:21)
When doing the following:
import * as td from 'testdouble';
describe('test/acceptance/sync.mjs', function () {
beforeEach(async function () {
await td.replaceEsm('../../src/mynewsdesk.mjs');
});
afterEach(function () {
td.reset();
});
it('should fetch and upsert entries', async function () {
});
});
If I add a replacement object as second argument, it doesn't fail:
await td.replaceEsm('../../src/mynewsdesk.mjs', {});
Looking at the source, if I have 2 or more arguments, it just transparently forwards down to quibble.
Environment
-
node -voutput: v14.18.1 -
npm -v(oryarn --version) output: 6.14.15 -
npm ls testdouble(oryarn list testdouble) version: testdouble@3.16.3
Windows 10.
The same code, doesn't throw error if running in Linux, via WSL. Even weirder though is that the code just works, without specifying a loader, however maybe the loader only makes the stubbing works so without an assertion I won't notice it.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with test/acceptance/sync.mjs and the replace flow referenced in lib/replace/module/index.js and lib/replace/index.js. Reproduce the no-second-argument case on Windows, compare it with the replacement-object case, and add a regression test showing that td.replaceEsm() works without named export stubs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100