Jest: support jest.config.mjs and jest.config.cjs

Created on 23 Nov 2019  路  4Comments  路  Source: facebook/jest

馃殌 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)
Feature Request

Most helpful comment

@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.

All 4 comments

this is pretty much blocked by #4842.

@SimenB jest.config.cjs is not blocked by experimental-loader API.

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?

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mmcgahan picture mmcgahan  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments

hramos picture hramos  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

ticky picture ticky  路  3Comments