Comments (12)
@kulshekhar, sorry for the late response. The import issue appeared at the time to come from a missing transform
field in my config. The transform
issue was difficult to track down because I appeared to be seeing a new issue that when the config changed, either through a different file via--config
or when a consistently named config file itself changed, that the cache didn't invalidate. I had planned to report the caching config issue as a standalone bug but unfortunately I can no longer reproduce it. For now, I apologize for the noise and will file a ticket if I can reproduce it again.
from ts-jest.
First time user here. I seemed to have had a similar (?) issue with imports when I accidentally mangled my Jest config to omit transform
. What really bit was me that the cache doesn't invalidate when the config changes. You can really test your config by disabling it, jest --no-cache
. You can check out the recommended example config here. I found the import token error quite cryptic.
from ts-jest.
What version of node you are using? And why do you use "jsx": "preserve"
?
from ts-jest.
@Igmat, sorry, forgot to mention, updated the question. By setting jsx=preserve
i tell typescript to not handle jsx transpilation and let babel do the job. For some reason it works faster than letting typescript transpile it all into es2015.
from ts-jest.
It's strange that it shows Unexpected token import
error.
Could you please share a repro? I have some thoughts but have to check them first.
from ts-jest.
@Igmat here you go https://github.com/dziamid/react-typescript-boilerplate
from ts-jest.
@Igmat did you have a change to have a look at my repro? Just in case: npm install
& npm test
to reproduce the proplem - it should fail on the first test with Unexpected token import
error.
from ts-jest.
@dziamid, sorry, I was too busy at this weekend. I'll take a look and will answer tomorrow.
from ts-jest.
@dziamid, first of all, problem isn't in ATL. Actually webpack and its loaders aren't executed while testing.
First problem is caused by setupTestFrameworkScriptFile
, so could you please tell me why do you need test-bundler.js
? If you use it for coverage, then better option would be to use
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js"
and --no-cache
flag.
Second problem is caused by "jsx": "preserve"
- currently we don't support it. I'll take a closer look on it but it seems that Jest
logic doesn't support using several transformers for one file, so we have only two possible solutions - creating feature request in Jest
and adding babel
transpilation inside ts-jest
, but seconds seems to cause a lot of issues, because I'm not sure that we will be able to correctly reflect user's babel config, and after all it not very good to make one package responsible for several transpilations.
Third problem is caused by your import
statement in several files. Syntax like this:
import H1 from 'components/H1';
doesn't seem to be supported by jest-resolve
, but I'll try to figure out what we can do with it in ts-jest
.
P.S.
After fixing above problems in your config, not all tests will pass, but it seems to happen because of incorrect tests or implementation.
from ts-jest.
Ok, while here is no responses, I think my last comment helped you to fix it. I'll create related TODO issues in order to find a workaround and may be even provide some changes to ts-jest
in order to solve problems with "jsx": "preserve"
and this type of import
statements.
from ts-jest.
Closing this due to #63 and #64 as more accurate issues.
from ts-jest.
@niedzielski I'm slightly confused. Is the issue about the import token error or cache invalidation?
from ts-jest.
Related Issues (20)
- [Bug]: TS 5.2 error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16' HOT 10
- [Bug]: ES6 still doesn't work HOT 1
- [Feature]: Add ability to pass config to presets
- [Bug]: importing `got` v13 package causes Jest to fail to parse the file
- [Bug]: error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'. HOT 1
- [Bug]: TS 5.2 - TypeError: toSorted is not a function HOT 2
- [Bug]: Cannot find module bundle-text (Parcel) HOT 1
- [Bug]: `ts-jest` silently hangs up with certain `moduleResolution` options HOT 13
- [Bug]: Divergent branch coverage in JS and TS reports HOT 1
- [Bug]: Mixed ESM/CJS Typescript files in node_modules HOT 1
- [Bug]: Seems it disrepects "@ts-nocheck"
- [Bug]: Failed to collect coverage from. | 'rootDir' is expected to contain all source files. HOT 2
- [Bug]: Wrong line number at error stack of global setup when using typescript
- [Bug]: Inconsistent hybrid module resolution (index.d.mts vs. index.d.cts) between ts-jest and tsc HOT 3
- [Bug]: Top level await expressions are only .... HOT 6
- [Bug]: Cannot find module '@jest/globals' when cache: false HOT 1
- [Bug]: TS 5.2+ fails if using `nodenext` module resolution and `noEmitOnError` is `true` HOT 2
- [Bug]: TsJestTransformerOptions throw type error
- [Bug]: ESM syntax is not allowed in a CommonJS HOT 1
- [Bug]: Produced source maps seem to have mismatch with file paths
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 ts-jest.