Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/plugin-coverage/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export const coveragePluginConfigSchema = z.object({
.optional(),
})
.optional(),
continueOnCommandFail: z
.boolean({
description:
'Continue on coverage tool command failure or error. Defaults to true.',
})
.default(true),
coverageTypes: z
.array(coverageTypeSchema, {
description: 'Coverage types measured. Defaults to all available types.',
Expand Down
21 changes: 13 additions & 8 deletions packages/plugin-coverage/src/lib/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function executeRunner({
runnerConfigPath,
runnerOutputPath,
}: RunnerFilesPaths): Promise<void> {
const { reports, coverageToolCommand, coverageTypes } =
const { reports, coverageToolCommand, continueOnCommandFail, coverageTypes } =
await readJsonFile<FinalCoveragePluginConfig>(runnerConfigPath);

// Run coverage tool if provided
Expand All @@ -34,15 +34,20 @@ export async function executeRunner({
await executeProcess({ command, args });
} catch (error) {
if (error instanceof ProcessError) {
ui().logger.error(bold('stdout from failed coverage tool process:'));
ui().logger.error(error.stdout);
ui().logger.error(bold('stderr from failed coverage tool process:'));
ui().logger.error(error.stderr);
const loggingFn = continueOnCommandFail
? ui().logger.warning.bind(ui().logger)
: ui().logger.error.bind(ui().logger);
loggingFn(bold('stdout from failed coverage tool process:'));
loggingFn(error.stdout);
loggingFn(bold('stderr from failed coverage tool process:'));
loggingFn(error.stderr);
}

throw new Error(
'Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing.',
);
if (!continueOnCommandFail) {
throw new Error(
'Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing.',
);
}
}
}

Expand Down
53 changes: 25 additions & 28 deletions packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,34 @@
export async function parseLcovFiles(
results: CoverageResult[],
): Promise<LCOVRecord[]> {
const parsedResults = await Promise.all(
results.map(async result => {
const resultsPath =
typeof result === 'string' ? result : result.resultsPath;
const lcovFileContent = await readTextFile(resultsPath);
if (lcovFileContent.trim() === '') {
ui().logger.warning(
`Coverage plugin: Empty lcov report file detected at ${resultsPath}.`,
);
}
const parsedRecords = parseLcov(toUnixNewlines(lcovFileContent));
return parsedRecords.map<LCOVRecord>(record => ({
...record,
file:
typeof result === 'string' || result.pathToProject == null
? record.file
: path.join(result.pathToProject, record.file),
}));
}),
);
if (parsedResults.length !== results.length) {
throw new Error('Some provided LCOV results were not valid.');
}

const flatResults = parsedResults.flat();
const parsedResults = (
await Promise.all(
results.map(async result => {
const resultsPath =
typeof result === 'string' ? result : result.resultsPath;
const lcovFileContent = await readTextFile(resultsPath);
if (lcovFileContent.trim() === '') {

Check failure on line 64 in packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts

View workflow job for this annotation

GitHub Actions / Code PushUp

<✓> Code coverage | Branch coverage

1st branch is not taken in any test case.
ui().logger.warning(
`Coverage plugin: Empty lcov report file detected at ${resultsPath}.`,
);
}
const parsedRecords = parseLcov(toUnixNewlines(lcovFileContent));
return parsedRecords.map<LCOVRecord>(record => ({
...record,
file:
typeof result === 'string' || result.pathToProject == null
? record.file
: path.join(result.pathToProject, record.file),
}));
}),
)
).flat();

if (flatResults.length === 0) {
throw new Error('All provided results are empty.');
if (parsedResults.length === 0) {
throw new Error('All provided coverage results are empty.');
}

return flatResults;
return parsedResults;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ end_of_record
it('should throw for only empty reports', async () => {
await expect(() =>
parseLcovFiles([path.join('coverage', 'lcov.info')]),
).rejects.toThrow('All provided results are empty.');
).rejects.toThrow('All provided coverage results are empty.');
});

it('should warn about an empty lcov file', async () => {
Expand Down
Loading