nyc: TSX file with JSX element can not be instrumented
Link to bug demonstration repository
My personal repo: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/tree/code-coverage-issue
What I have done:
1. Install dependencies of code-coverage for cypress and nyc
, I did run below command:
yarn add -D @cypress/code-coverage @istanbuljs/nyc-config-typescript @testing-library/cypress nyc source-map-support ts-node istanbul-lib-coverage
2. Other than that, I made below changes in package.json
with configs for nyc
:
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"report-dir": ".cypress-coverage",
"extension": [
".js",
".ts",
".tsx"
],
"include": [
"public/**/*.{js,ts,tsx}"
],
"exclude": [
"**/*.test.{ts,tsx}",
"**/__mocks__/**",
"**/__test__/**"
],
"reporter": [
"json",
"html"
]
},
package.json
: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/package.json
3. I run command:
yarn nyc instrument --compact false public .instrumented
I find all the .ts
files are instrumented as expected, while .tsx
and .js
files are not instrumented at all.
Result .ts
file[Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/hooks/useDelayedLoader.ts
Result .tsx
file[Not Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/components/ContentPanel/ContentPanel.tsx
Result .js
file[Not Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/app.js
Expected Behavior
All the .ts
, .tsx
, .js
should be instrumented
Observed Behavior
None of .tsx
and .js
file is instrumented, while all the .ts
files are instrumented as expected.
Troubleshooting steps
- still occurring when I put
cache: false
in my nyc config
Environment Information
โ anomaly-detection-kibana-plugin git:(code-coverage-issue) โ npx envinfo@latest --preset nyc
npx: installed 1 in 2.706s
System:
OS: macOS High Sierra 10.13.6
CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
Memory: 1.37 GB / 16.00 GB
Binaries:
Node: 10.21.0 - ~/.nvm/versions/node/v10.21.0/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.14.4 - ~/.nvm/versions/node/v10.21.0/bin/npm
npmPackages:
@babel/plugin-proposal-class-properties: ^7.5.5 => 7.10.1
@babel/plugin-proposal-object-rest-spread: ^7.5.5 => 7.10.1
@babel/preset-env: ^7.5.5 => 7.10.2
@babel/preset-react: ^7.0.0 => 7.10.1
@babel/preset-typescript: ^7.3.3 => 7.10.1
babel-eslint: ^9.0.0 => 9.0.0
babel-jest: ^24.8.0 => 24.9.0
babel-polyfill: ^6.26.0 => 6.26.0
eslint-plugin-babel: ^5.2.0 => 5.3.0
istanbul-lib-coverage: ^3.0.0 => 3.0.0
nyc: ^15.1.0 => 15.1.0
source-map-support: ^0.5.19 => 0.5.19
ts-node: ^8.10.2 => 8.10.2
typescript: 3.0.3 => 3.0.3
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 17
I am having the same issue and this did not resolve it for me either. After some investigation, it seems to me that
parser-plugins
option inpackage.json
is somehow ignored, as modifying the content ofnode_modules/@istanbuljs/nyc-config-typescript/index.js
to:works.
Anyways, for now I created a small package
nyc-config-tsx
which is basically that. With that package installed, extendingnyc-config-tsx
instead of@istanbuljs/nyc-config-typescript
resolved the issue for me, so perhaps it helps resolve your issue as well @yizheliu-amazon, though it would be nice if this was added directly to the official@istanbuljs/nyc-config-typescript
or there was an official config like@istanbuljs/nyc-config-tsx
.@SimonDanisch I think one way you can do before this issue gets a TRUE fix is to create a new file (e.g. nyc-config.js) which has same code as the updated
@istanbuljs/nyc-config-typescript/index.js
. Then define your nyc configuration as below. By this way, you can manage the fix in your git repo, ๐.nyc-config.js
thank u very much,it works for me!!!
@loreanvictor Thanks for sharing your solution! I will try it and come back with result.
Cool. That is interesting to know. In my understanding, it is an illegal syntax to have JSX element in
.ts
file. Thatโs why I save above change in.tsx
file. Can you save thea.ts
asa.tsx
file and try instrumenting again?@yizheliu-amazon
package.json
a.ts
when i run
./node_modules/nyc/bin/nyc.js instrument a.ts
it got output
but when i remove config
jsx
it output