question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

support jest.config.mjs and jest.config.cjs

See original GitHub issue

🚀 Feature Proposal

jest.config.js is using commonjs. Can we use jest.config.mjs and jest.config.cjs for config file in node 13.2?

Motivation

esm support for config file

Example

// jest.config.mjs
export default {
  // [...]
  // Replace `ts-jest` with the preset you want to use
  // from the above list
  preset: 'ts-jest/presets/js-with-ts',
};

Pitch

Why does this feature belong in the Jest core platform?

Common feature proposals that do not typically make it to core:

  • New matchers (see jest-extended)
  • Changes to the default reporter (use custom reporters instead)
  • Changes to node/jsdom test environments (use custom environments instead)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
the-spykecommented, Dec 10, 2019

@SimenB Yes, it does. I have type=module packages and use Jest+Babel to run tests. But Node 13 refuses to load .js files inside such packages, which means that Jest fails to open a .js config. Moreover, you can’t manually point to a .cjs file because of a check in readConfigs(). I’ve made a similar request in #9086.

2reactions
SimenBcommented, Nov 25, 2019

Does it make sense to add support for this, which is useless outside of esm support in node (which we don’t support)? It’s simple enough in isolation, but I’m not sure it provides much value, and might confuse users more? thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
It is recommended to define the configuration in a dedicated JavaScript, TypeScript or JSON file. The file will be discovered automatically, if it...
Read more >
How to import ".mjs" modules in Jest's xyz.test.js?
I think it would work with following setup: At root level of your app, jest.config.js : module.exports = { testRegex: "(/__tests__/.*|(\\.
Read more >
Presets | ts-jest - GitHub Pages
If you are using custom transform config, please remove preset from your Jest config to avoid issues that Jest doesn't transform files correctly....
Read more >
babel-jest - Awesome JS
[jest-config] Do not warn about preset in ProjectConfig #13583 ... [jest-runtime] Properly support CJS re-exports from dual packages (#13170) ...
Read more >
Config Files - Babel.js
cjs allow you to define your configuration as CommonJS, using module.exports . They have been supported since v7.7.0 . babel.config.mjs and .babelrc.mjs ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found