UNPKG

@zebrunner/javascript-agent-mocha

Version:
94 lines (76 loc) 2.65 kB
const { IPC_EVENTS } = require('./events'); const { tcmTypes } = require('./constants'); const { connectIPCClient, publishIPCEvent } = require('./ipc-client'); const { parseTestInfo } = require('./object-transformer'); const { isCurrentTestPresent, isBlankString, isNotEmptyArray } = require('./utils'); const emitAddTestCaseEvent = (test, tcmType, testCaseKey, resultStatus) => { if (!isCurrentTestPresent(test)) { console.log('`test` object of the current test must be specified'); return; } if (isBlankString(testCaseKey)) { console.log(`Test Case key must be a not blank string. Provided value is '${testCaseKey}'`); return; } connectIPCClient(); const testInfo = parseTestInfo(test); const testCase = { tcmType, testCaseId: testCaseKey, resultStatus, }; publishIPCEvent(IPC_EVENTS.ADD_TEST_CASES, { testInfo, testCase }); }; const Zebrunner = { testCaseKey: (test, ...testCaseKeys) => { if (isNotEmptyArray(testCaseKeys)) { testCaseKeys.forEach((testCaseKey) => emitAddTestCaseEvent(test, tcmTypes.ZEBRUNNER, testCaseKey)); } }, testCaseStatus: (test, testCaseKey, resultStatus) => { emitAddTestCaseEvent(test, tcmTypes.ZEBRUNNER, testCaseKey, resultStatus); }, }; const emitTestRailAddTestCaseEvent = (test, testCaseId, resultStatus) => { let caseId = testCaseId; if (!isBlankString(testCaseId) && testCaseId.startsWith('C')) { caseId = testCaseId.substring(1); } emitAddTestCaseEvent(test, tcmTypes.TEST_RAIL, caseId, resultStatus); }; const TestRail = { testCaseId: (test, ...testCaseIds) => { if (isNotEmptyArray(testCaseIds)) { testCaseIds.forEach((testCaseId) => emitTestRailAddTestCaseEvent(test, testCaseId)); } }, testCaseStatus: (test, testCaseId, resultStatus) => { emitTestRailAddTestCaseEvent(test, testCaseId, resultStatus); }, }; const Xray = { testCaseKey: (test, ...testCaseKeys) => { if (isNotEmptyArray(testCaseKeys)) { testCaseKeys.forEach((testCaseKey) => emitAddTestCaseEvent(test, tcmTypes.XRAY, testCaseKey)); } }, testCaseStatus: (test, testCaseKey, resultStatus) => { emitAddTestCaseEvent(test, tcmTypes.XRAY, testCaseKey, resultStatus); }, }; const Zephyr = { testCaseKey: (test, ...testCaseKeys) => { if (isNotEmptyArray(testCaseKeys)) { testCaseKeys.forEach((testCaseKey) => emitAddTestCaseEvent(test, tcmTypes.ZEPHYR, testCaseKey)); } }, testCaseStatus: (test, testCaseKey, resultStatus) => { emitAddTestCaseEvent(test, tcmTypes.ZEPHYR, testCaseKey, resultStatus); }, }; module.exports = { Zebrunner, TestRail, Xray, Zephyr, };