jasmine-atm-reporter
Version:
npm module for jest-puppeteer to upload result in atm
75 lines (68 loc) • 3.55 kB
JavaScript
require('dotenv').config();
var env = require('./createEnvironment')
var atm = require('./resultUpload');
var rep = require("./reporter");
var fs = require('fs');
var arrStepStatus = [];
arrStepComment = [];
testCaseStatus = "Pass";
testCaseComment = null;
class JasmineATMReporter {
constructor() {
}
specDone(specResult){
if(process.env.TEST_CYCLE_ID === undefined){
fs.readFile('./cycleID.txt', 'utf8', function(err, cycleID) {
if (err) throw err;
else process.env.TEST_CYCLE_ID = cycleID;
});
}
arrStepStatus.push(specResult.status);
if(specResult.failedExpectations.length > 0)arrStepComment.push('MESSAGE ::==> ' + specResult.failedExpectations[0].message);
else arrStepComment.push(null);
};
suiteDone(suiteResult){
env.createEnvironment(process.argv.ENVIRONMENT);
var TestStepdata;
var testStepStatus
for(var iLoop=0; iLoop < arrStepStatus.length; iLoop++) {
if(arrStepStatus[iLoop] === "failed") testCaseStatus = "Fail";
if(arrStepStatus[iLoop] === "failed") testStepStatus = "Fail";
else testStepStatus = "Pass";
if(iLoop === 0){
if((iLoop === 0) && (arrStepStatus.length === 1)){
var data = "[{\"index\":" + iLoop + ", \"status\":\"" + testStepStatus + "\", \"comment\":" + JSON.stringify(arrStepComment[iLoop]) + "}]";
TestStepdata = data;
}
else {
var data = "[{\"index\":" + iLoop + ", \"status\":\"" + testStepStatus + "\", \"comment\":" + JSON.stringify(arrStepComment[iLoop]) + "}, ";
TestStepdata = data;
}
}
else {
if(iLoop === arrStepStatus.length -1){
var data = "{\"index\":" + iLoop + ", \"status\":\"" + testStepStatus + "\", \"comment\":" + JSON.stringify(arrStepComment[iLoop]) + "}]";
TestStepdata = TestStepdata + data;
}
else {
var data = "{\"index\":" + iLoop + ", \"status\":\"" + testStepStatus + "\", \"comment\":" + JSON.stringify(arrStepComment[iLoop]) + "}, ";
TestStepdata = TestStepdata + data;
}
}
}
atm.testResultUpload(process.env.TEST_CYCLE_ID, process.argv.TEST_CASE_ID, testCaseStatus, process.argv.ENVIRONMENT, TestStepdata);
arrStepStatus = [];
arrStepComment = [];
fs.createWriteStream('.test-env').write('TEST_CYCLE_ID=' + process.env.TEST_CYCLE_ID);
fs.appendFile('.test-env', "\n" + 'TEST_CASE_ID=' + process.argv.TEST_CASE_ID, function (err) {if (err) throw err;});
fs.appendFile('.test-env', "\n" + 'TEST_CASE_STATUS=' + testCaseStatus, function (err) {if (err) throw err;});
fs.appendFile('.test-env', "\n" + 'TEST_CASE_ENVIRONMENT=' + process.argv.ENVIRONMENT, function (err) {if (err) throw err;});
fs.appendFile('.test-env', "\n" + 'TEST_STEP_RESULT=' + TestStepdata, function (err) {if (err) throw err;});
};
}
function registerAtmReporter() {
const reporter = global.reporter = new rep();
jasmine.getEnv().addReporter(new JasmineATMReporter());
}
exports.registerAtmReporter = registerAtmReporter;
registerAtmReporter();