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

[bug] jest can't process ES6 modules with .mjs extension. #5204

Closed
awidjaja opened this issue Jan 2, 2018 · 5 comments
Closed

[bug] jest can't process ES6 modules with .mjs extension. #5204

awidjaja opened this issue Jan 2, 2018 · 5 comments

Comments

@awidjaja
Copy link

awidjaja commented Jan 2, 2018

Do you want to request a feature or report a bug?

bug

What is the current behavior?

Jest testmatch filter currently doesn't work (ignores .mjs extension).
my work around is to rename all .mjs to .js and transpile them through babel for testing only 😢

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

  • configure jest testMatch
        "testMatch": [ 
          '**/spec/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)', 
          '**/spec/**/*.mjs', '**/?(*.)(spec|test).mjs' 
        ],
  • create a simple test.mjs module and use import declaration.
  • run jest

What is the expected behavior?

Jest will find the matching .mjs files and either:
execute the import statement natively (pass experimental flag if node version is 8.9.3 above) or,
transpile the .mjs files using babel.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

version:
Jest: v21.2.1
Node: 8.9.3
Yarn: 1.2.3

"jest": {
    "roots": [
      "<rootDir>/src/",
      "<rootDir>/spec/"
    ],
    "transform": {
      "^.+\\.m?jsx?$": "babel-jest"
    },
    "testMatch": [ 
      '**/spec/**/*.js?(x)', '**/?(*.)(spec|test).js?(x)', 
      '**/spec/**/*.mjs', '**/?(*.)(spec|test).mjs' 
    ],
    "testPathIgnorePatterns": [
      "/node_modules/",
      "/dist/"
    ],
    "verbose": true
  },
@Haroenv
Copy link
Contributor

Haroenv commented Jan 2, 2018

duplicate of #4637

@thymikee
Copy link
Collaborator

thymikee commented Jan 2, 2018

Thank you @Haroenv!

@thymikee thymikee closed this as completed Jan 2, 2018
@DenKorn
Copy link

DenKorn commented Feb 5, 2020

duplicate of #4637

No, this issue regards using Jest without Babel. I guess the issue should be reopened.

@SimenB
Copy link
Member

SimenB commented Feb 5, 2020

This issue explicitly sets babel-jest up to transpile mjs, look at the config in the OP.

If you wanna track native mjs support in jest, follow #4842 and #9430.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants