forked from aws/aws-toolkit-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core): merge all package test reports (aws#6261)
## Problem - CI test reporting only captures the last package's results - Running `npm run testE2E` only preserves toolkit's report.xml, losing other package results ## Solution - Generate individual report.xml files per subproject - Consolidate all existing package reports into root .test-reports/report.xml - This is done in the buildspecs themselves rather than directly in the package.json (the original approach to solve this problem) because mac/linux and windows have two different ways of getting the last error code, resulting in a complicated package.json for something thats only needed in our codebuilds --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
- Loading branch information
1 parent
3514601
commit 74197a1
Showing
6 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = `${__dirname}/../packages` | ||
|
||
// 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) => `${dir}/.test-reports/report.xml`) | ||
.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') | ||
|
||
// Create reports directory if it doesn't exist | ||
if (!fs.existsSync(reportsDir)) { | ||
fs.mkdirSync(reportsDir, { recursive: true }) | ||
} | ||
|
||
fs.writeFileSync(`${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() |