I tried to get a coverage report for my test cases, and installed istanbul, My coverage report works fine for a single test file that is in root folder, else I get “No coverage information was collected, exit without writing coverage information”
My folder structure is
app/
— node_modules/
— coverage/
— server/
— — app.js
— test/
— — index.test.js
— test.js
When I run
istanbul cover _mocha test.js
I get a coverage report however If I try to tun
istanbul cover _mocha test/*.js
or
istanbul cover _mocha test/index.test.js
I don’t get any coverage report I tried all hit and trial its not working any work around for the same?
How can I run istanbul to cover report for all the test cases recursively ?
So Actually I misunderstood how Istanbul works,
I was running the server as separate instance to run the test case and then running the istanbul.
So I stopped the running instance of the server and then include config to run server for istanbul.
That helps irrespective of the folder structure you keep for your test cases.
Do global installation of mocha and istanbul
npm install -g mocha istanbulFOR LINUX/MAC
NODE_ENV=testing_coverage istanbul cover _mocha ./server/tests/*/.js --recursive ./bin/www ; open coverage/lcov-report/*.htmlWhere:
FOR Windows
SET NODE_ENV=testing_coverage&istanbul cover ./node_modules/mocha/bin/_mocha ./server/tests/*/.js --recursive ./bin/www&open coverage/lcov-report/*.htmlSET This is to be include in the windows to set the enviorment &this is to be included in windows to seperate the commands NODE_ENV=testing_coverage enviorment set for coverage and add this config in config.env file cover to cover istanbul code coverage, check istanbul help ---recursive for running recursive test case _mocha For mac: mocha file in node_modules/.bin/_mocha ./node_modules/mocha/bin/_mocha For windows set this path ./bin/www Main file to start the application ./server/tests/*/.js test cases folder path from root open coverage/lcov-report/*.html To open the coverage report in browser after all the test case gets completed