有没有办法让Jenkins集成在基于Jasmine构建的Javascript Jest测试框架中?
我尝试将Jest与jasmine-reporters集成,但没有设法获得JUnit XML输出。我使用npm install jasmine-reporters@~1.0.0
安装了Jasmine 1.3的记者,然后安装在setupTestFrameworkScriptFile
:
require('jasmine-reporters');
jasmine.VERBOSE = true;
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
savePath: "output/"
}));
当我运行jest
时,我得到NodeJS attempt: Arguments to path.join must be strings
或NodeJS attempt: Object [object Object] has no method 'join'
。
答案 0 :(得分:7)
我已经设法在这个repo中获得了它的工作版本。问题是我没有在测试文件中嘲笑path
和fs
。
答案 1 :(得分:4)
您正在使用jasmine-reporter 2.x与1.x分支的语法。具体来说,您传递的是选项对象,但您需要发送位置参数。
不要这样做:
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter({
savePath: "output/"
}));
相反,你应该这样做:
jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter("output/"));
您可以查看the source以获取可用选项列表。以下是当前的选项:
/**
* 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) {
/* ... */
}
答案 2 :(得分:1)
看起来jest-junit也是一种选择。