Closed wwwsevolod closed 9 years ago
Same issue here... I am trying to figure out how to generate code coverage reports on all the src files... No luck so far.
+1 Same here
+1
well, at least for now I have no idea how to do this too.
What I was guessing is that the isparta-loader loads a module only if somewhere in the test its imported.
For example lets say we have a componentA
if somewhere in the test there is import componentA from 'path/to/componentA'
or if there var componentA = require('path/to/componentA')
then that files is covered, otherwise there is no coverage at all and the file is not tracked.
One easy temporary solution might be writing a test for index.js
or any main file that basically has most of the imports which eventually include most of the components or modules.
isparta-loader just can't process files which were not required anywhere, this is the reason of our issue.
so, we can do something like karma-webpack "alternative usage" – read this first.
my working example:
// `test/components/all.es6`
// require all `test/components/**/index.es6`
const testsContext = require.context('./', true, /index\.es6$/);
testsContext.keys().forEach(testsContext);
// require all `src/components/**/index.es6`
const componentsContext = require.context('../src/components/', true, /index\.es6$/);
componentsContext.keys().forEach(componentsContext);
I'll update README with this info soon and close this issue. feel free to ask anything.
@deepsweet your suggestion works for me. Thx!
@deepsweet I've tried as you suggested to require the source code as well, but webpack tries to bundle everything in node_modules
as well (e.g.: babel, react, and so on).
Any idea how to prevent that?
PS: thanks for the work on isparta btw!
@emmenko I updated README with new setup instructions
@deepsweet cool, thanks! So that works now, if I run with Chrome as a browser the tests run and I can see the full coverage for all the source code, that's awesome.
If I run it with Phantomjs though, it fails with
20 08 2015 09:43:56.217:INFO [karma]: Karma v0.13.9 server started at http://localhost:9876/
20 08 2015 09:43:56.226:INFO [launcher]: Starting browser PhantomJS
20 08 2015 09:43:57.039:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket YPMFPkSoLquyrlKaAAAA with id 81286275
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
TypeError: Cannot call a class as a function
at /Users/emmenko/dev/src/my-project/test/index.js:5938 <- webpack:///~/babel-runtime/helpers/class-call-check.js:5:0
Finished in 0.443 secs / 0 secs
SUMMARY:
✔ 0 tests completed
I'm guessing something needs to be polyfilled for phantomjs (e.g.: had a problem before with Function.bind
) but I'm not sure and I don't understand what.
Maybe you have some ideas?
Many thanks!
Update: I tried that shim library but didn't help. I've tried now with phantomjs@2.0
and seems to work.
So with v2.0
I don't get that error anymore and tests run, only one test fails with
ERROR: 'Unhandled promise rejection', Error{framesToPop: 1, line: 7541, sourceURL: 'http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1', stack: ' at invariant (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:7541:17)
at _registerComponent (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:15600:56)
at _renderNewRootComponent (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:15640:53)
at ReactMount__renderNewRootComponent (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:10318:27)
at render (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:15738:56)
at React_render (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:10318:27)
at http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:62489:196
at run (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:987:42)
at http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:998:32
at flush (http://localhost:9876/base/test/index.js?3e8d98e74e86c9560b89d1910ba90473ace472c1:1330:18)'}
I just have to figure out how to debug that stack trace, as I don't see any source map (and yes, I'm using sourcemap
as a preprocessor).
FYI for those who might be interested: I've installed phantomjs with brew install phantomjs
(it installs v2.0
by default). The karma-phantomjs-launcher
still pulls the v1.9
version though, so you have to specify the env var path as:
PHANTOMJS_BIN=/usr/local/bin/phantomjs npm test
As far i understand, idea of code coverage is in show how much code you not covered in project, not only which files is imported explicitly. I understand that problem is here bcz it is just loader for webpack and cover only files that imported in tests, may be you can say how to setup isparta to use with webpack and babel, for that result that i'm expecting (show coverage of all files, not only imported) please? :(
or may be im doing something wrong?
Thank you.