Giter Site home page Giter Site logo

Comments (3)

codan84 avatar codan84 commented on June 15, 2024

I use testdouble with ava and it seems to work on node 20.
Initially it started failing after upgrading to node 20, but switching loader ts-node/esm to --import=tsimp/import for TypeScript worked.
https://www.npmjs.com/package/tsimp
I appreciate you might not be using Ava, but this might help with whatever other test framework you are using.
My Ava config, for reference:

export default {
  cache: false,
  failWithoutAssertions: false,
  extensions: {
    ts: 'module'
  },
  nodeArguments: [
    '--import=tsimp/import',
    '--import=testdouble'
  ]
}

from testdouble.js.

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024

This is almost surely caused by the testdouble loader's resolve hook stomping other loaders' resolve hooks (perhaps a short-circuit?). This is the case for https://github.com/JakobJingleheimer/nodejs-loaders:

node --loader=testdouble --loader=nodejs-loaders/dev/tsx ./main.mts
// main.mts

import './foo.mts'; // the contents of foo.mts doesn't matter
node --loader=testdouble --loader=nodejs-loaders/dev/css-module ./main.mjs
// main.mjs

import './foo.module.css'; // the contents of foo.module.css doesn't matter

These work fine when --loader=testdouble is removed.

This issue occurs in node v20 and node v21.

from testdouble.js.

JakobJingleheimer avatar JakobJingleheimer commented on June 15, 2024

I believe the issue may be caused by
https://github.com/testdouble/quibble/blob/main/lib/quibble.mjs#L58
https://github.com/testdouble/quibble/blob/main/lib/quibble.mjs#L66

There is more output from await resolve() than just url (format and importAttributes), and that omitted output must be included in the return:

  try {
-   const { url } = await resolve()
+   const { url, ...ctx } = await resolve()

    const quibbledUrl = addQueryToUrl(url, '__quibble', stubModuleGeneration)

    if (url.startsWith('node:') && !getStubsInfo(quibbledUrl)) {
      return { url }
    }

-   return { url: quibbledUrl }
+   return { ...ctx, url: quibbledUrl }
  } catch (error) {

I confirmed the above fixes the issue (by manually editing quibble in my node_modules).

A caveat though: the above fix is potentially only half the cause. Quibble's query params dupe node's path.extname (et al) as well as endsWith(): path.extname('foo.mts?__quibble=0')'.mts?__quibble=0', which can cause the other loaders (such as the ones I cited in the above #525 (comment)) to fail to recognise the file.

from testdouble.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.