-
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.
fix: add support for coverage JSONs created by
sf apex run test
- Loading branch information
Showing
10 changed files
with
189 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
/* eslint-disable no-await-in-loop */ | ||
|
||
import { create } from 'xmlbuilder2'; | ||
|
||
import { TestCoverageData, CoverageObject, FileObject } from './types.js'; | ||
import { getPackageDirectories } from './getPackageDirectories.js'; | ||
import { findFilePath } from './findFilePath.js'; | ||
import { normalizePathToUnix } from './normalizePathToUnix.js'; | ||
|
||
export async function transformTestCoverageReport( | ||
testCoverageData: TestCoverageData[] | ||
): Promise<{ xml: string; warnings: string[]; filesProcessed: number }> { | ||
const coverageObj: CoverageObject = { coverage: { '@version': '1', file: [] } }; | ||
const warnings: string[] = []; | ||
let filesProcessed: number = 0; | ||
const { repoRoot, packageDirectories } = await getPackageDirectories(); | ||
|
||
if (!Array.isArray(testCoverageData)) { | ||
testCoverageData = [testCoverageData]; | ||
} | ||
|
||
for (const data of testCoverageData) { | ||
const { name, lines } = data; | ||
const formattedFileName = name.replace(/no-map[\\/]+/, ''); | ||
const relativeFilePath = await findFilePath(formattedFileName, packageDirectories, repoRoot); | ||
if (relativeFilePath === undefined) { | ||
warnings.push(`The file name ${formattedFileName} was not found in any package directory.`); | ||
continue; | ||
} | ||
const fileObj: FileObject = { | ||
'@path': normalizePathToUnix(relativeFilePath), | ||
lineToCover: [], | ||
}; | ||
|
||
for (const [lineNumber, isCovered] of Object.entries(lines)) { | ||
fileObj.lineToCover.push({ | ||
'@lineNumber': Number(lineNumber), | ||
'@covered': `${isCovered === 1}`, | ||
}); | ||
} | ||
filesProcessed++; | ||
coverageObj.coverage.file.push(fileObj); | ||
} | ||
const xml = create(coverageObj).end({ prettyPrint: true, indent: ' ' }); | ||
return { xml, warnings, filesProcessed }; | ||
} |
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
File renamed without changes.
File renamed without changes.
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,59 @@ | ||
[ | ||
{ | ||
"id": "01p9X00000DKqDQQA1", | ||
"name": "AccountProfile", | ||
"totalLines": 28, | ||
"lines": { | ||
"9": 1, | ||
"10": 1, | ||
"11": 1, | ||
"12": 1, | ||
"14": 1, | ||
"17": 1, | ||
"20": 1, | ||
"21": 1, | ||
"24": 1, | ||
"25": 1, | ||
"26": 1, | ||
"27": 1, | ||
"28": 1, | ||
"29": 1, | ||
"30": 1, | ||
"32": 1, | ||
"43": 1, | ||
"44": 1, | ||
"52": 1, | ||
"53": 1, | ||
"54": 1, | ||
"55": 1, | ||
"56": 1, | ||
"57": 1, | ||
"59": 1, | ||
"60": 1, | ||
"61": 1, | ||
"62": 1 | ||
}, | ||
"totalCovered": 28, | ||
"coveredPercent": 100 | ||
}, | ||
{ | ||
"id": "01p9X00000DKqCiQAL", | ||
"name": "AccountTrigger", | ||
"totalLines": 11, | ||
"lines": { | ||
"11": 1, | ||
"13": 1, | ||
"14": 1, | ||
"15": 1, | ||
"18": 1, | ||
"20": 1, | ||
"21": 1, | ||
"22": 1, | ||
"23": 1, | ||
"25": 0, | ||
"26": 1 | ||
}, | ||
"totalCovered": 10, | ||
"coveredPercent": 91 | ||
} | ||
] |