I have a couple of projects that use Karma to run Jasmine unit tests. We're using npm for package management and Grunt for building our JavaScript projects and executing their unit test tasks. After committing, these projects are built automatically via Jenkins jobs.
On Windows, my projects build successfully. When Jenkins runs the builds on Linux, however, I randomly will see unit test failures that seem to be caused by a previous version of my file being referenced.
For example, I have a class that previously called:
alert('Cannot retrieve report with the following url: report');
It was recently changed to call:
alert('There was an error trying to retrieve report with ID: 123');
When I run my unit tests locally on Windows, every test runs successfully. When Jenkins runs them on Linux, the tests fail with this output:
Expected spy alert to have been called with [ 'There was an error
trying to retrieve report with ID: 123' ] but actual calls were [
'Cannot retrieve report with the following url: report' ]
It seems that somewhere the old version of my file is being referenced. Is it possible that somewhere something (Jenkins, a Node module, etc.) is caching my files?
I've verified that my Jenkins workspace contains the correct versions of the files for which the unit tests are failing. I've also removed any tildes from my package.json and used npm shrinkwrap to ensure that I have full control of my dependencies. I've wiped my workspace several times and created multiple jobs, but I can't seem to rid myself of this problem.
Related
I'm starting to learn React Native. I tried to install it from what I read from the documentation. It works flawlessly on Android. After installing the project, I run the 'xcworkspace' file in the ios folder, but I get an error.
This is the error I got => Command PhaseScriptExecution failed with a nonzero exit code
When I run the project from the console with the following code "npx react-native run-ios" I get the following error.
warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/omerulusoy/Library/Developer/Xcode/DerivedData/AwesomeProject-bzsmyrhehnlgrpbitthszribdkvm/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00018F30.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)
I entered the ios folder and ran the following code 'pod deintegrate' and then this code 'pod install' but I still get the error.
I tried installing older versions of React, but this time I got different errors.
One of the errors I got => 'Typedef redefinition with different types ('uint8_t' (aka 'unsigned char') vs 'enum clockid_t')'
Meteor application has built with 'meteor build' command and then deployed. After deployment application runs using plain node command 'node bundle/main.js'.
Running nyc using command 'nyc node main.js' only give the partial results from the meteor generate files.
Code coverage result
Is there anyway to get the full code coverage results? I am only interested to get result about javascript files.
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'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.
I have a project that I am setting up through teamcity for CI.
The project itself is a nodejs application and it includes test written in mocha, which we cover through jscoverage. In the build configuration I'm setting up I have 3 build steps
which occur on checkin.
call jscoverage.exe against the folders in my project that I'm
covering.
call mocha to run the test against the jscovered files from step 1
and output to the html-cov reporter
move the generated coverage.html report into a public web directory
to browse later.
The build currently fails on step 2:
mocha" is not present in directory C:\NodeJS\MeasuresAPI
I've made sure to include mocha and all my node packages in the system environment paths and I am able to access them in the command prompt, but TeamCity doesnt appear to see them.
for the jscoverage.exe, I had to include the full path. With mocha, I tried including the path to my node global installation where mocha installed to but it gives me an error:
"..\node_modules\mocha\bin\mocha" (in directory "C:\NodeJS\MeasuresAPI"): CreateProcess error=193, %1 is not a valid Win32 application
Anyone had any experience with Teamcity and Mocha and how to get them to play nice?
or any ideas for continuous integration with a nodejs, mocha stack?
Yes , this happened to me too, when I was setting up TeamCity to run mocha on Windows Server. The solution was to call mocha by specifying path to the mocha.cmd bat file. For example , if you have folder C:\mocha and you have executed
npm install mocha
in that directory , than path to the bat file will be
C:\mocha\node_modules.bin\mocha.cmd
And you can tell Teamcity to execute mocha command by giving it next instruction :
C:\mocha\node_modules.bin\mocha --ui tdd --reporter html-cov test\measureDBTests.js > coverage.html