Jenkins integration with Jest

2019-04-24 07:29发布

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

3条回答
劳资没心,怎么记你
2楼-- · 2019-04-24 07:49

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) {
    /* ... */
}
查看更多
smile是对你的礼貌
3楼-- · 2019-04-24 07:58

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.

查看更多
欢心
4楼-- · 2019-04-24 07:59

Looks like jest-junit is also a option.

查看更多
登录 后发表回答