Skip to content

Commit

Permalink
chore(tests): report tests with xunit (#5318)
Browse files Browse the repository at this point in the history
* chore: xunit

* prepend package in xunit

* delimiter

* use the reported for e2e

* remove attach.results
  • Loading branch information
mcasimir authored Jan 12, 2024
1 parent 8c64dee commit 1c44cea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
5 changes: 2 additions & 3 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ post:
remote_file: ${project}/${revision}_${revision_order_id}/vulnerability-report.md
content_type: text/markdown
optional: true
- command: attach.results
- command: attach.xunit_results
params:
file_location: src/packages/compass-e2e-tests/.log/report.json

file: src/.logs/*.xml
functions:
clone:
- command: git.get_project
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ mongodb-crypt
packages/*/.npmrc
config/*/.npmrc
.sbom
.logs
.evergreen/logs
3 changes: 3 additions & 0 deletions configs/mocha-config-compass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
const path = require('path');
const base = require('@mongodb-js/mocha-config-devtools');

const fs = require('fs');

module.exports = {
...base,
reporter: path.resolve(__dirname, 'reporter.js'),
require: [
...base.require,
path.resolve(__dirname, 'register', 'resolve-from-source-register.js'),
Expand Down
30 changes: 30 additions & 0 deletions configs/mocha-config-compass/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Mocha = require('mocha');
const fs = require('fs');
const path = require('path');

// Import the built-in reporters
const Spec = Mocha.reporters.Spec;
const XUnit = Mocha.reporters.XUnit;

class Reporter {
constructor(runner) {
const suiteName = path.basename(process.cwd());

new Spec(runner);

runner.on('suite', (suite) => {
if (suite.parent?.root) {
suite.title = `${suiteName}__${suite.title}`;
}
});

new XUnit(runner, {
reporterOptions: {
suiteName,
output: path.join(__dirname, '..', '..', '.logs', `${suiteName}.xml`),
},
});
}
}

module.exports = Reporter;
15 changes: 7 additions & 8 deletions packages/compass-e2e-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ async function main() {
const mocha = new Mocha({
timeout: 240_000, // kinda arbitrary, but longer than waitforTimeout set in helpers/compass.ts so the test can fail before it times out
bail,
reporter: path.resolve(
__dirname,
'..',
'..',
'configs/mocha-config-compass/reporter.js'
),
});

tests.forEach((testPath: string) => {
Expand Down Expand Up @@ -196,14 +202,7 @@ async function main() {
});
});

// write a report.json to be uploaded to evergreen
debug('Writing report.json');
const result = await resultLogger.done(failures);
const reportPath = path.join(LOG_PATH, 'report.json');
const jsonReport = JSON.stringify(result, null, 2);
await fs.promises.writeFile(reportPath, jsonReport);

debug('done');
await resultLogger.done(failures);
}

process.once('SIGINT', () => {
Expand Down

0 comments on commit 1c44cea

Please sign in to comment.