Skip to content

Incompatibility with node v20.0.0 #513

@stixx200

Description

@stixx200

Description

Issue

I wan't to get testdouble working on Node.js v20.0.0
Node.js v20.0.0 introduces a segregation of loader code and production code
In the changelog, they call it "Loader hooks are executed off the main thread" (https://nodejs.org/api/esm.html#modules-ecmascript-modules)

With this segregation, it is only possible to communicate via a messagePort with the loader. But this only allows to send copied values, no shared objects or modules.

Is there a way to run testdouble.js with Node v20.0.0?

Environment

  • node -v output: v20.0.0
  • npm -v (or yarn --version) output: npm 9.6.4
  • npm ls testdouble (or yarn list testdouble) version: testdouble@3.17.2

Failing Test

Example Repo

// test.js
import * as td from 'testdouble';

await td.replaceEsm('./foo.js', { foo: () => "foomocked" });

const { print } = await import("./other.js");
print();
// other.js
import { foo } from "./foo.js";

export function print() {
    console.log("imported", foo());
}
// foo.js
export const foo = () => "foo.js"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions