-
Notifications
You must be signed in to change notification settings - Fork 47
How to cover JSX / React components? #55
Comments
+1 |
1 similar comment
+1 |
I sent a PR #61 for this. |
Now only workaround is change all your jsx files to js. |
Closes with #61 |
I tried with above mentioned istanbul config with 3.0.4, but I still cannot get .jsx to show up in test coverage report. Are there additional steps that need to be taken to get this to work? |
Same here like @larpo . My instrumentation:
root: src
extensions:
- .js
- .jsx
reporting:
reports:
- text
- html |
setup a .istanbul.yml
and add in your isparta config
First for istanbul, second for isparta, they are different. |
Unfortunately it does not work. If I make a $ babel-node ./node_modules/.bin/isparta --include "**/*.js" --include "**/*.jsx" cover _mocha -- src/** nothing happens. No reporting at all. As well the istanbul documentation $ babel-node ./node_modules/.bin/isparta -i "**/*.js" -i "**/*.jsx" cover _mocha -- src/** I get a syntax error: /Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/lib/transformation/file/index.js:670
throw err;
^
SyntaxError: /Users/screendriver/Development/my_project/node_modules/isparta/node_modules/which/which.js: Invalid number (19:21)
17 | } else {
18 | isExe = function isExe (mod, uid, gid) {
> 19 | var ret = (mod & 0001)
| ^
20 | || (mod & 0010) && process.getgid && gid === process.getgid()
21 | || (mod & 0100) && process.getuid && uid === process.getuid()
22 | || (mod & 0110) && process.getuid && 0 === process.getuid()
at Parser.pp.raise (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.readNumber (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/tokenizer/index.js:666:12)
at Parser.getTokenFromCode (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/tokenizer/index.js:474:21)
at Parser.readToken (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/tokenizer/index.js:160:17)
at Parser.<anonymous> (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/plugins/jsx/index.js:445:20)
at Parser.readToken (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/plugins/flow.js:736:22)
at Parser.nextToken (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/tokenizer/index.js:151:19)
at Parser.next (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/tokenizer/index.js:88:10)
at Parser.pp.parseExprOp (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:185:12)
at Parser.pp.parseExprOps (/Users/screendriver/.nvm/versions/io.js/v2.5.0/lib/node_modules/babel/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:167:17) |
if there is a config file try |
Ok, I finally got it to work. The trick was to move the --include args to after the cover part like this:
and make sure the 'extensions' in .istanbul.yml was correctly aligned inside instrument:
|
For anyone this might help this works for us And in our .istanbul.yml file: instrumentation:
root: src
extensions:
- .jsx
- .js |
I'm using the command pattern suggested by @larpo. What I'm seeing is that the Here is my command: "scripts": {
"pretest": "rm -rf coverage",
"test": "BABEL_ENV=test babel-node node_modules/isparta/bin/isparta cover --include '**/*.js*' _mocha"
}, and instrumentation:
root: src
excludes: ['*_test.js*']
extensions:
- .js
- .jsx and
|
For those arriving in desperation from Google (this is first hit), the magic word is 'babel-istanbul'. You can see http://stackoverflow.com/a/33725069/1320510 for a correct write-up as of April, 2017. |
isparta
only covers *.js files. How can I enable coverage for *.jsx files? I already added the .jsx extension to my.istanbul.yml
but unfortunately it's not working.package.json
.istanbul.yml
The text was updated successfully, but these errors were encountered: