Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

td.replaceEsm does not work when specifier is resolved via loader #528

Closed
7 tasks
JakobJingleheimer opened this issue Mar 14, 2024 · 1 comment · May be fixed by testdouble/quibble#109
Closed
7 tasks

Comments

@JakobJingleheimer
Copy link
Contributor

JakobJingleheimer commented Mar 14, 2024

Description

When the specifier provided to replaceEsm() needs to be resolved by a loader, the resolution is done correctly, but testdouble is not using the resolved value, which causes the replacement to actually fail:

node --loader=testdouble --loader=alias-resolver ./main.mjs
// main.mjs

await ts.replaceEsm('…/foo.mjs', { isFake: true });
console.log('foo:', await import('…/foo.mjs')) // the original foo.mjs

Where alias-resolver replaces …/ and provides the true url.

Environment

  • node -v output: 21.7.0 (and also 20.11.1)
  • npm -v (or yarn --version) output: 10.5.0
  • npm ls testdouble (or yarn list testdouble) version: 3.20.1

Failing Test

  • Fork the repo
  • Add a failing test (probably to the `/regression/src' directory)
  • Submit a pull request for the failing test or link to your branch here

Example Repo

Reproduction: JakobJingleheimer/td-global-mock@0008fb5
"Fixed": JakobJingleheimer/td-global-mock@e5775aa

This is truly mind-bending because all the urls testdouble output are correct (ex from td.listReplacedModules()), so everything appears to be working—except that it clearly isn't.

Runkit Notebook

  • Create a Runkit notebook
  • Invoke var td = require('testdouble') at the top
  • Verify the behavior your issue is concerned with by clicking "Run"
  • Link to the Runkit here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant