9

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'.

4

3 回答 3

7

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.

于 2014-08-27T09:04:55.347 回答
4

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) {
    /* ... */
}
于 2014-08-06T19:45:40.420 回答
1

Looks like jest-junit is also a option.

于 2017-11-09T12:23:23.420 回答