Skip to content

Conversation

legendecas
Copy link
Contributor

@legendecas legendecas commented Jun 19, 2025

PR Checklist

Overview

Add module loader test.

@legendecas
Copy link
Contributor Author

legendecas commented Jun 19, 2025

Hmm, it seems like the new test fails starting with Node.js v22.12.0 (which should be addressed by the revert).

@voxpelli
Copy link
Member

@legendecas Can we add the tests independently of #5381?

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds tests for validating the support of ESM module hooks and loader compilers, including tests to cover both standard and top‐level await functionality. Key changes include:

  • Adding integration tests for files with .js and .ts extensions.
  • Creating new ESM loader fixture files and corresponding compiled test files.
  • Updating ESLint configuration to support top-level await in the ESM test files.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/integration/compiler-esm.spec.js New integration tests for ESM module hook compilers using .js/.ts test files.
test/compiler-fixtures/esm.fixture.js Fixture that registers the ESM loader via Module.register.
test/compiler-fixtures/esm-loader.fixture.mjs Defines the custom ESM loader for reading compiled fixture files.
test/compiler-esm/test.ts.compiled Compiled TS test file validating ESM behavior.
test/compiler-esm/test.ts Source TS test file for ESM.
test/compiler-esm/test.js.compiled Compiled JS test file validating ESM behavior.
test/compiler-esm/test.js Source JS test file for ESM.
test/compiler-esm/test-tla.ts.compiled Compiled TS test file with top-level await to validate ESM TLA behavior.
test/compiler-esm/test-tla.ts Source TS test file with top-level await feature.
test/compiler-esm/test-tla.js.compiled Compiled JS test file with top-level await.
test/compiler-esm/test-tla.js Source JS test file with top-level await.
test/compiler-esm/package.json Package file setting the module type to ESM for tests.
eslint.config.js ESLint config update to handle top-level await in ESM files.
Comments suppressed due to low confidence (1)

test/compiler-esm/test-tla.ts.compiled:12

  • Add a comment explaining the purpose of 'await undefined' to clarify that it is intentionally used to test top-level await functionality.
await undefined;

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks solid to me!

I think this PR in conjunction with #5384 is a very good solution to the introduced 11.17.0 issues.

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review June 24, 2025 12:05
@legendecas

This comment was marked as outdated.

@JoshuaKGoldberg
Copy link
Member

We can ignore the compliance bot, it's just reporting that this doesn't fix a linked issue. This is fine.

@legendecas
Copy link
Contributor Author

I added two new test cases to cover CJS format with module loaders..

@legendecas legendecas force-pushed the require-esm-test branch 2 times, most recently from cd7fc27 to a9dbb2d Compare June 24, 2025 12:27
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Jun 24, 2025

Fantastic, even better! I'm ready to merge this whenever you are. 👍

Edit: assuming all test failures are also happening on main (i.e. are not introduced by this PR)

@legendecas
Copy link
Contributor Author

Seems like the new tests fails on v18. I'm going to split them up to a follow-up PR.

@legendecas
Copy link
Contributor Author

legendecas commented Jun 24, 2025

This should be ready to be reviewed again. The compliance failure seems due to no associated issue. Update: done

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @legendecas! 🔥

@JoshuaKGoldberg JoshuaKGoldberg merged commit f58e49f into mochajs:main Jun 24, 2025
75 of 76 checks passed
@legendecas legendecas deleted the require-esm-test branch June 24, 2025 13:32
@jdmarshall
Copy link

This test breaks Node 18 compatibility.

Module.register doesn't exist until Node 20 and then it's a candidate feature.

@JoshuaKGoldberg
Copy link
Member

This test breaks Node 18 compatibility.

What do you mean?

@jdmarshall
Copy link

What do you mean?

Module.register doesn't exist until Node 20 and then it's a candidate feature.

You're relying on effectively experimental APIs that don't even exist in the set of Node versions in package.json->engines

@JoshuaKGoldberg
Copy link
Member

Module.register doesn't exist until Node 20

It's in 18: https://nodejs.org/docs/latest-v18.x/api/module.html#moduleregisterspecifier-parenturl-options. We can also tell it's in 18 because the integration tests on this PR, then on main, passed: e.g. https://github.com/mochajs/mocha/actions/runs/15851891395/job/44687301757

candidate feature
effectively experimental APIs

Well, at the time of authoring in 18 and 20, they were. But now that 18 is EOL and 20 is no longer under active development, they're roughly stable. It's quite unlikely that 20 would take in a change that alters Module.register. But, if it does, this is just internal test code -- we can always change it internally. Nothing in this PR impacts end users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants