Reputation: 4974
Is there a way to have Jenkins integration in the Javascript Jest testing framework that is built on top of Jasmine?
I've tried to integrate Jest with jasmine-reporters, but didn't manage to get a JUnit XML output. I installed the reporters for Jasmine 1.3 with npm install jasmine-reporters@~1.0.0
and then in my setupTestFrameworkScriptFile
:
require('jasmine-reporters');
jasmine.VERBOSE = true;
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
savePath: "output/"
}));
When I run jest
I get NodeJS attempt: Arguments to path.join must be strings
or NodeJS attempt: Object [object Object] has no method 'join'
.
Upvotes: 9
Views: 10401
Reputation: 4974
I've managed to get a working version of it in this repo. The problem was I was not mocking path
and fs
in the test file.
Upvotes: 7
Reputation: 271
You're using the syntax of jasmine-reporters 2.x with the 1.x branch. Specifically, you are passing an object of options but you need to send positional arguments.
Don't do this:
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
savePath: "output/"
}));
Instead, you should do this:
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter("output/"));
You can check out the source for the list of available options. Here are the current options:
/**
* Generates JUnit XML for the given spec run.
* Allows the test results to be used in java based CI
* systems like CruiseControl and Hudson.
*
* @param {string} [savePath] where to save the files
* @param {boolean} [consolidate] whether to save nested describes within the
* same file as their parent; default: true
* @param {boolean} [useDotNotation] whether to separate suite names with
* dots rather than spaces (ie "Class.init" not
* "Class init"); default: true
* @param {string} [filePrefix] is the string value that is prepended to the
* xml output file; default: 'TEST-'
* @param {boolean} [consolidateAll] whether to save test results from different
* specs all in a single file; filePrefix is then the whole file
* name without extension; default: false
*/
var JUnitXmlReporter = function(savePath, consolidate, useDotNotation, filePrefix, consolidateAll) {
/* ... */
}
Upvotes: 4