Comments (5)
I'll take a look soon.
from jest.
Fixed with the new version of @swc/jest
.
You can use v0.2.0
to do this.
from jest.
This is now actually a major blocker for using ESM in jest (jestjs/jest#9430).
When I comment out the line that forces commonjs
:
Line 48 in 9d81a9a
And use these configs:
// jest.config.js
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
// testEnvironment: 'jsdom', // Irrelevant for the bug. Enable at will.
transform: {
'^.+\\.tsx?$': '@swc/jest'
},
extensionsToTreatAsEsm: ['.ts']
};
// .swcrc
{
"sourceMaps": true,
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true, // Might as well be false, if not transpiling `.tsx`.
"decorators": false,
"dynamicImport": true // Required.
},
"target": "es2020",
"loose": true
}
}
ESM and jest work just fine, with the limitations noted in the tracking issue: jestjs/jest#9430
from jest.
Much appreciated! Thank you. 💖
What do you think a good long-term plan would be for the config patching? AFAICT, these options are crucial when wanting to use TypeScript & ESM with jest:
{
"sourceMaps": true, // Important
"jsc": {
"parser": {
"syntax": "typescript", // Important
"tsx": true, // Depending on whether `.tsx` is targeted as well.
// "decorators": false,
"dynamicImport": true // Important.
},
"target": "es2020" // I think that was important for dynamic import stuff.
},
"module": null // Important
}
{
transform: {
'^.+\\.tsx?$': '@swc/jest'
},
extensionsToTreatAsEsm: ['.ts', '.tsx']
}
It would be nice, if these options could eventually be applied correctly out-of-the-box.
from jest.
{
"sourceMaps": true, // Maybe this should be true by default.
"jsc": {
"parser": {
"syntax": "typescript", // Should be specified, because jest can be used with non-ts codes.
"tsx": true, // Making this true will just work, if it's accepted by tsc
// "decorators": false,
"dynamicImport": true // If this is required by jest? If so, it should be default
},
"target": "es2020" // Not important for dynamic imports.
},
"module": null // This is null by default
}
from jest.
Related Issues (20)
- Context is undefined while initialising state for class component HOT 2
- swcrc is imported again after having removed fields in jest config, or changing them HOT 4
- class Decorator not working with @swc/jest HOT 1
- `.swc` directory is created HOT 3
- semicolon bug with nestjs
- jest works fine, but with the coverage flag many tests fail HOT 1
- /* istanbul ignore next */ not working HOT 3
- Jest: clone is not a function HOT 3
- follow on swc/jest with plugins HOT 4
- Module @swc/jest should have "jest-preset.js" or "jest-preset.json" file at the root. HOT 1
- ReferenceError: setImmediate is not defined HOT 1
- "SyntaxError: Unexpected identifier" for AsyncDisposable HOT 5
- env and jest.target cannot be used at same time HOT 1
- CustomEvent thrown `TypeError` is not an instance of `TypeError` HOT 4
- Cannot find module error after upgrading `@swc/core` HOT 1
- `@swc/jest` is has nothing to do with `/node_modules/` problem HOT 4
- transform automatic for react not working inside yarn workspace
- Is there a docs for usage in react native ?
- The coverage percent of babel-jest and @swc/jest are different HOT 2
- ReferenceError: React is not defined with tsx HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest.