Skip to content

Commit 975fd4f

Browse files
authored
chore: qase integration (#37538)
1 parent 109705a commit 975fd4f

File tree

7 files changed

+152
-4
lines changed

7 files changed

+152
-4
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ jobs:
654654
env:
655655
ROCKETCHAT_IMAGE: ghcr.io/${{ needs.release-versions.outputs.lowercase-repo }}/rocket.chat:${{ needs.release-versions.outputs.gh-docker-tag }}
656656
ENTERPRISE_LICENSE_RC1: ${{ secrets.ENTERPRISE_LICENSE_RC1 }}
657+
QASE_TESTOPS_JEST_API_TOKEN: ${{ secrets.QASE_TESTOPS_JEST_API_TOKEN }}
657658
run: yarn test:integration --image "${ROCKETCHAT_IMAGE}"
658659

659660
report-coverage:

ee/packages/federation-matrix/jest.config.federation.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ export default {
2121
forceExit: true, // Force Jest to exit after tests complete
2222
detectOpenHandles: true, // Detect open handles that prevent Jest from exiting
2323
globalTeardown: '<rootDir>/tests/teardown.ts',
24+
// To disable Qase integration, remove this line or comment it out
25+
setupFilesAfterEnv: ['<rootDir>/tests/setup-qase.ts'],
2426
verbose: false,
2527
silent: false,
28+
reporters: [
29+
'default',
30+
...(process.env.QASE_TESTOPS_JEST_API_TOKEN
31+
? [
32+
[
33+
'jest-qase-reporter',
34+
{
35+
mode: 'testops',
36+
testops: {
37+
api: { token: process.env.QASE_TESTOPS_JEST_API_TOKEN },
38+
project: 'RC',
39+
run: { complete: true },
40+
},
41+
debug: true,
42+
},
43+
] as [string, { [x: string]: unknown }],
44+
]
45+
: []),
46+
] as Config['reporters'],
2647
} satisfies Config;

ee/packages/federation-matrix/tests/end-to-end/room.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ import { SynapseClient } from '../helper/synapse-client';
176176
config: rc1AdminRequestConfig,
177177
});
178178

179-
console.log('response', response.body);
180-
181179
expect(response.body).toHaveProperty('success', true);
182180
expect(response.body).toHaveProperty('message');
183181

ee/packages/federation-matrix/tests/helper/ddp-listener.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export class DDPListener {
8484
return new Promise((resolve, reject) => {
8585
// Check if message already exists
8686
const existingMessage = this.ephemeralMessages.find((msg) => {
87-
console.log('msg', msg);
8887
const contentMatches = msg.msg?.includes(expectedContent);
8988
const roomMatches = !roomId || msg.rid === roomId;
9089
return contentMatches && roomMatches;
@@ -107,7 +106,6 @@ export class DDPListener {
107106

108107
const checkMessages = () => {
109108
const message = this.ephemeralMessages.find((msg) => {
110-
console.log('msg', msg);
111109
const contentMatches = msg.msg?.includes(expectedContent);
112110
const roomMatches = !roomId || msg.rid === roomId;
113111
return contentMatches && roomMatches;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* Jest setup file that automatically wraps describe and it/test functions
3+
* to register suites and tests with Qase.
4+
*
5+
* The Qase Jest reporter reports the directory structure up from the tests directory,
6+
* making it not consistent with the test suite structure we currently follow in Qase.
7+
* The solution is to wrap describe and it/test functions to automatically set the suite
8+
* at the very start of the test to what we really want the reporting structure to be.
9+
*
10+
* This file is loaded via setupFilesAfterEnv in jest.config.federation.ts.
11+
* Qase integration is only enabled when QASE_TESTOPS_JEST_API_TOKEN is set.
12+
*/
13+
14+
import { qase } from 'jest-qase-reporter/jest';
15+
16+
const ROOT_SUITE = 'Rocket.Chat Federation Automation';
17+
18+
/**
19+
* Stack to track the current suite path hierarchy
20+
*/
21+
const suitePathStack: string[] = [];
22+
23+
/**
24+
* Store the original Jest describe function before we replace it
25+
*/
26+
const originalDescribe = global.describe;
27+
28+
/**
29+
* Gets the full suite path including root
30+
*/
31+
function getFullSuitePath(): string {
32+
return [ROOT_SUITE, ...suitePathStack].join('\t');
33+
}
34+
35+
/**
36+
* Wraps describe to automatically track suite hierarchy and set suite for tests
37+
*/
38+
function describeImpl(name: string, fn: () => void): void {
39+
suitePathStack.push(name);
40+
const currentPath = getFullSuitePath();
41+
42+
originalDescribe(name, () => {
43+
// Add beforeEach to set suite for all tests in this describe block
44+
// This must be called before the test runs so the reporter picks it up
45+
global.beforeEach(() => {
46+
qase.suite(currentPath);
47+
});
48+
49+
// Store current it and test wrappers (they might be wrapped by parent describe)
50+
const currentIt = global.it;
51+
const currentTest = global.test;
52+
53+
// Wrap it() to automatically set suite at the very start
54+
global.it = ((testName: any, fn?: any, timeout?: number) => {
55+
// Handle qase-wrapped test names (qase returns a string)
56+
if (typeof testName === 'string' && fn) {
57+
return currentIt(
58+
testName,
59+
async () => {
60+
// Set suite immediately at the start of the test
61+
qase.suite(currentPath);
62+
// Call the original test function and return the result
63+
return fn();
64+
},
65+
timeout,
66+
);
67+
}
68+
// Handle cases where testName might be a number or other type
69+
return currentIt(testName, fn, timeout);
70+
}) as typeof global.it;
71+
72+
// Wrap test() to automatically set suite at the very start
73+
global.test = ((testName: any, fn?: any, timeout?: number) => {
74+
if (typeof testName === 'string' && fn) {
75+
return currentTest(
76+
testName,
77+
async () => {
78+
// Set suite immediately at the start of the test
79+
qase.suite(currentPath);
80+
// Call the original test function and return the result
81+
return fn();
82+
},
83+
timeout,
84+
);
85+
}
86+
return currentTest(testName, fn, timeout);
87+
}) as typeof global.test;
88+
89+
// Execute the describe block
90+
fn();
91+
92+
// Restore previous wrappers
93+
global.it = currentIt;
94+
global.test = currentTest;
95+
});
96+
97+
suitePathStack.pop();
98+
}
99+
100+
// Only apply qase wrapping if the environment variable is set
101+
if (process.env.QASE_TESTOPS_JEST_API_TOKEN) {
102+
// Replace global describe with our wrapper
103+
(global as any).describe = Object.assign(describeImpl, {
104+
skip: (name: string, fn: () => void) => originalDescribe.skip(name, fn),
105+
only: (name: string, fn: () => void) => originalDescribe.only(name, fn),
106+
}) as typeof global.describe;
107+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@types/chart.js": "^2.9.41",
2222
"@types/js-yaml": "^4.0.9",
2323
"@types/node": "~22.16.5",
24+
"jest-qase-reporter": "^2.1.3",
2425
"ts-node": "^10.9.2",
2526
"turbo": "~2.6.1",
2627
"typescript": "~5.9.3"

yarn.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25723,6 +25723,20 @@ __metadata:
2572325723
languageName: node
2572425724
linkType: hard
2572525725

25726+
"jest-qase-reporter@npm:^2.1.3":
25727+
version: 2.1.3
25728+
resolution: "jest-qase-reporter@npm:2.1.3"
25729+
dependencies:
25730+
lodash.get: "npm:^4.4.2"
25731+
lodash.has: "npm:^4.5.2"
25732+
qase-javascript-commons: "npm:~2.4.2"
25733+
uuid: "npm:^9.0.0"
25734+
peerDependencies:
25735+
jest: ">=28.0.0"
25736+
checksum: 10/1c19643adaffd514674d1dbdc92d6377beb859d4036228133a8ad2dadadbc879bc65b74df5f14ad371b5e269976720da3b787afbfba034ff8be0f1a1792324c7
25737+
languageName: node
25738+
linkType: hard
25739+
2572625740
"jest-regex-util@npm:30.0.1":
2572725741
version: 30.0.1
2572825742
resolution: "jest-regex-util@npm:30.0.1"
@@ -26998,6 +27012,13 @@ __metadata:
2699827012
languageName: node
2699927013
linkType: hard
2700027014

27015+
"lodash.has@npm:^4.5.2":
27016+
version: 4.5.2
27017+
resolution: "lodash.has@npm:4.5.2"
27018+
checksum: 10/35c0862e715bc22528dd3cd34f1e66d25d58f0ecef9a43aa409fb7ddebaf6495cb357ae242f141e4b2325258f4a6bafdd8928255d51f1c0a741ae9b93951c743
27019+
languageName: node
27020+
linkType: hard
27021+
2700127022
"lodash.includes@npm:^4.3.0":
2700227023
version: 4.3.0
2700327024
resolution: "lodash.includes@npm:4.3.0"
@@ -32912,6 +32933,7 @@ __metadata:
3291232933
"@types/js-yaml": "npm:^4.0.9"
3291332934
"@types/node": "npm:~22.16.5"
3291432935
"@types/stream-buffers": "npm:^3.0.8"
32936+
jest-qase-reporter: "npm:^2.1.3"
3291532937
node-gyp: "npm:^10.2.0"
3291632938
ts-node: "npm:^10.9.2"
3291732939
turbo: "npm:~2.6.1"

0 commit comments

Comments
 (0)