Skip to content

Commit

Permalink
fix(default-reporter): should print error summary as expected (#6345)
Browse files Browse the repository at this point in the history
* fix(default-reporter): should print error summary as expected

* docs: add changeset
  • Loading branch information
await-ovo authored and zkochan committed Apr 3, 2023
1 parent 56e44a4 commit 292bdd8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/red-knives-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---

Should report error summary as expected.
8 changes: 4 additions & 4 deletions cli/default-reporter/src/reportError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ function reportLockfileBreakingChange (err: Error, msg: object) {
}
}

function formatRecursiveCommandSummary (msg: { fails: Array<Error & { prefix: string }>, passes: number }) {
const output = EOL + `Summary: ${chalk.red(`${msg.fails.length} fails`)}, ${msg.passes} passes` + EOL + EOL +
msg.fails.map((fail) => {
return fail.prefix + ':' + EOL + formatErrorSummary(fail.message)
function formatRecursiveCommandSummary (msg: { failures: Array<Error & { prefix: string }>, passes: number }) {
const output = EOL + `Summary: ${chalk.red(`${msg.failures.length} fails`)}, ${msg.passes} passes` + EOL + EOL +
msg.failures.map(({ message, prefix }) => {
return prefix + ':' + EOL + formatErrorSummary(message)
}).join(EOL + EOL)
return {
title: '',
Expand Down
2 changes: 1 addition & 1 deletion cli/default-reporter/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ ${formatError('ERROR', 'f failed')}`)
})

const err = new PnpmError('RECURSIVE_FAIL', '...')
err['fails'] = [
err['failures'] = [
{
message: 'a failed',
prefix: '/a',
Expand Down
33 changes: 33 additions & 0 deletions pnpm/test/errorHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,36 @@ test('should clean up child processes when process exited', async () => {
expect(await isPortInUse(9990)).toBe(false)
expect(await isPortInUse(9999)).toBe(false)
})

test('should print error summary when some packages fail with --no-bail', async () => {
preparePackages([
{
location: 'project-1',
package: {
scripts: {
build: 'echo "build project-1"',
},
},
},
{
name: 'project-2',
version: '1.0.0',
scripts: {
build: 'exit 1',
},
},
{
name: 'project-3',
version: '1.0.0',
scripts: {
build: 'echo "build project-3"',
},
},
])
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
const { stdout } = execPnpmSync(['-r', '--no-bail', 'run', 'build'])
const output = stdout.toString()
expect(output).toContain('ERR_PNPM_RECURSIVE_FAIL')
expect(output).toContain('Summary: 1 fails, 2 passes')
expect(output).toContain('ERROR  project-2@1.0.0 build: `exit 1`')
})

0 comments on commit 292bdd8

Please sign in to comment.