Skip to content

Commit 3322cec

Browse files
committed
adding qase.ts file
1 parent 6ba6d88 commit 3322cec

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

cypress/support/qase.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* global Mocha */
2+
/* eslint-disable no-console */
3+
let qaseImport: any;
4+
5+
try {
6+
// Try to use the qase function from the reporter if available
7+
// This is the recommended way for cypress-qase-reporter 3.0.0+
8+
qaseImport = require('cypress-qase-reporter/mocha').qase;
9+
} catch (e) {
10+
// Fallback to custom implementation if the import fails
11+
}
12+
13+
/**
14+
* Custom wrapper for Qase ID integration.
15+
* If the official reporter is available, it delegates to it.
16+
* Otherwise, it appends the Qase ID to the test title manually.
17+
*/
18+
export const qase = (caseId: number | number[], test: Mocha.Test): Mocha.Test => {
19+
if (qaseImport) {
20+
try {
21+
return qaseImport(caseId, test);
22+
} catch (e) {
23+
console.warn('Qase reporter import failed at runtime, falling back to manual title update.');
24+
}
25+
}
26+
27+
// Custom fallback implementation
28+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
29+
if (!test || !test.title) {
30+
return test;
31+
}
32+
const caseIds = Array.isArray(caseId) ? caseId : [caseId];
33+
34+
test.title = `${ test.title } (Qase ID: ${ caseIds.join(',') })`;
35+
36+
return test;
37+
};

0 commit comments

Comments
 (0)