Jenkins integration with Jest

跟風遠走 提交于 2019-12-10 02:58:57

问题


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


回答1:


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.




回答2:


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) {
    /* ... */
}



回答3:


Looks like jest-junit is also a option.



来源:https://stackoverflow.com/questions/25155767/jenkins-integration-with-jest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!