diff --git a/.evergreen/functions.yml b/.evergreen/functions.yml index 02d12140b70..ca1e602d2c1 100644 --- a/.evergreen/functions.yml +++ b/.evergreen/functions.yml @@ -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 diff --git a/.gitignore b/.gitignore index 0930b41847e..8ec88947dcc 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,5 @@ mongodb-crypt packages/*/.npmrc config/*/.npmrc .sbom +.logs .evergreen/logs diff --git a/configs/mocha-config-compass/index.js b/configs/mocha-config-compass/index.js index 834549fe272..8df2bb2e664 100644 --- a/configs/mocha-config-compass/index.js +++ b/configs/mocha-config-compass/index.js @@ -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'), diff --git a/configs/mocha-config-compass/reporter.js b/configs/mocha-config-compass/reporter.js new file mode 100644 index 00000000000..7f999d81581 --- /dev/null +++ b/configs/mocha-config-compass/reporter.js @@ -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; diff --git a/packages/compass-e2e-tests/index.ts b/packages/compass-e2e-tests/index.ts index f2e6d6e2245..44ef3a072b3 100644 --- a/packages/compass-e2e-tests/index.ts +++ b/packages/compass-e2e-tests/index.ts @@ -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) => { @@ -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', () => {