From c00f74e95e96287f856ca29b2ef50c0c0a27d9be Mon Sep 17 00:00:00 2001 From: Peter <53189696+PeterYinusa@users.noreply.github.com> Date: Fri, 10 Feb 2023 19:34:01 +0000 Subject: [PATCH] e2e multiple reports (#17715) * multiple reports * fix run all * clean up report --- development/lib/run-command.js | 14 +++++++++----- package.json | 2 +- test/e2e/e2e-process-report.js | 10 ++++++++++ test/e2e/run-all.js | 2 ++ test/e2e/run-e2e-test.js | 25 +++++++++++++++---------- 5 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 test/e2e/e2e-process-report.js diff --git a/development/lib/run-command.js b/development/lib/run-command.js index 08bffcc1b..1097e6abc 100644 --- a/development/lib/run-command.js +++ b/development/lib/run-command.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const spawn = require('cross-spawn'); /** @@ -87,17 +88,20 @@ async function runCommand(command, args) { * * @param {string} command - The command to run * @param {Array} [args] - The arguments to pass to the command + * @param {string} output - The output file to write to */ -async function runInShell(command, args) { +async function runInShell(command, args, output) { let errorSignal; let errorCode; const internalError = new Error('Internal'); try { await new Promise((resolve, reject) => { - const childProcess = spawn(command, args, { - encoding: 'utf8', - stdio: 'inherit', - }); + const childProcess = spawn(command, args); + childProcess.stdout.setEncoding('utf8'); + childProcess.stdout.pipe(process.stdout); + if (output) { + childProcess.stdout.pipe(fs.createWriteStream(output)); + } childProcess.once('exit', (code, signal) => { if (code === 0) { diff --git a/package.json b/package.json index 2355654ed..b298aba1b 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "test:e2e:firefox:snaps": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js --snaps", "test:e2e:firefox:nft": "SELENIUM_BROWSER=firefox node test/e2e/run-all.js --nft", "test:e2e:single": "node test/e2e/run-e2e-test.js", - "test:e2e:report": "jrm ./test/test-results/e2e.xml \"./test/test-results/e2e/*.xml\"", + "test:e2e:report": "node ./test/e2e/e2e-process-report.js && jrm ./test/test-results/e2e.xml \"./test/test-results/e2e/*.xml\"", "test:coverage:mocha": "node ./test/run-unit-tests.js --mocha --coverage", "test:coverage:jest": "node ./test/run-unit-tests.js --jestGlobal --coverage", "test:coverage:jest:dev": "node ./test/run-unit-tests.js --jestDev --coverage", diff --git a/test/e2e/e2e-process-report.js b/test/e2e/e2e-process-report.js new file mode 100644 index 000000000..a9146ec12 --- /dev/null +++ b/test/e2e/e2e-process-report.js @@ -0,0 +1,10 @@ +const fs = require('fs'); + +const dir = 'test/test-results/e2e'; + +fs.readdirSync(dir).forEach((file) => { + const currentFile = `${dir}/${file}`; + let data = fs.readFileSync(currentFile, { encoding: 'utf8', flag: 'r' }); + data = data.substring(data.indexOf(' { - await runInShell('yarn', [ - 'mocha', - `--config=${configFile}`, - `--timeout=${testTimeoutInMilliseconds}`, - '--reporter=xunit', - '--reporter-option', - `output=test/test-results/e2e/${testFileName}.xml`, - e2eTestPath, - exit, - ]); + await runInShell( + 'yarn', + [ + 'mocha', + `--config=${configFile}`, + `--timeout=${testTimeoutInMilliseconds}`, + '--reporter=xunit', + e2eTestPath, + exit, + ], + `${dir}/${testFileName}.xml`, + ); }); }