Closed kentcdodds closed 8 years ago
cc @jamestalmage @sindresorhus @sotojuan @novemberborn @vdemedes, if ya'll would have a second to give this a look I'd really appreciate it :-) I'm seeing this in my work project as well.
I've been looking into this for a day now. I don't really have any leads.
Also, maybe @bcoe of the nyc
project would have some insights here :smile:
Thanks for any help/tips you can give. This is an instructional repository and I'd love to be able to remove this section about having to install 9.2.0
when teaching people how to use AVA with React :-)
Another person who may have thoughts: @xjamundx
I think that this is an inter-op issue with React + AVA + nyc somehow...
Here are a few commands you can run to get a quick-start on this:
git clone -b pr/update-ava https://github.com/kentcdodds/react-ava-workshop.git
cd react-ava-workshop/
npm i
./node_modules/.bin/nyc --version
./node_modules/.bin/ava --version
npm t
npm run cover
./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/ava app/**/Customers.test.js --require ./other/setup-ava-tests.js
./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/ava app/**/CustomerList.test.js --require ./other/setup-ava-tests.js
Here's the output I see with those last two commands:
~/Desktop/react-ava-workshop (pr/update-ava)
🍰 $ ./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/ava app/**/Customers.test.js --require ./other/setup-ava-tests.js
3 passed
~/Desktop/react-ava-workshop (pr/update-ava)
🍰 $ ./node_modules/.bin/nyc --reporter=lcov ./node_modules/.bin/ava app/**/CustomerList.test.js --require ./other/setup-ava-tests.js
Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListOfCustomers`. See https://fb.me/react-warning-keys for more information.
4 passed
/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:241
text = structuredText[startLine].text;
^
TypeError: Cannot read property 'text' of undefined
at /Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:241:45
at Array.forEach (native)
at annotateFunctions (/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:224:26)
at HtmlReport.Report.mix.writeDetailPage (/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:427:9)
at /Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:489:26
at SyncFileWriter.extend.writeFile (/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/util/file-writer.js:57:9)
at FileWriter.extend.writeFile (/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/util/file-writer.js:147:23)
at /Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:488:24
at Array.forEach (native)
at HtmlReport.Report.mix.writeFiles (/Users/kdodds/Desktop/react-ava-workshop/node_modules/istanbul/lib/report/html.js:482:23)
A few things you'll notice:
ava
and nyc
$ npm t
works :+1:$ npm run cover
does not work :-(Customers.test.js
tests report coverage just fineCustomerList.test.js
tests fail when reporting coverageThe most noticeable difference between those two files is one has JSX and the other does not. I'm thinking that may have something to do with it...
Note: The AVA docs say that for code coverage you may need to specify inline source maps for coverage to work. But adding this to my .babelrc
doesn't seem make a difference:
"sourceMaps": "inline"
@novemberborn any thoughts on this one, looks like startLine
was invalid? I thought we put some logic in to pin to a valid line number a while back?
@kentcdodds, got a hotfix for you:
npm i -D jamestalmage/ava#hotfix/inline-sourcemaps
@novemberborn
See my commit message in https://github.com/jamestalmage/ava/commit/919a1318cbca11fe9bc8f1da5f2ee5c77d80a4bb
@jamestalmage, I updated the PR and it's still giving me the same error. Am I doing something wrong?
Thanks for looking into this by the way! :tada:
Clear node_modules/.cache
That worked! Any chance this will get patch released today? Or should I just go with the hotfix for now?
I'm not entirely sure my solution is the correct one (I think the problem is elsewhere), so hotfix.
I've opened an AVA PR to discuss
@kentcdodds I have some ideas on what's going here but haven't yet had a chance to dig deeper. I can reproduce the issue locally though so that's good.
Thanks for taking the time to look at it :-)
@kentcdodds nyc is covering your test files and then fails to apply the source maps. That's a separate issue I haven't tracked down yet.
To exclude your test files add the following to your package.json
:
"nyc": {
"exclude": "app/**/*.test.js"
}
Normally nyc excludes ['test', 'test{,-*}.js']
but your tests are in an unusual spot (to me at least).
Oh interesting. Didn't even realize that I was instrumenting the test files. I'll give that a look. But this didn't actually solve the root issue correct? You're still looking at that?
But this didn't actually solve the root issue correct? You're still looking at that?
Indeed. Regardless of the root issue though you probably don't want to be instrumenting the test files.
If course :-)
Mind if I submit a pull request to support my naming convention for test files?
Mind if I submit a pull request to support my naming convention for test files?
Please do!
I'm sure I could find it, but if it's quick for you, I'd appreciate a link to the relevant code :-)
I'm sure I could find it, but if it's quick for you, I'd appreciate a link to the relevant code :-)
https://github.com/bcoe/nyc/blob/69ed03b29c423c0fd7bd41f9dc8e7a3a68f7fe50/index.js#L45
I'll leave the test location for you ;-)
Looks like nyc cannot find the source map AVA generated for the test file. Unfortunately nyc thinks it instrumented the original test file but it didn't. Without the source map it can't generate a coverage report because the information generated by Istanbul does not line with the test file.
This might need some changes both to AVA and nyc. Good thing I have commit access to both ;-)
See https://github.com/sindresorhus/ava/pull/662 for an AVA fix that allows nyc to access the source maps.
Some output before these changes:
Some output after these changes:
As you can see, the tests work in both cases (yay), but coverage is busted after upgrading to AVA
0.13.0
and I have no idea why. Been working on this for a while now and I'm really stumped.Thoughts appreciated from my AVA friends :-)