我是茉莉花的新人。我打算用茉莉花创造一个记者。我在下面举例说明。
afterAll( function(){
writeStream.write( date + " execution done " );
writeStream.end();
});
describe("Sample test 1",function(){
it("after each function ", function(){
expect(1).toEqual(1);
});
it("Sample test 2 ", function(){
expect(1).toEqual(1);
});
});
一旦两个规格都被执行了。我想将结果记录在JSON文件中。在afterAll
。我正在努力通过互联网了解解决方案。有人可以知道如何做到这一点。
答案 0 :(得分:0)
我用过自定义记者。它做了我想做的事情
https://jasmine.github.io/2.3/custom_reporter.html
示例:
suiteDone : function(result) {
console.log('Suite: ' + result.description + ' was ' + result.testStatus);
for (var i = 0; i < result.failedExpectations.length; i++) {
console.log('AfterAll ' + result.failedExpectations[i].message);
console.log(result.failedExpectations[i].stack);
}
if(result.failedExpectations.length==0){
testStatus="pass";
}
suiteEndTime = currentDateTime();
var obj = {
"name" : suiteName,
"testStatus" : testStatus,
"tests" : [ testCaseName ],
"total" : totalTestCases,
"pass" : passedTestCaseCount,
"fail" : failedTestCaseCount,
"skip" : 0,
"startTime" : parseInt(suiteStartTime),
"endTime" : parseInt(suiteEndTime)
};
var fs = require('fs');
var json = JSON.stringify(obj, null, 4);
fs.writeFile(createJsonMetadataInJsonFolder(), json, 'utf8');
}