@testomatio/reporter
Version:
Testomatio Reporter Client
81 lines (80 loc) • 3.74 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_js_1 = __importDefault(require("../client.js"));
const config_js_1 = require("../config.js");
const constants_js_1 = require("../constants.js");
const utils_js_1 = require("../utils/utils.js");
const apiKey = config_js_1.config.TESTOMATIO;
const client = new client_js_1.default({ apiKey });
module.exports = {
write: async (results, options, done) => {
await client.createRun();
const testFiles = results.modules;
for (const fileName in testFiles) {
// in nightwatch: object containing tests from a single file
const testModule = testFiles[fileName];
// passed and failed tests (tests with assertions)
const completedTests = testModule.completed;
// skipped tests (skipped by user or tests without assertions)
const skippedTests = testModule.skipped;
const tags = testModule.tags || [];
// if test file contains multiple suites, the last suite name is used as a name 🤷♂️
// no other places which contain suite name (even inside test object)
const suiteTitle = testModule.name;
for (const testTitle in completedTests) {
const test = completedTests[testTitle];
let status;
switch (test.status) {
case 'pass':
status = constants_js_1.STATUS.PASSED;
break;
case 'fail':
status = constants_js_1.STATUS.FAILED;
break;
// probably not required (because skipped tests are in separate array), but just in case
case 'skip':
status = constants_js_1.STATUS.SKIPPED;
console.info('Skipped test is in completed tests array:', test, 'Not expected behavior.');
break;
default:
console.error('Test status processing error:', test.status);
}
const testId = (0, utils_js_1.getTestomatIdFromTestTitle)(testTitle);
client.addTestRun(status, {
error: { name: test.assertions?.[0]?.name, message: test.assertions?.[0]?.message, stack: test.stackTrace },
file: testModule.modulePath?.replace(process.cwd(), ''),
message: test.assertions?.[0]?.message,
rid: `${testModule.uuid || ''}_${testTitle || ''}`,
stack: test.stackTrace,
suite_title: suiteTitle,
tags,
test_id: testId,
time: test.timeMs,
title: testTitle,
});
}
// just array with skipped tests titles, no any other info
for (const testTitle of skippedTests) {
client.addTestRun(constants_js_1.STATUS.SKIPPED, {
suite_title: suiteTitle,
tags,
rid: `${testModule.uuid || ''}_${testTitle || ''}`,
title: testTitle,
});
}
}
/**
* @type {'passed' | 'failed' | 'finished'}
*/
let runStatus = 'finished';
if (results.failed)
runStatus = 'failed';
else if (results.passed)
runStatus = 'passed';
await client.updateRunStatus(runStatus);
done();
},
};