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

Enforce _foo.default || _foo to import lib files in tests #14673

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jun 19, 2022

Q                       A
Tests Added + Pass? Yes
License MIT

This is another step towards #13414. Unfortunately importing a default import from ESM has different behavior depending on if the imported file is compiled to CJS or not: in one case you need to use import _x; const x = x.default, in the other case only import x;.

This PR updates our tests (which are currently our only ESM files) to use _foo.default || _foo, so that they work both with ESM sources and with compiled sources.
Since we still only runs our tests by compiling our sources to CommonJS, I added a custom (temporary) lint rule to enforce it.

@nicolo-ribaudo nicolo-ribaudo added this to In progress in Move to native ES modules via automation Jun 19, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Jun 19, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52268/

@nicolo-ribaudo

This comment was marked as resolved.

@nicolo-ribaudo nicolo-ribaudo changed the title Force _foo.default || _foo fallback to import lib files in tests Enforce _foo.default || _foo fallback to import lib files in tests Jun 19, 2022
@nicolo-ribaudo
Copy link
Member Author

I'm merging this with a single approval, since:

  • it only affects test files
  • it doesn't change any test, but only some boilerplate code

@nicolo-ribaudo nicolo-ribaudo changed the title Enforce _foo.default || _foo fallback to import lib files in tests Enforce _foo.default || _foo to import lib files in tests Jun 19, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit f0ec180 into babel:main Jun 19, 2022
Move to native ES modules automation moved this from In progress to Done Jun 19, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the import-default-test-fallback branch June 19, 2022 20:14
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Sep 19, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: tests outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Development

Successfully merging this pull request may close these issues.

None yet

3 participants