-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Loading .cjs config files on Node 13 #9086
Comments
Sorry, I don't follow. What's the issue in Jest? |
The problem is that after upgrade of Node from 12.15 to 12.16 warning become an error. I have a So in essence this ticket also applies to Node 12, not just 13 as mentioned in title. |
Aha! Gotcha, thanks for clarifying. You can rename the file to |
It will break differently, unfortunately. If I rename
Then if I rename
... the problem is that our previous release (for which we're doing patches now) was on Jest 24... And we cannot do major version upgrade that easily due to policies etc etc. |
That second one looks weird... Babel supports That won't help if you're stuck on Jest 24 though, as Jest won't recognize the config file... If your config file is just JSON you use that, or do some fancy hacks like putting your config in a preset in another module and load that in Jest (which should circumvent the |
@kirill-konshin This is an issue with your setup, probably some glob/regexs in config files are broken because of changed extensions. I'm using Node yarn
yarn test |
@SimenB you're right, our babel in that outdated branch is So far we just downgraded to Node 12.15... I wonder how come such breaking change made its way to minor release. Thank you for support! |
@kirill-konshin I'm not sure if experimental features are a part of stable API. Also, it isn't really a change, because importing a file with |
@the-spyke somehow it worked on Node 12.15. It produced warnings, but code worked fine. |
@kirill-konshin Yeah, because it was experimental and did some things not as it should. That's why there was a warning: when implementation of ESM finishes |
The most frustrating about this experimental feature is the transition from "no warning" to "warning" and then to "error" all within minor release... |
If I run
This directly contradicts the jest documentation:
|
@emma-borhanian with jest 25? cjs and mjs support landed in 25 (in theory) |
@SimenB Yup, jest 25. Maybe you missed a spot? if (
argv.config &&
!isJSONString(argv.config) &&
!argv.config.match(/\.js(on)?$/)
) {
throw new Error(
'The --config option requires a JSON string literal, or a file path with a .js or .json extension.\n' +
'Example usage: jest --config ./jest.config.js',
);
} undercut test log: https://gist.github.com/emma-borhanian/94a233217b2f8551157291aa3adcc956 |
This allows for `"type": "module"` in package.json while also using a mocha config file, which was previously impossible. See: https://nodejs.org/api/esm.html Compare to jestjs/jest#9086
@emma-borhanian Indeed, I somehow forget to patch |
Aha, good catch @emma-borhanian! |
Hi guys, this is really nice feature for future versions of Node. But I still have one problem with this. My script for the test is defined as:
Running on Node v13.9.0 Then I have jest.config.cjs file with the setup:
And babel.config.json as:
Package versions are updated: But I am still getting the error below when I run my tests... _/Volumes/FjoogaDEV/projects/fjooga-api/test/unit/Organisation.test.js:1
What am I doing wrong? Thank you in advance guys. |
@bouchja1 Your test file has .js extension, but Jest transformer is set to .mjs extension. |
That could be a problem. I have renamed it to *.mjs (and added
to jest.config.cjs but it says "No tests found, exiting with code 0" now... This is that test and I think it is written correctly.
EDIT: I am able to run the test after adding this to jest.config.cjs...
|
@bouchja1 As you've renamed tests to In general, you shouldn't rename files into |
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. |
🚀 Feature Proposal
If you have Node 13 and
jest.config.js
file in a package withtype=module
then Node will emit a warning:In case of manually specifying the config fole with
--config jest.config.cjs
it fails with an error:Using ES Modules syntax for config file gives an error too:
The issue is the same as babel/babel#10595.
.cjs
is mandatory, but being able to load an ESM from.js
or.mjs
is nice to have too.Motivation
Support ES Modules workflows in Node13+
Example
Configuring Jest in packages with
type=module
and config file namedjest.config.cjs
Pitch
The text was updated successfully, but these errors were encountered: