-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(core): merge all package test reports #6261
base: master
Are you sure you want to change the base?
Changes from 15 commits
0b2aed9
081c031
5ef73cf
dfe2892
5273b20
5b6e145
adf5ca6
4e5655f
bb0bf30
b7e94e0
9d89d5b
155f4c5
d03a757
924b90e
5d3ade7
9a6f7b7
28384ad
a5f44d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import * as xml2js from 'xml2js' | ||
|
||
/** | ||
* Merge all of the packages/ test reports into a single directory | ||
*/ | ||
async function mergeReports() { | ||
console.log('Merging test reports') | ||
|
||
const packagesDir = path.join(__dirname, '..', 'packages') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string literals do not need join() |
||
|
||
// Get all packages/* directories | ||
const packageDirs = fs.readdirSync(packagesDir).map((dir) => path.join(packagesDir, dir)) | ||
|
||
// Find report.xml files in .test-reports subdirectories | ||
const testReports = packageDirs | ||
.map((dir) => path.join(dir, '.test-reports', 'report.xml')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string literals do not need join() |
||
.filter((file) => fs.existsSync(file)) | ||
|
||
const mergedReport = { | ||
testsuites: { | ||
testsuite: [], | ||
}, | ||
} | ||
|
||
// Collect all test reports into a single merged test report object | ||
for (const file of testReports) { | ||
const content = fs.readFileSync(file) | ||
const result: { testsuites: { testsuite: [] } } = await xml2js.parseStringPromise(content) | ||
if (result.testsuites && result.testsuites.testsuite) { | ||
mergedReport.testsuites.testsuite.push(...result.testsuites.testsuite) | ||
} | ||
} | ||
|
||
const builder = new xml2js.Builder() | ||
const xml = builder.buildObject(mergedReport) | ||
|
||
/** | ||
* Create the new test reports directory and write the test report | ||
*/ | ||
const reportsDir = path.join(__dirname, '..', '.test-reports') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string literals do not need join() |
||
|
||
// Create reports directory if it doesn't exist | ||
if (!fs.existsSync(reportsDir)) { | ||
fs.mkdirSync(reportsDir, { recursive: true }) | ||
} | ||
|
||
fs.writeFileSync(path.join(reportsDir, 'report.xml'), xml) | ||
|
||
const exitCodeArg = process.argv[2] | ||
if (exitCodeArg) { | ||
/** | ||
* Retrieves the exit code from the previous test run execution. | ||
* | ||
* This allows us to: | ||
* 1. Merge and upload test reports regardless of the test execution status | ||
* 2. Preserve the original test run exit code | ||
* 3. Report the test status back to CI | ||
*/ | ||
const exitCode = parseInt(exitCodeArg || '0', 10) | ||
process.exit(exitCode) | ||
} | ||
} | ||
|
||
mergeReports() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on a local test of this command:
I suspect the above
;
may not correctly pipe all the output fromnpm test
torun_and_report
as intended.To confirm that the piping to
run_and_report
is still working correctly, can you try temporarily changing this search patter to something that always outputs, like:then CI should fail.
If it doesn't, we can fix the issue by changing the pipeline to something like (note: whitespace near the braces is required):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested and that was indeed the case. I've switched to your suggestion and it seems to work as expected