Unverified Commit dc8f7737 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Stop adding additional padding to Next.js logs (#86139)

parent 3e5b96a1
...@@ -35,18 +35,15 @@ function prefixedLog(prefixType: keyof typeof prefixes, ...message: any[]) { ...@@ -35,18 +35,15 @@ function prefixedLog(prefixType: keyof typeof prefixes, ...message: any[]) {
// Ensure if there's ANSI escape codes it's concatenated into one string. // Ensure if there's ANSI escape codes it's concatenated into one string.
// Chrome DevTool can only handle color if it's in one string. // Chrome DevTool can only handle color if it's in one string.
if (message.length === 1 && typeof message[0] === 'string') { if (message.length === 1 && typeof message[0] === 'string') {
console[consoleMethod](' ' + prefix + ' ' + message[0]) console[consoleMethod](prefix + ' ' + message[0])
} else { } else {
console[consoleMethod](' ' + prefix, ...message) console[consoleMethod](prefix, ...message)
} }
} }
} }
export function bootstrap(...message: string[]) { export function bootstrap(message: string) {
// logging format: ' <prefix> <message>' console.log(message)
// e.g. ' ✓ Compiled successfully'
// Add spaces to align with the indent of other logs
console.log(' ' + message.join(' '))
} }
export function wait(...message: any[]) { export function wait(...message: any[]) {
......
...@@ -33,11 +33,11 @@ describe('middleware - development errors', () => { ...@@ -33,11 +33,11 @@ describe('middleware - development errors', () => {
}) })
expect(stripAnsi(next.cliOutput)).toContain( expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack isTurbopack
? '\n ⨯ Error: boom' + ? '\n⨯ Error: boom' +
// TODO(veil): Sourcemap to original name i.e. "default" // TODO(veil): Sourcemap to original name i.e. "default"
'\n at __TURBOPACK__default__export__ (middleware.js:3:15)' + '\n at __TURBOPACK__default__export__ (middleware.js:3:15)' +
'\n 1 |' '\n 1 |'
: '\n ⨯ Error: boom' + : '\n⨯ Error: boom' +
'\n at default (middleware.js:3:15)' + '\n at default (middleware.js:3:15)' +
'\n 1 |' '\n 1 |'
) )
...@@ -129,12 +129,12 @@ describe('middleware - development errors', () => { ...@@ -129,12 +129,12 @@ describe('middleware - development errors', () => {
}) })
expect(stripAnsi(next.cliOutput)).toContain( expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack isTurbopack
? ' ⨯ unhandledRejection: Error: async boom!' + ? '⨯ unhandledRejection: Error: async boom!' +
'\n at throwError (middleware.js:4:15)' + '\n at throwError (middleware.js:4:15)' +
// TODO(veil): Sourcemap to original name i.e. "default" // TODO(veil): Sourcemap to original name i.e. "default"
'\n at __TURBOPACK__default__export__ (middleware.js:7:9)' + '\n at __TURBOPACK__default__export__ (middleware.js:7:9)' +
"\n 2 | import { NextResponse } from 'next/server'" "\n 2 | import { NextResponse } from 'next/server'"
: '\n ⨯ unhandledRejection: Error: async boom!' + : '\n⨯ unhandledRejection: Error: async boom!' +
'\n at throwError (middleware.js:4:15)' + '\n at throwError (middleware.js:4:15)' +
'\n at default (middleware.js:7:9)' + '\n at default (middleware.js:7:9)' +
"\n 2 | import { NextResponse } from 'next/server'" "\n 2 | import { NextResponse } from 'next/server'"
...@@ -184,12 +184,12 @@ describe('middleware - development errors', () => { ...@@ -184,12 +184,12 @@ describe('middleware - development errors', () => {
} }
expect(stripAnsi(next.cliOutput)).toContain( expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack isTurbopack
? '\n ⨯ Error [ReferenceError]: test is not defined' + ? '\n⨯ Error [ReferenceError]: test is not defined' +
'\n at eval (middleware.js:4:9)' + '\n at eval (middleware.js:4:9)' +
'\n at <unknown> (middleware.js:4:9)' + '\n at <unknown> (middleware.js:4:9)' +
// TODO(veil): Should be sourcemapped // TODO(veil): Should be sourcemapped
'\n at __TURBOPACK__default__export__ (' '\n at __TURBOPACK__default__export__ ('
: '\n ⨯ Error [ReferenceError]: test is not defined' + : '\n⨯ Error [ReferenceError]: test is not defined' +
// TODO(veil): Redundant and not clickable // TODO(veil): Redundant and not clickable
'\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' + '\n at eval (file://webpack-internal:///(middleware)/./middleware.js)' +
'\n at eval (middleware.js:4:9)' + '\n at eval (middleware.js:4:9)' +
...@@ -198,11 +198,11 @@ describe('middleware - development errors', () => { ...@@ -198,11 +198,11 @@ describe('middleware - development errors', () => {
) )
expect(stripAnsi(next.cliOutput)).toContain( expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack isTurbopack
? "\n ⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" + ? "\n⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
'\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' + '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' +
// TODO(veil): Should be sourcemapped // TODO(veil): Should be sourcemapped
'\n at __TURBOPACK__default__export__ (' '\n at __TURBOPACK__default__export__ ('
: "\n ⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" + : "\n⚠ DynamicCodeEvaluationWarning: Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime" +
'\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' + '\nLearn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation' +
'\n at default (middleware.js:4:9)' + '\n at default (middleware.js:4:9)' +
"\n 2 | import { NextResponse } from 'next/server'" "\n 2 | import { NextResponse } from 'next/server'"
...@@ -294,10 +294,10 @@ describe('middleware - development errors', () => { ...@@ -294,10 +294,10 @@ describe('middleware - development errors', () => {
}) })
expect(stripAnsi(next.cliOutput)).toContain( expect(stripAnsi(next.cliOutput)).toContain(
isTurbopack isTurbopack
? '\n ⨯ Error: booooom!' + ? '\n⨯ Error: booooom!' +
// TODO(veil): Should be sourcemapped // TODO(veil): Should be sourcemapped
'\n at module evaluation (middleware.js:3:13)' '\n at module evaluation (middleware.js:3:13)'
: '\n ⨯ Error: booooom!' + : '\n⨯ Error: booooom!' +
// TODO: Should be anonymous method without a method name // TODO: Should be anonymous method without a method name
'\n at <unknown> (middleware.js:3)' + '\n at <unknown> (middleware.js:3)' +
// TODO: Should be ignore-listed // TODO: Should be ignore-listed
......
...@@ -4965,7 +4965,7 @@ describe('Cache Components Errors', () => { ...@@ -4965,7 +4965,7 @@ describe('Cache Components Errors', () => {
], ],
}, },
{ {
"description": " ⨯ "unhandledRejection:" "BOOM"", "description": "⨯ "unhandledRejection:" "BOOM"",
"environmentLabel": "Prerender", "environmentLabel": "Prerender",
"label": "Console Error", "label": "Console Error",
"source": null, "source": null,
...@@ -4974,7 +4974,7 @@ describe('Cache Components Errors', () => { ...@@ -4974,7 +4974,7 @@ describe('Cache Components Errors', () => {
], ],
}, },
{ {
"description": " ⨯ "unhandledRejection: " "BOOM"", "description": "⨯ "unhandledRejection: " "BOOM"",
"environmentLabel": "Prerender", "environmentLabel": "Prerender",
"label": "Console Error", "label": "Console Error",
"source": null, "source": null,
...@@ -4992,7 +4992,7 @@ describe('Cache Components Errors', () => { ...@@ -4992,7 +4992,7 @@ describe('Cache Components Errors', () => {
], ],
}, },
{ {
"description": " ⨯ "unhandledRejection:" "BAM"", "description": "⨯ "unhandledRejection:" "BAM"",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Console Error", "label": "Console Error",
"source": null, "source": null,
...@@ -5001,7 +5001,7 @@ describe('Cache Components Errors', () => { ...@@ -5001,7 +5001,7 @@ describe('Cache Components Errors', () => {
], ],
}, },
{ {
"description": " ⨯ "unhandledRejection: " "BAM"", "description": "⨯ "unhandledRejection: " "BAM"",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Console Error", "label": "Console Error",
"source": null, "source": null,
......
...@@ -57,7 +57,7 @@ describe('app-dir - server source maps edge runtime', () => { ...@@ -57,7 +57,7 @@ describe('app-dir - server source maps edge runtime', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain( expect(cliOutput).toContain(
' ⨯ Error: ssr-throw' + '⨯ Error: ssr-throw' +
'\n at throwError (app/ssr-throw/page.js:4:9)' + '\n at throwError (app/ssr-throw/page.js:4:9)' +
'\n at Page (app/ssr-throw/page.js:8:3)' + '\n at Page (app/ssr-throw/page.js:8:3)' +
'\n 2 |' + '\n 2 |' +
...@@ -87,7 +87,7 @@ describe('app-dir - server source maps edge runtime', () => { ...@@ -87,7 +87,7 @@ describe('app-dir - server source maps edge runtime', () => {
const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex)) const cliOutput = stripAnsi(next.cliOutput.slice(outputIndex))
expect(cliOutput).toContain( expect(cliOutput).toContain(
' ⨯ Error: rsc-throw' + '⨯ Error: rsc-throw' +
'\n at throwError (app/rsc-throw/page.js:2:9)' + '\n at throwError (app/rsc-throw/page.js:2:9)' +
'\n at Page (app/rsc-throw/page.js:6:3)' + '\n at Page (app/rsc-throw/page.js:6:3)' +
'\n 1 | function throwError() {' + '\n 1 | function throwError() {' +
......
...@@ -40,7 +40,7 @@ describe('fetch failures have good stack traces in edge runtime', () => { ...@@ -40,7 +40,7 @@ describe('fetch failures have good stack traces in edge runtime', () => {
'\n 7 | }' + '\n 7 | }' +
'\n 8 |' + '\n 8 |' +
// TODO(veil): Why double error? // TODO(veil): Why double error?
'\n ⨯ Error [TypeError]: fetch failed' '\n⨯ Error [TypeError]: fetch failed'
) )
// Turbopack produces incorrect mappings in the sourcemap. // Turbopack produces incorrect mappings in the sourcemap.
......
...@@ -221,7 +221,7 @@ describe('Validations for <Link legacyBehavior>', () => { ...@@ -221,7 +221,7 @@ describe('Validations for <Link legacyBehavior>', () => {
}) })
expect(output).toMatchInlineSnapshot( expect(output).toMatchInlineSnapshot(
`" ⨯ Error: \`<Link legacyBehavior>\` received a direct child that is either a Server Component, or JSX that was loaded with React.lazy(). This is not supported. Either remove legacyBehavior, or make the direct child a Client Component that renders the Link's \`<a>\` tag."` `"⨯ Error: \`<Link legacyBehavior>\` received a direct child that is either a Server Component, or JSX that was loaded with React.lazy(). This is not supported. Either remove legacyBehavior, or make the direct child a Client Component that renders the Link's \`<a>\` tag."`
) )
} }
}) })
...@@ -279,7 +279,7 @@ describe('Validations for <Link legacyBehavior>', () => { ...@@ -279,7 +279,7 @@ describe('Validations for <Link legacyBehavior>', () => {
}) })
expect(output).toMatchInlineSnapshot( expect(output).toMatchInlineSnapshot(
`" ⨯ Error: React.Children.only expected to receive a single React element child."` `"⨯ Error: React.Children.only expected to receive a single React element child."`
) )
} }
}) })
...@@ -311,7 +311,7 @@ describe('Validations for <Link legacyBehavior>', () => { ...@@ -311,7 +311,7 @@ describe('Validations for <Link legacyBehavior>', () => {
}) })
expect(output).toMatchInlineSnapshot( expect(output).toMatchInlineSnapshot(
`" ⨯ Error: React.Children.only expected to receive a single React element child."` `"⨯ Error: React.Children.only expected to receive a single React element child."`
) )
} }
}) })
...@@ -350,7 +350,7 @@ describe('Validations for <Link legacyBehavior>', () => { ...@@ -350,7 +350,7 @@ describe('Validations for <Link legacyBehavior>', () => {
}) })
expect(output).toMatchInlineSnapshot( expect(output).toMatchInlineSnapshot(
`" ⨯ Error: \`<Link legacyBehavior>\` received a direct child that is either a Server Component, or JSX that was loaded with React.lazy(). This is not supported. Either remove legacyBehavior, or make the direct child a Client Component that renders the Link's \`<a>\` tag."` `"⨯ Error: \`<Link legacyBehavior>\` received a direct child that is either a Server Component, or JSX that was loaded with React.lazy(). This is not supported. Either remove legacyBehavior, or make the direct child a Client Component that renders the Link's \`<a>\` tag."`
) )
} }
}) })
......
...@@ -16,7 +16,7 @@ const appDir = join(__dirname, '..') ...@@ -16,7 +16,7 @@ const appDir = join(__dirname, '..')
const configFile = new File(join(appDir, '/next.config.js')) const configFile = new File(join(appDir, '/next.config.js'))
const configFileMjs = new File(join(appDir, '/next.config.mjs')) const configFileMjs = new File(join(appDir, '/next.config.mjs'))
const experimentalHeader = ' - Experiments (use with caution):' const experimentalHeader = '- Experiments (use with caution):'
let app let app
async function collectStdoutFromDev(appDir) { async function collectStdoutFromDev(appDir) {
......
...@@ -34,7 +34,7 @@ describe('server-side dev errors', () => { ...@@ -34,7 +34,7 @@ describe('server-side dev errors', () => {
// All tests cause Runtime ReferenceErrors which may lead to this message which // All tests cause Runtime ReferenceErrors which may lead to this message which
// is not relevant to this test. // is not relevant to this test.
stderr = stderr.replace( stderr = stderr.replace(
' ⚠ Fast Refresh had to perform a full reload due to a Runtime ReferenceError.', '⚠ Fast Refresh had to perform a full reload due to a Runtime ReferenceError.',
'' ''
) )
}, },
......
...@@ -93,7 +93,7 @@ export class NextInstance { ...@@ -93,7 +93,7 @@ export class NextInstance {
public forcedPort?: string public forcedPort?: string
public subDir: string = '' public subDir: string = ''
public startServerTimeout: number = 10_000 // 10 seconds public startServerTimeout: number = 10_000 // 10 seconds
public serverReadyPattern: RegExp = / ✓ Ready in / public serverReadyPattern: RegExp = /✓ Ready in /
patchFileDelay: number = 0 patchFileDelay: number = 0
constructor(opts: NextInstanceOpts) { constructor(opts: NextInstanceOpts) {
......
...@@ -53,7 +53,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => { ...@@ -53,7 +53,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {
expect(spy).toHaveBeenCalledWith( expect(spy).toHaveBeenCalledWith(
expect.stringContaining( expect.stringContaining(
' ⚠ `experimental.skipTrailingSlashRedirect` has been moved to `skipTrailingSlashRedirect`. Please update your next.config.js file accordingly.' '⚠ `experimental.skipTrailingSlashRedirect` has been moved to `skipTrailingSlashRedirect`. Please update your next.config.js file accordingly.'
) )
) )
}) })
...@@ -73,7 +73,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => { ...@@ -73,7 +73,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {
expect(spy).toHaveBeenCalledWith( expect(spy).toHaveBeenCalledWith(
expect.stringContaining( expect.stringContaining(
' ⚠ `experimental.relay` has been moved to `compiler.relay`. Please update your next.config.js file accordingly.' '⚠ `experimental.relay` has been moved to `compiler.relay`. Please update your next.config.js file accordingly.'
) )
) )
}) })
...@@ -131,7 +131,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => { ...@@ -131,7 +131,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {
expect(spy).toHaveBeenCalledWith( expect(spy).toHaveBeenCalledWith(
expect.stringContaining( expect.stringContaining(
' ⚠ `experimental.bundlePagesExternals` has been moved to `bundlePagesRouterDependencies`. Please update your next.config.js file accordingly.' '⚠ `experimental.bundlePagesExternals` has been moved to `bundlePagesRouterDependencies`. Please update your next.config.js file accordingly.'
) )
) )
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment