Skip to content

Commit

Permalink
Polish error icon for error log (#55618)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Sep 20, 2023
1 parent 23c3ea4 commit f5bef04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/build/output/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from '../../lib/chalk'

export const prefixes = {
wait: chalk.white(chalk.bold('○')),
error: chalk.red(chalk.bold('X')),
error: chalk.red(chalk.bold('')),
warn: chalk.yellow(chalk.bold('⚠')),
ready: chalk.bold('▲'), // no color
info: chalk.white(chalk.bold(' ')),
Expand Down
46 changes: 26 additions & 20 deletions test/development/middleware-errors/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ createNextDescribe(
it('logs the error correctly', async () => {
await next.fetch('/')
const output = stripAnsi(next.cliOutput)
await check(
() => stripAnsi(next.cliOutput),
new RegExp(
`middleware.js \\(\\d+:\\d+\\) @ Object.default \\[as handler\\]\\s*\\w+\\s*boom`,
'm'
await check(() => {
expect(stripAnsi(next.cliOutput)).toMatch(
/middleware.js \(\d+:\d+\) @ Object.default \[as handler\]/
)
)
expect(stripAnsi(next.cliOutput)).toMatch(/boom/)
return 'success'
}, 'success')
expect(output).not.toContain(
'webpack-internal:///(middleware)/./middleware.js'
)
Expand Down Expand Up @@ -103,13 +103,13 @@ createNextDescribe(
it('logs the error correctly', async () => {
await next.fetch('/')
const output = stripAnsi(next.cliOutput)
await check(
() => stripAnsi(next.cliOutput),
new RegExp(
`middleware.js \\(\\d+:\\d+\\) @ eval\\s*\\w+\\s*test is not defined`,
'm'
await check(() => {
expect(stripAnsi(next.cliOutput)).toMatch(
/middleware.js \(\d+:\d+\) @ eval/
)
)
expect(stripAnsi(next.cliOutput)).toMatch(/test is not defined/)
return 'success'
}, 'success')
expect(output).not.toContain(
'webpack-internal:///(middleware)/./middleware.js'
)
Expand Down Expand Up @@ -141,13 +141,13 @@ createNextDescribe(
it('logs the error correctly', async () => {
await next.fetch('/')
const output = stripAnsi(next.cliOutput)
await check(
() => stripAnsi(next.cliOutput),
new RegExp(
`middleware.js \\(\\d+:\\d+\\) @ <unknown>\\s*\\w+\\s*booooom!`,
'm'
await check(() => {
expect(stripAnsi(next.cliOutput)).toMatch(
/middleware.js \(\d+:\d+\) @ <unknown>/
)
)
expect(stripAnsi(next.cliOutput)).toMatch(/booooom!/)
return 'success'
}, 'success')
expect(output).not.toContain(
'webpack-internal:///(middleware)/./middleware.js'
)
Expand Down Expand Up @@ -247,8 +247,14 @@ createNextDescribe(

it('logs the error correctly', async () => {
await next.fetch('/')
expect(next.cliOutput).toContain(`Expected '{', got '}'`)
expect(next.cliOutput.split(`Expected '{', got '}'`).length).toEqual(2)
await check(async () => {
expect(next.cliOutput).toContain(`Expected '{', got '}'`)
expect(next.cliOutput.split(`Expected '{', got '}'`).length).toEqual(
2
)

return 'success'
}, 'success')
})

it('renders the error correctly and recovers', async () => {
Expand Down

0 comments on commit f5bef04

Please sign in to comment.