@gurglosa/playwright-zephyr-jira-reporter
Version:
A custom Playwright reporter that syncs test results to Zephyr Scale and creates Jira bugs on failures.
84 lines (83 loc) • 3.64 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZephyrServices = exports.TestExecutionStatus = void 0;
const axios_1 = __importDefault(require("axios"));
var TestExecutionStatus;
(function (TestExecutionStatus) {
TestExecutionStatus["passed"] = "Pass";
TestExecutionStatus["failed"] = "Fail";
TestExecutionStatus["skipped"] = "Blocked";
TestExecutionStatus["timedOut"] = "Fail";
TestExecutionStatus["interrupted"] = "Fail";
TestExecutionStatus["in_progress"] = "In Progress";
TestExecutionStatus["UNKNOWN"] = "Blocked";
// BLOCKED = 'Blocked',
// UNEXECUTED = 'Unexecuted',
// NOT_APPLICABLE = 'Not Applicable',
})(TestExecutionStatus || (exports.TestExecutionStatus = TestExecutionStatus = {}));
class ZephyrServices {
constructor(config) {
const requiredFields = [
{ key: 'Zephyr_Base_URL', message: 'Zephyr Base URL is required' },
{ key: 'Zephyr_Access_Token', message: 'Zephyr Access Token is required' },
{ key: 'Zephyr_Test_Cycle_ID', message: 'Zephyr Test Cycle ID is required' },
{ key: 'Zephyr_Test_Project_Key', message: 'Zephyr Test Project Key is required' }
];
for (const field of requiredFields) {
if (!config[field.key]) {
throw new Error(field.message);
}
}
this.client = axios_1.default.create({
baseURL: config.Zephyr_Base_URL,
headers: {
Authorization: `Bearer ${config.Zephyr_Access_Token}`,
'Content-Type': 'application/json'
}
});
}
async updateTestExecutionStatus(params) {
try {
const { projectKey, testCaseKey, testCycleKey, statusName, testScriptResults, environmentName, actualEndDate, executedBy, assignedToId, comment, customFields } = params;
const payload = {
projectKey,
testCaseKey,
testCycleKey,
statusName,
environmentName,
comment: comment || `Test execution ${testCaseKey} updated to status: ${statusName}`,
executedBy,
assignedToId,
executionDate: actualEndDate || new Date().toISOString(),
customFields,
};
// Add test script to payload if provided (passing object directly)
if (testScriptResults) {
payload.testScriptResults = testScriptResults;
}
const response = await this.client.post('/testexecutions', payload);
console.log(`✅ Test execution ${testCaseKey} updated to status: ${statusName}`);
return response.data;
}
catch (error) {
const axiosError = error;
console.error(`❌ Failed to update test execution ${params.testCaseKey}:`, axiosError.message, axiosError.response?.data);
throw error;
}
}
async linkIssueToTestCase(testCaseKey, link) {
try {
const response = await this.client.post(`/testcases/${testCaseKey}/links/issues`, link);
}
catch (error) {
const axiosError = error;
console.error(`❌ Failed to link issue ${link.issueId} to test case ${testCaseKey}:`, axiosError.message, axiosError.response?.data);
throw error;
}
}
}
exports.ZephyrServices = ZephyrServices;
exports.default = ZephyrServices;