I have a sample project that I am using to write Unit Tests for Dojo modules before moving our to my main project. I have tests that are successfully running in node and chrome environments, but the coverage report is only reporting coverage for the tests executed in the node environment.
Below is a link to the sample project. Does anyone have any ideas why the code coverage report is not showing the metrics for TestModule_Dijit.js file specifically?
SampleProject.zip
Thanks in advance
I tried your sample project, and it appears to be working fine. At least, when running Intern I see coverage reports for both the browser and Node.
Note that coverage is only gathered for browser tests that are managed Intern running in Node. In other words, tests run when you call intern from the command line will collect coverage, whether they're run in Node or in a browser. Tests run using the browser client, where you manually browse to http://localhost:9000/__intern/, will not collect coverage.
Unrelated to the original question, I noticed that you're gathering coverage data for your tests rather than the source files. In general, coverage is most meaningful for the source since the point of test coverage data is to show how much of your application code is being exercised by the tests (not how much of the test code itself is running).
Related
I've publish a tool which based on jest to test my code and collect coverage.
I found the same file's coverage in entire coverage report can't match single one file coverage report since I use v8 coverage provider.
This is my coverage of entire project.
It can't match the result that I run jest in single one file.
I think it maybe v8 coverage problem and also try out babel coverage, It seems OK.
So, the problems is that I can't remember why I use v8 instead of babel becuase leave on a warnning in my tool.
Is there any problems if I switch v8 to babel?
I'm trying to get code coverage for unit tests in a Google Closure client-server project. We have code coverage for the server side, and need client side coverage.
JSCover runs its own server. Our cleint side unit tests require running under our server to access specific services. I don't see a way to make them work together, but a suggestion on how to do so would be ideal.
istanbul supports a number of underlying frameworks, but Google Closure does not appear to be one of them. Is there an easy way to use istanbul with a Google Closure unit test?
Blanket does not seem to be supported any longer. Does anyone have any recent experience that indicates it might still work with Google Closure?
Are there other coverage tools that would work well with Google Closure in a client-server configuration?
Istanbul works well with Google Closure and goog.testing.testSuite, although it is not obvious how to set it up. In general, follow the instructions for using Istanbul with IoT.js.
More specifically, here's an outline of how we instrumented our own Google Closure tests with Istanbul to generate code coverage information:
Install Node.js.
Using the Node.js package manager, install the Istanbul command line tool using the command npm install --save-dev nyc.
In our case, we use custom server code, so running our test suit under Node.js was not an option. I added a server-side call that accepted a file name and the contents of a file, and used this call to collect the code coverage statistics. If you don't need to use your own server code from your JavaScript tests, it is simpler to use Node.js as the server. See the link to using Istanbul with IoT.js (above) for some thoughts.
In each file for which code coverage is desired, run Istanbul's command line tool to instrument the file for coverage. The command will look something like nyc instrument myfile.js coverage_output_directory. This changes your .js files, so be sure to have a copy somewhere that you can use to restore the file. I used a Python script to find an instrument the various files.
In each Google Closure test file, add this to the end of the file:
window.onbeforeunload = function( event ) {
/** #const {!FileUploadService} */
var fileUploadService = new FileUploadService( "../.." );
fileUploadService.upload( "coverage_output_directory.myfile.data", JSON.stringify( __coverage__ ) );
};
Use a unique output file name for each test file. FileUploadService is the object we used to save result files on the server; you will need to replace this with your own service, or use the one in Node.js.
Run your tests.
Restore all changed files from your backups.
Use Istanbul and a report generator to create a code coverage report. For example, nyc report --reporter=lcov --temp-directory=coverage_output_directory. This uses the lcov report generator, which installs with Istanbul and creates a nice report.
Inspect the code coverage using a browser by loading coverage_output_directory/lcov-report/index.html.
JSCover runs its own server
It would be more accurate to say "JSCover can run its own server". You can also instrument your JavaScript files and deploy them to your server, run your tests and collect the coverage. There's a working example here.
I am trying to set up code coverage for my node.js unit tests.
What I am trying to do is this:
Use WebStorm for running tests
use Mocha (and co-mocha) as a testing framework
Use yield and generators for making my test code more readable
See the code coverage of my source code via the WebStorm UI (hoping to see my source code files color-coded according to code coverage)
The first two points are going fine, the third one is tripping me up.
Unfortunately WebStorm doesn't provide coverage support for Mocha:( Please follow WEB-10373 for updates
I just came into a Node.js project that has a ton of unit tests, most of which, unfortunately, are outdated and don't run. There's no test runner or any kind of code coverage tool implemented, and it is certainly not in my scope of work to refactor everything.
That being said, that doesn't stop me from wanting to check the code coverage of my work. I've looked at both Istanbul and Blanket and can't find a way to only have them run certain unit tests. Surely, there is a way so that I can get a report that, obviously, reports a very low percentage of coverage, but that I can dive into certain files and such (those that my tests hit) to ensure my code is throughly tested.
With istanbul.js, you can easily get the coverage information this by for example specifying the following command (Following example uses mocha but it will be similar for any test framework):
istanbul cover node_modules/.bin/_mocha -- -u exports -R spec test/test1.spec.js test/test2.spec.js
You can also specify all the tests in particular sub-directory eg: test/yourfeaturetest/*.spec.js. You also have something like test/myfeature/**/*.spec.js to cover all the tests in the test/myfeature directory including tests that could have been created recursively in sub-directories.
As for me, I use gulp and thus utilize plugins such as gulp-istanbul and run tests and coverage via gulp tasks.
I'm trying to get sonar to produce code coverage reports and unit test results. I'm running my unit tests with JS Test Driver and using maven to send the results to sonar which is installed on an internal server machine.
I've managed to get the unit test results to show up, but when I look at the source for the individual test files in sonar I get:
"Could not find source for unit test: Chrome_280150095_Windows.ButtonTest in any of test directories"
Additionally the code coverage results do not appear although they are being generated. I have a feeling it's because the jsTestDriver.conf-coverage.dat file contains paths to code from the machine I'm running jstestdriver from, not the machine I'm using to host sonar.
Can I only run mvn sonar:sonar on a machine with sonar installed locally or can I do it remotely like I'm trying? Where will sonar pick up the source classes from?
I'm very new to sonar so forgive me if I'm doing something totally wrong!
Here are the various files involed:
pom: http://pastebin.com/N21rbZZ3
maven settings profile for sonar: http://pastebin.com/HZfPMF0f
mvn sonar:sonar output: http://pastebin.com/WvPf1Axf
jsTestDriver.conf-coverage.dat: http://pastebin.com/pYYx20A9
TEST-Chrome_280150095_Windows.ButtonTest.xml: http://pastebin.com/f97EHtYE
Thanks!
Properties such as "sonar.sources" and "sonar.tests" are not taken into account while triggering the analysis with Maven. See http://docs.codehaus.org/display/SONAR/Analysis+Parameters. Hence your issue regarding source code of tests that is not found. This behavior will eventually changed when the following ticket is implemented: http://jira.codehaus.org/browse/SONAR-4536. Meanwhile, you should use the SonarQube Runner to trigger the analysis.