Unverified Commit 30f84e31 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update dev logs to include request timings (#49191)

This updates our dev logs to include request timings and also includes
fetch timings in app directory to including info on whether the cache
was leveraged or not allowing easier debugging of contributing factors
to render times. In the future we can expand to include middleware
timings separate as well to single that out along with timings for
`getStaticProps` potentially as well.


<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
19@2x](https://user-images.githubusercontent.com/22380829/236135624-da1d873b-5abf-42d0-9708-8e20d1c56cef.png)

</details>

<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
32@2x](https://user-images.githubusercontent.com/22380829/236135642-bc974b82-13e0-47f0-8be5-581d92077fc1.png)

</details>

<details>

<summary>Screenshot</summary>

![CleanShot 2023-05-04 at 00 13
47@2x](https://user-images.githubusercontent.com/22380829/236135664-5b2975ce-fa78-40d5-b320-d42d35b17541.png)

</details>

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1681418590738249)
parent d24f506e
import chalk from '../../lib/chalk' import chalk from '../../lib/chalk'
export const prefixes = { export const prefixes = {
wait: chalk.cyan('wait') + ' -', wait: '- ' + chalk.cyan('wait'),
error: chalk.red('error') + ' -', error: '- ' + chalk.red('error'),
warn: chalk.yellow('warn') + ' -', warn: '- ' + chalk.yellow('warn'),
ready: chalk.green('ready') + ' -', ready: '- ' + chalk.green('ready'),
info: chalk.cyan('info') + ' -', info: '- ' + chalk.cyan('info'),
event: chalk.magenta('event') + ' -', event: '- ' + chalk.magenta('event'),
trace: chalk.magenta('trace') + ' -', trace: '- ' + chalk.magenta('trace'),
} }
export function wait(...message: any[]) { export function wait(...message: any[]) {
......
...@@ -31,6 +31,15 @@ export interface StaticGenerationStore { ...@@ -31,6 +31,15 @@ export interface StaticGenerationStore {
pathWasRevalidated?: boolean pathWasRevalidated?: boolean
tags?: string[] tags?: string[]
fetchMetrics?: Array<{
url: string
idx: number
end: number
start: number
method: string
status: number
cacheStatus: 'hit' | 'miss'
}>
} }
export type StaticGenerationAsyncStorage = export type StaticGenerationAsyncStorage =
......
...@@ -217,6 +217,8 @@ export async function renderToHTMLOrFlight( ...@@ -217,6 +217,8 @@ export async function renderToHTMLOrFlight(
`Invariant: Render expects to have staticGenerationAsyncStorage, none found` `Invariant: Render expects to have staticGenerationAsyncStorage, none found`
) )
} }
staticGenerationStore.fetchMetrics = []
;(renderOpts as any).fetchMetrics = staticGenerationStore.fetchMetrics
// don't modify original query object // don't modify original query object
query = { ...query } query = { ...query }
......
...@@ -1613,6 +1613,10 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1613,6 +1613,10 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Handle the match and collect the response if it's a static response. // Handle the match and collect the response if it's a static response.
const response = await this.handlers.handle(match, req, context) const response = await this.handlers.handle(match, req, context)
if (response) { if (response) {
;(req as any).fetchMetrics = (
context.staticGenerationContext as any
).fetchMetrics
const cacheTags = (context.staticGenerationContext as any).fetchTags const cacheTags = (context.staticGenerationContext as any).fetchTags
// If the request is for a static response, we can cache it so long // If the request is for a static response, we can cache it so long
...@@ -1753,6 +1757,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1753,6 +1757,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
'x-next-cache-tags': cacheTags, 'x-next-cache-tags': cacheTags,
} }
} }
;(req as any).fetchMetrics = (renderOpts as any).fetchMetrics
// we don't throw static to dynamic errors in dev as isSSG // we don't throw static to dynamic errors in dev as isSSG
// is a best guess in dev since we don't have the prerender pass // is a best guess in dev since we don't have the prerender pass
......
...@@ -345,6 +345,8 @@ export class AppRouteRouteModule extends RouteModule< ...@@ -345,6 +345,8 @@ export class AppRouteRouteModule extends RouteModule<
const res = await handler(wrappedRequest, { const res = await handler(wrappedRequest, {
params: context.params, params: context.params,
}) })
;(context.staticGenerationContext as any).fetchMetrics =
staticGenerationStore.fetchMetrics
await Promise.all( await Promise.all(
staticGenerationStore.pendingRevalidates || [] staticGenerationStore.pendingRevalidates || []
......
...@@ -26,6 +26,43 @@ export function addImplicitTags( ...@@ -26,6 +26,43 @@ export function addImplicitTags(
return newTags return newTags
} }
function trackFetchMetric(
staticGenerationStore: ReturnType<StaticGenerationAsyncStorage['getStore']>,
ctx: {
url: string
status: number
method: string
cacheStatus: 'hit' | 'miss'
start: number
}
) {
if (!staticGenerationStore) return
if (!staticGenerationStore.fetchMetrics) {
staticGenerationStore.fetchMetrics = []
}
const dedupeFields = ['url', 'status', 'method']
// don't add metric if one already exists for the fetch
if (
staticGenerationStore.fetchMetrics.some((metric) => {
return dedupeFields.every(
(field) => (metric as any)[field] === (ctx as any)[field]
)
})
) {
return
}
staticGenerationStore.fetchMetrics.push({
url: ctx.url,
cacheStatus: ctx.cacheStatus,
status: ctx.status,
method: ctx.method,
start: ctx.start,
end: Date.now(),
idx: staticGenerationStore.nextFetchId || 0,
})
}
// we patch fetch to collect cache information used for // we patch fetch to collect cache information used for
// determining if a page is static or not // determining if a page is static or not
export function patchFetch({ export function patchFetch({
...@@ -53,7 +90,7 @@ export function patchFetch({ ...@@ -53,7 +90,7 @@ export function patchFetch({
// Error caused by malformed URL should be handled by native fetch // Error caused by malformed URL should be handled by native fetch
url = undefined url = undefined
} }
const fetchStart = Date.now()
const method = init?.method?.toUpperCase() || 'GET' const method = init?.method?.toUpperCase() || 'GET'
return await getTracer().trace( return await getTracer().trace(
...@@ -267,7 +304,7 @@ export function patchFetch({ ...@@ -267,7 +304,7 @@ export function patchFetch({
const fetchIdx = staticGenerationStore.nextFetchId ?? 1 const fetchIdx = staticGenerationStore.nextFetchId ?? 1
staticGenerationStore.nextFetchId = fetchIdx + 1 staticGenerationStore.nextFetchId = fetchIdx + 1
const doOriginalFetch = async () => { const doOriginalFetch = async (isStale?: boolean) => {
// add metadata to init without editing the original // add metadata to init without editing the original
const clonedInit = { const clonedInit = {
...init, ...init,
...@@ -275,6 +312,15 @@ export function patchFetch({ ...@@ -275,6 +312,15 @@ export function patchFetch({
} }
return originFetch(input, clonedInit).then(async (res) => { return originFetch(input, clonedInit).then(async (res) => {
if (!isStale) {
trackFetchMetric(staticGenerationStore, {
start: fetchStart,
url: fetchUrl,
cacheStatus: 'miss',
status: res.status,
method: clonedInit.method || 'GET',
})
}
if ( if (
res.status === 200 && res.status === 200 &&
staticGenerationStore.incrementalCache && staticGenerationStore.incrementalCache &&
...@@ -336,7 +382,7 @@ export function patchFetch({ ...@@ -336,7 +382,7 @@ export function patchFetch({
staticGenerationStore.pendingRevalidates = [] staticGenerationStore.pendingRevalidates = []
} }
staticGenerationStore.pendingRevalidates.push( staticGenerationStore.pendingRevalidates.push(
doOriginalFetch().catch(console.error) doOriginalFetch(true).catch(console.error)
) )
} else if ( } else if (
tags && tags &&
...@@ -374,6 +420,14 @@ export function patchFetch({ ...@@ -374,6 +420,14 @@ export function patchFetch({
decodedBody = Buffer.from(resData.body, 'base64').subarray() decodedBody = Buffer.from(resData.body, 'base64').subarray()
} }
trackFetchMetric(staticGenerationStore, {
start: fetchStart,
url: fetchUrl,
cacheStatus: 'hit',
status: resData.status || 200,
method: init?.method || 'GET',
})
return new Response(decodedBody, { return new Response(decodedBody, {
headers: resData.headers, headers: resData.headers,
status: resData.status, status: resData.status,
......
...@@ -18,7 +18,7 @@ import type RenderResult from './render-result' ...@@ -18,7 +18,7 @@ import type RenderResult from './render-result'
import type { FetchEventResult } from './web/types' import type { FetchEventResult } from './web/types'
import type { PrerenderManifest } from '../build' import type { PrerenderManifest } from '../build'
import type { CustomRoutes, Rewrite } from '../lib/load-custom-routes' import type { CustomRoutes, Rewrite } from '../lib/load-custom-routes'
import type { BaseNextRequest, BaseNextResponse } from './base-http' import { BaseNextRequest, BaseNextResponse } from './base-http'
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import type { PayloadOptions } from './send-payload' import type { PayloadOptions } from './send-payload'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta' import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
...@@ -109,6 +109,7 @@ import { pathHasPrefix } from '../shared/lib/router/utils/path-has-prefix' ...@@ -109,6 +109,7 @@ import { pathHasPrefix } from '../shared/lib/router/utils/path-has-prefix'
import { invokeRequest } from './lib/server-ipc/invoke-request' import { invokeRequest } from './lib/server-ipc/invoke-request'
import { filterReqHeaders } from './lib/server-ipc/utils' import { filterReqHeaders } from './lib/server-ipc/utils'
import { createRequestResponseMocks } from './lib/mock-request' import { createRequestResponseMocks } from './lib/mock-request'
import chalk from 'next/dist/compiled/chalk'
export * from './base-server' export * from './base-server'
...@@ -1461,7 +1462,7 @@ export default class NextNodeServer extends BaseServer { ...@@ -1461,7 +1462,7 @@ export default class NextNodeServer extends BaseServer {
'x-invoke-path': invokePathname, 'x-invoke-path': invokePathname,
'x-invoke-query': encodeURIComponent(invokeQuery), 'x-invoke-query': encodeURIComponent(invokeQuery),
} }
;(req as any).didInvokePath = true
const invokeRes = await invokeRequest( const invokeRes = await invokeRequest(
renderUrl.toString(), renderUrl.toString(),
{ {
...@@ -1668,7 +1669,138 @@ export default class NextNodeServer extends BaseServer { ...@@ -1668,7 +1669,138 @@ export default class NextNodeServer extends BaseServer {
void this.prepare() void this.prepare()
const handler = super.getRequestHandler() const handler = super.getRequestHandler()
return async (req, res, parsedUrl) => { return async (req, res, parsedUrl) => {
return handler(this.normalizeReq(req), this.normalizeRes(res), parsedUrl) const normalizedReq = this.normalizeReq(req)
const normalizedRes = this.normalizeRes(res)
if (this.renderOpts.dev) {
const _req = req as NodeNextRequest | IncomingMessage
const _res = res as NodeNextResponse | ServerResponse
const origReq = 'originalRequest' in _req ? _req.originalRequest : _req
const origRes =
'originalResponse' in _res ? _res.originalResponse : _res
const reqStart = Date.now()
const reqCallback = () => {
// if we already logged in a render worker
// don't log again in the router worker.
// we also don't log for middleware alone
if (
(normalizedReq as any).didInvokePath ||
origReq.headers['x-middleware-invoke']
) {
return
}
const reqEnd = Date.now()
const fetchMetrics = (normalizedReq as any).fetchMetrics || []
const reqDuration = reqEnd - reqStart
const getDurationStr = (duration: number) => {
let durationStr = duration.toString()
if (duration < 500) {
durationStr = chalk.green(duration + 'ms')
} else if (duration < 2000) {
durationStr = chalk.yellow(duration + 'ms')
} else {
durationStr = chalk.red(duration + 'ms')
}
return durationStr
}
if (Array.isArray(fetchMetrics) && fetchMetrics.length) {
process.stdout.write('\n')
process.stdout.write(
`- ${chalk.grey('┌')} ${chalk.cyan(req.method || 'GET')} ${
req.url
} ${res.statusCode} in ${getDurationStr(reqDuration)}\n`
)
const calcNestedLevel = (
prevMetrics: any[],
start: number
): string => {
let nestedLevel = 0
for (let i = 0; i < prevMetrics.length; i++) {
const metric = prevMetrics[i]
const prevMetric = prevMetrics[i - 1]
if (
metric.end <= start &&
!(prevMetric && prevMetric.start < metric.end)
) {
nestedLevel += 1
}
}
if (nestedLevel === 0) return ''
return ` ${nestedLevel} level${nestedLevel === 1 ? '' : 's'} `
}
for (let i = 0; i < fetchMetrics.length; i++) {
const metric = fetchMetrics[i]
const lastItem = i === fetchMetrics.length - 1
let cacheStatus = metric.cacheStatus
const duration = metric.end - metric.start
if (cacheStatus === 'hit') {
cacheStatus = chalk.green('HIT')
} else {
cacheStatus = chalk.yellow('MISS')
}
let url = metric.url
if (url.length > 48) {
const parsed = new URL(url)
const truncatedHost =
parsed.host.length > 16
? parsed.host.substring(0, 16) + '..'
: parsed.host
const truncatedPath =
parsed.pathname.length > 24
? parsed.pathname.substring(0, 24) + '..'
: parsed.pathname
const truncatedSearch =
parsed.search.length > 16
? parsed.search.substring(0, 16) + '..'
: parsed.search
url =
parsed.protocol +
'//' +
truncatedHost +
truncatedPath +
truncatedSearch
}
process.stdout.write(` ${chalk.grey('│')}\n`)
process.stdout.write(
` ${chalk.grey(
`${lastItem ? '└' : '├'}──${calcNestedLevel(
fetchMetrics.slice(0, i),
metric.start
)}──`
)} ${chalk.cyan(metric.method)} ${url} ${
metric.status
} in ${getDurationStr(duration)} (cache: ${cacheStatus})\n`
)
}
process.stdout.write('\n')
} else {
process.stdout.write(
`- ${chalk.cyan(req.method || 'GET')} ${req.url} ${
res.statusCode
} in ${getDurationStr(reqDuration)}\n`
)
}
origRes.off('close', reqCallback)
}
origRes.on('close', reqCallback)
}
return handler(normalizedReq, normalizedRes, parsedUrl)
} }
} }
......
...@@ -2,6 +2,7 @@ import { ...@@ -2,6 +2,7 @@ import {
StaticGenerationAsyncStorage, StaticGenerationAsyncStorage,
StaticGenerationStore, StaticGenerationStore,
} from '../../../client/components/static-generation-async-storage' } from '../../../client/components/static-generation-async-storage'
import { addImplicitTags } from '../../lib/patch-fetch'
type Callback = (...args: any[]) => Promise<any> type Callback = (...args: any[]) => Promise<any>
...@@ -54,6 +55,15 @@ export function unstable_cache<T extends Callback>( ...@@ -54,6 +55,15 @@ export function unstable_cache<T extends Callback>(
options.revalidate as number options.revalidate as number
)) ))
const tags = options.tags || []
const implicitTags = addImplicitTags(store)
for (const tag of implicitTags) {
if (!tags.includes(tag)) {
tags.push(tag)
}
}
const invokeCallback = async () => { const invokeCallback = async () => {
const result = await cb(...args) const result = await cb(...args)
...@@ -67,7 +77,7 @@ export function unstable_cache<T extends Callback>( ...@@ -67,7 +77,7 @@ export function unstable_cache<T extends Callback>(
// TODO: handle non-JSON values? // TODO: handle non-JSON values?
body: JSON.stringify(result), body: JSON.stringify(result),
status: 200, status: 200,
tags: options.tags, tags,
}, },
revalidate: options.revalidate as number, revalidate: options.revalidate as number,
}, },
...@@ -106,15 +116,12 @@ export function unstable_cache<T extends Callback>( ...@@ -106,15 +116,12 @@ export function unstable_cache<T extends Callback>(
console.error(`revalidating cache with key: ${joinedKey}`, err) console.error(`revalidating cache with key: ${joinedKey}`, err)
) )
) )
} else if ( } else if (tags && !tags.every((tag) => currentTags?.includes(tag))) {
options.tags &&
!options.tags.every((tag) => currentTags?.includes(tag))
) {
if (!cacheEntry.value.data.tags) { if (!cacheEntry.value.data.tags) {
cacheEntry.value.data.tags = [] cacheEntry.value.data.tags = []
} }
for (const tag of options.tags) { for (const tag of tags) {
if (!cacheEntry.value.data.tags.includes(tag)) { if (!cacheEntry.value.data.tags.includes(tag)) {
cacheEntry.value.data.tags.push(tag) cacheEntry.value.data.tags.push(tag)
} }
......
...@@ -24,7 +24,7 @@ describe('api-route-errors cli output', () => { ...@@ -24,7 +24,7 @@ describe('api-route-errors cli output', () => {
const output = stripAnsi(next.cliOutput.slice(outputIndex)) const output = stripAnsi(next.cliOutput.slice(outputIndex))
// Location // Location
expect(output).toContain('error - pages/api/error.js (2:8) @ error') expect(output).toContain('- error pages/api/error.js (2:8) @ error')
// Stack // Stack
expect(output).toContain('pages/api/error.js:6:11') expect(output).toContain('pages/api/error.js:6:11')
// Source code // Source code
...@@ -39,7 +39,7 @@ describe('api-route-errors cli output', () => { ...@@ -39,7 +39,7 @@ describe('api-route-errors cli output', () => {
const output = stripAnsi(next.cliOutput.slice(outputIndex)) const output = stripAnsi(next.cliOutput.slice(outputIndex))
// Location // Location
expect(output).toContain( expect(output).toContain(
'error - pages/api/uncaught-exception.js (3:10) @ Timeout' '- error pages/api/uncaught-exception.js (3:10) @ Timeout'
) )
// Stack // Stack
expect(output).toContain('pages/api/uncaught-exception.js:7:15') expect(output).toContain('pages/api/uncaught-exception.js:7:15')
...@@ -57,7 +57,7 @@ describe('api-route-errors cli output', () => { ...@@ -57,7 +57,7 @@ describe('api-route-errors cli output', () => {
const output = stripAnsi(next.cliOutput.slice(outputIndex)) const output = stripAnsi(next.cliOutput.slice(outputIndex))
// Location // Location
expect(output).toContain( expect(output).toContain(
'error - pages/api/unhandled-rejection.js (2:17) @ unhandledRejection' '- error pages/api/unhandled-rejection.js (2:17) @ unhandledRejection'
) )
// Stack // Stack
expect(output).toContain('pages/api/unhandled-rejection.js:6:20') expect(output).toContain('pages/api/unhandled-rejection.js:6:20')
......
...@@ -54,7 +54,7 @@ describe.each([ ...@@ -54,7 +54,7 @@ describe.each([
expect(res.status).toEqual(200) expect(res.status).toEqual(200)
expect(next.cliOutput).not.toInclude('error') expect(next.cliOutput).not.toInclude('error')
expect(stripAnsi(next.cliOutput)).toInclude( expect(stripAnsi(next.cliOutput)).toInclude(
`warn - /pages/api/edge provided runtime 'experimental-edge'. It can be updated to 'edge' instead.` `- warn /pages/api/edge provided runtime 'experimental-edge'. It can be updated to 'edge' instead.`
) )
}) })
it('warns about page using edge runtime', async () => { it('warns about page using edge runtime', async () => {
...@@ -70,7 +70,7 @@ describe.each([ ...@@ -70,7 +70,7 @@ describe.each([
expect(res.status).toEqual(200) expect(res.status).toEqual(200)
expect(next.cliOutput).not.toInclude('error') expect(next.cliOutput).not.toInclude('error')
expect(stripAnsi(next.cliOutput)).toInclude( expect(stripAnsi(next.cliOutput)).toInclude(
`warn - You are using an experimental edge runtime, the API might change.` `- warn You are using an experimental edge runtime, the API might change.`
) )
}) })
...@@ -86,7 +86,7 @@ describe.each([ ...@@ -86,7 +86,7 @@ describe.each([
const res = await fetchViaHTTP(next.url, `/`) const res = await fetchViaHTTP(next.url, `/`)
expect(res.status).toEqual(200) expect(res.status).toEqual(200)
expect(stripAnsi(next.cliOutput)).toInclude( expect(stripAnsi(next.cliOutput)).toInclude(
`error - Page /pages provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.` `- error Page /pages provided runtime 'edge', the edge runtime for rendering is currently experimental. Use runtime 'experimental-edge' instead.`
) )
expect(next.cliOutput).not.toInclude('warn') expect(next.cliOutput).not.toInclude('warn')
}) })
......
...@@ -426,7 +426,7 @@ describe('Switchable runtime', () => { ...@@ -426,7 +426,7 @@ describe('Switchable runtime', () => {
/Hello from page with invalid type/ /Hello from page with invalid type/
) )
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
'error - The `runtime` config must be a string. Please leave it empty or choose one of:' '- error The `runtime` config must be a string. Please leave it empty or choose one of:'
) )
// Invalid runtime // Invalid runtime
...@@ -447,7 +447,7 @@ describe('Switchable runtime', () => { ...@@ -447,7 +447,7 @@ describe('Switchable runtime', () => {
/Hello from page with invalid runtime/ /Hello from page with invalid runtime/
) )
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
'error - Provided runtime "asd" is not supported. Please leave it empty or choose one of:' '- error Provided runtime "asd" is not supported. Please leave it empty or choose one of:'
) )
// Fix the runtime // Fix the runtime
...@@ -486,7 +486,7 @@ describe('Switchable runtime', () => { ...@@ -486,7 +486,7 @@ describe('Switchable runtime', () => {
/Hello from app/ /Hello from app/
) )
expect(next.cliOutput).toInclude( expect(next.cliOutput).toInclude(
'error - Provided runtime "invalid-runtime" is not supported. Please leave it empty or choose one of:' '- error Provided runtime "invalid-runtime" is not supported. Please leave it empty or choose one of:'
) )
await next.patchFile( await next.patchFile(
......
...@@ -52,7 +52,7 @@ describe.skip('app dir with output export (next dev / next build)', () => { ...@@ -52,7 +52,7 @@ describe.skip('app dir with output export (next dev / next build)', () => {
} }
) )
expect(stderr).toContain( expect(stderr).toContain(
'warn - "next export" is no longer needed when "output: export" is configured in next.config.js' '- warn "next export" is no longer needed when "output: export" is configured in next.config.js'
) )
expect(stdout).toContain('Export successful. Files written to') expect(stdout).toContain('Export successful. Files written to')
expect(await getFiles()).toEqual(expectedFiles) expect(await getFiles()).toEqual(expectedFiles)
...@@ -85,7 +85,7 @@ describe.skip('app dir with output export (next dev / next build)', () => { ...@@ -85,7 +85,7 @@ describe.skip('app dir with output export (next dev / next build)', () => {
} }
expect(error).toBeDefined() expect(error).toBeDefined()
expect(stderr).toContain( expect(stderr).toContain(
'error - "next export" does not work with App Router. Please use "output: export" in next.config.js' '- error "next export" does not work with App Router. Please use "output: export" in next.config.js'
) )
expect(stdout).not.toContain('Export successful. Files written to') expect(stdout).not.toContain('Export successful. Files written to')
expect(await getFiles()).toEqual([]) expect(await getFiles()).toEqual([])
......
...@@ -23,7 +23,7 @@ describe('Invalid config syntax', () => { ...@@ -23,7 +23,7 @@ describe('Invalid config syntax', () => {
await fs.remove(nextConfigJS) await fs.remove(nextConfigJS)
expect(stderr).toContain( expect(stderr).toContain(
'error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error' '- error Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error'
) )
expect(stderr).toContain('SyntaxError') expect(stderr).toContain('SyntaxError')
}) })
...@@ -44,7 +44,7 @@ describe('Invalid config syntax', () => { ...@@ -44,7 +44,7 @@ describe('Invalid config syntax', () => {
await fs.remove(nextConfigMJS) await fs.remove(nextConfigMJS)
expect(stderr).toContain( expect(stderr).toContain(
'error - Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error' '- error Failed to load next.config.mjs, see more info here https://nextjs.org/docs/messages/next-config-error'
) )
expect(stderr).toContain('SyntaxError') expect(stderr).toContain('SyntaxError')
}) })
......
...@@ -278,7 +278,7 @@ describe.each([ ...@@ -278,7 +278,7 @@ describe.each([
await fetchViaHTTP(nextUrl, '/unhandled-rejection', undefined, { agent }) await fetchViaHTTP(nextUrl, '/unhandled-rejection', undefined, { agent })
await check(() => stderr, /unhandledRejection/) await check(() => stderr, /unhandledRejection/)
expect(stderr).toContain( expect(stderr).toContain(
'error - unhandledRejection: Error: unhandled rejection' '- error unhandledRejection: Error: unhandled rejection'
) )
expect(stderr).toContain('server.js:32:22') expect(stderr).toContain('server.js:32:22')
}) })
......
...@@ -59,7 +59,7 @@ describe('Middleware development errors', () => { ...@@ -59,7 +59,7 @@ describe('Middleware development errors', () => {
await check( await check(
() => stripAnsi(context.logs.output), () => stripAnsi(context.logs.output),
new RegExp( new RegExp(
`error - middleware.js \\(\\d+:\\d+\\) @ Object.default \\[as handler\\]\nerror - boom`, `- error middleware.js \\(\\d+:\\d+\\) @ Object.default \\[as handler\\]\n- error boom`,
'm' 'm'
) )
) )
...@@ -93,7 +93,7 @@ describe('Middleware development errors', () => { ...@@ -93,7 +93,7 @@ describe('Middleware development errors', () => {
await fetchViaHTTP(context.appPort, '/') await fetchViaHTTP(context.appPort, '/')
await check( await check(
() => stripAnsi(context.logs.output), () => stripAnsi(context.logs.output),
new RegExp(`error - unhandledRejection: Error: async boom!`, 'm') new RegExp(`- error unhandledRejection: Error: async boom!`, 'm')
) )
// expect(output).not.toContain( // expect(output).not.toContain(
// 'webpack-internal:///(middleware)/./middleware.js' // 'webpack-internal:///(middleware)/./middleware.js'
...@@ -123,7 +123,7 @@ describe('Middleware development errors', () => { ...@@ -123,7 +123,7 @@ describe('Middleware development errors', () => {
await check( await check(
() => stripAnsi(context.logs.output), () => stripAnsi(context.logs.output),
new RegExp( new RegExp(
`error - middleware.js \\(\\d+:\\d+\\) @ eval\nerror - test is not defined`, `- error middleware.js \\(\\d+:\\d+\\) @ eval\n- error test is not defined`,
'm' 'm'
) )
) )
...@@ -157,7 +157,7 @@ describe('Middleware development errors', () => { ...@@ -157,7 +157,7 @@ describe('Middleware development errors', () => {
await check( await check(
() => stripAnsi(context.logs.output), () => stripAnsi(context.logs.output),
new RegExp( new RegExp(
`error - middleware.js \\(\\d+:\\d+\\) @ <unknown>\nerror - booooom!`, `- error middleware.js \\(\\d+:\\d+\\) @ <unknown>\n- error booooom!`,
'm' 'm'
) )
) )
...@@ -194,7 +194,7 @@ describe('Middleware development errors', () => { ...@@ -194,7 +194,7 @@ describe('Middleware development errors', () => {
await fetchViaHTTP(context.appPort, '/') await fetchViaHTTP(context.appPort, '/')
await check( await check(
() => stripAnsi(context.logs.output), () => stripAnsi(context.logs.output),
new RegExp(`error - unhandledRejection: Error: you shall see me`, 'm') new RegExp(`- error unhandledRejection: Error: you shall see me`, 'm')
) )
// expect(output).not.toContain( // expect(output).not.toContain(
// 'webpack-internal:///(middleware)/./middleware.js' // 'webpack-internal:///(middleware)/./middleware.js'
......
...@@ -20,7 +20,7 @@ describe('svgo-webpack with Image Component', () => { ...@@ -20,7 +20,7 @@ describe('svgo-webpack with Image Component', () => {
const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) const { stderr, code } = await nextBuild(appDir, [], { stderr: true })
const errors = stderr const errors = stderr
.split('\n') .split('\n')
.filter((line) => line && !line.startsWith('warn -')) .filter((line) => line && !line.startsWith('- warn'))
expect(errors).toEqual([]) expect(errors).toEqual([])
expect(code).toBe(0) expect(code).toBe(0)
}) })
...@@ -45,7 +45,7 @@ describe('svgo-webpack with Image Component', () => { ...@@ -45,7 +45,7 @@ describe('svgo-webpack with Image Component', () => {
await renderViaHTTP(appPort, '/', {}) await renderViaHTTP(appPort, '/', {})
const errors = devOutput.stderr const errors = devOutput.stderr
.split('\n') .split('\n')
.filter((line) => line && !line.startsWith('warn -')) .filter((line) => line && !line.startsWith('- warn'))
expect(errors).toEqual([]) expect(errors).toEqual([])
}) })
}) })
......
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