Skip to content

Commit 1c44cea

Browse files
authored
chore(tests): report tests with xunit (#5318)
* chore: xunit * prepend package in xunit * delimiter * use the reported for e2e * remove attach.results
1 parent 8c64dee commit 1c44cea

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

.evergreen/functions.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ post:
122122
remote_file: ${project}/${revision}_${revision_order_id}/vulnerability-report.md
123123
content_type: text/markdown
124124
optional: true
125-
- command: attach.results
125+
- command: attach.xunit_results
126126
params:
127-
file_location: src/packages/compass-e2e-tests/.log/report.json
128-
127+
file: src/.logs/*.xml
129128
functions:
130129
clone:
131130
- command: git.get_project

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ mongodb-crypt
3333
packages/*/.npmrc
3434
config/*/.npmrc
3535
.sbom
36+
.logs
3637
.evergreen/logs

configs/mocha-config-compass/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
const path = require('path');
44
const base = require('@mongodb-js/mocha-config-devtools');
55

6+
const fs = require('fs');
7+
68
module.exports = {
79
...base,
10+
reporter: path.resolve(__dirname, 'reporter.js'),
811
require: [
912
...base.require,
1013
path.resolve(__dirname, 'register', 'resolve-from-source-register.js'),
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const Mocha = require('mocha');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
// Import the built-in reporters
6+
const Spec = Mocha.reporters.Spec;
7+
const XUnit = Mocha.reporters.XUnit;
8+
9+
class Reporter {
10+
constructor(runner) {
11+
const suiteName = path.basename(process.cwd());
12+
13+
new Spec(runner);
14+
15+
runner.on('suite', (suite) => {
16+
if (suite.parent?.root) {
17+
suite.title = `${suiteName}__${suite.title}`;
18+
}
19+
});
20+
21+
new XUnit(runner, {
22+
reporterOptions: {
23+
suiteName,
24+
output: path.join(__dirname, '..', '..', '.logs', `${suiteName}.xml`),
25+
},
26+
});
27+
}
28+
}
29+
30+
module.exports = Reporter;

packages/compass-e2e-tests/index.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ async function main() {
153153
const mocha = new Mocha({
154154
timeout: 240_000, // kinda arbitrary, but longer than waitforTimeout set in helpers/compass.ts so the test can fail before it times out
155155
bail,
156+
reporter: path.resolve(
157+
__dirname,
158+
'..',
159+
'..',
160+
'configs/mocha-config-compass/reporter.js'
161+
),
156162
});
157163

158164
tests.forEach((testPath: string) => {
@@ -196,14 +202,7 @@ async function main() {
196202
});
197203
});
198204

199-
// write a report.json to be uploaded to evergreen
200-
debug('Writing report.json');
201-
const result = await resultLogger.done(failures);
202-
const reportPath = path.join(LOG_PATH, 'report.json');
203-
const jsonReport = JSON.stringify(result, null, 2);
204-
await fs.promises.writeFile(reportPath, jsonReport);
205-
206-
debug('done');
205+
await resultLogger.done(failures);
207206
}
208207

209208
process.once('SIGINT', () => {

0 commit comments

Comments
 (0)