testdouble / testdouble.js

A minimal test double library for TDD with JavaScript
MIT License
1.42k stars 142 forks source link

ES module replacement changed in Node 18.6 #495

Closed tari closed 2 years ago

tari commented 2 years ago

Description

Node 18.6 breaks ES module replacement.

Issue

Starting from Node 18.6.0, the ES module replacement API provided by node is changed in an incompatible way that causes runtime failure. Representative output from running my package's tests:

$ mocha --loader=testdouble my/test
(node:43) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:43) DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: getFormat, getSource
  connection handling
    1) "before each" hook for "connects"
    2) "after each" hook for "connects"
  0 passing (680ms)
  2 failing
  1) "before each" hook for "connects":
     Error [ERR_LOADER_CHAIN_INCOMPLETE]: "testdouble 'load'" did not call the next hook in its chain and did not explicitly signal a short circuit. If this is intentional, include `shortCircuit: true` in the hook's return.
      at new NodeError (node:internal/errors:387:5)
      at ESMLoader.load (node:internal/modules/esm/loader:624:13)
      at async ESMLoader.moduleProvider (node:internal/modules/esm/loader:472:11)
      at async link (node:internal/modules/esm/module_job:67:21)
  2) "after each" hook for "connects":
     TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.
      at Object.convert (node_modules/jsdom/lib/jsdom/living/generated/Node.js:749:11)
      at HTMLBodyElement.removeChild (node_modules/jsdom/lib/jsdom/living/generated/Node.js:323:29)
      at Context.<anonymous> (file:///builds/cemetech/7/sax/frontend/test/ui.test.mjs:26:17)
      at process.processImmediate (node:internal/timers:471:21)

Environment

node:current docker image, currently corresponding to 18.6.0 (node@sha256:c9504e6bdd0498b99acbf392b94e4d0d56b2c6a37e52b5766cfb909894d9f389).

searls commented 2 years ago

Can you share what version of quibble you're using? @giltayar just made a change in quibble@0.6.12 that likely fixes this

tari commented 2 years ago

Looks like I'm on 0.6.8 right now. I'll check that updating fixes it.

giltayar commented 2 years ago

The update fixes exactly that. :-)

tari commented 2 years ago

Verified that updating quibble to 0.6.12 in my environment fixes the issue; thanks!

FossPrime commented 2 years ago

Found this issue on google, so hope this helps anyone who also does...

Had the same issue with Mocha 10 combined with ts-node 10.7.0. Updated ts-node to 10.9.1 and that fixed the issue.

Of note... I'm on Node LTS 16.17.0, which means the change has been backported. I'm not sure what the best solution for loading typescript into mocha is in 2022, but if using experimental features is still necessary, I'd rather just with naked Node.js or Vitest instead.