Commit a49c479a authored by RobPruzan's avatar RobPruzan Committed by Jiachi Liu

don't log browser console in terminal during test mode

parent c8ee24d8
import { UNDEFINED_MARKER } from '../../shared/forward-logs-shared'
import { UNDEFINED_MARKER } from '../../shared/log-patch'
import {
preLogSerializationClone,
PROMISE_MARKER,
......
......@@ -16,7 +16,7 @@ import {
type LogMethod,
patchConsoleMethod,
UNDEFINED_MARKER,
} from '../../shared/forward-logs-shared'
} from '../../shared/log-patch'
const terminalLoggingConfig = getTerminalLoggingConfig()
export const PROMISE_MARKER = 'Promise {}'
......
......@@ -12,7 +12,7 @@ import {
type LogMethod,
type ConsoleEntry,
UNDEFINED_MARKER,
} from '../../../next-devtools/shared/forward-logs-shared'
} from '../../../next-devtools/shared/log-patch'
import type { NextConfigComplete } from '../../config-shared'
export function getDisplayedSourceLocation(
......@@ -68,8 +68,14 @@ const forwardConsole: typeof console = {
...Object.fromEntries(
methods.map((method) => [
method,
(...args: Array<any>) =>
(console[method] as any)(
(...args: Array<any>) => {
if (
process.env.__NEXT_TEST_MODE &&
!process.env.NEXT_TEST_BROWSER_LOGS
) {
return
}
return (console[method] as any)(
...args.map((arg) =>
methodsToSkipInspect.has(method) ||
typeof arg !== 'object' ||
......@@ -78,7 +84,8 @@ const forwardConsole: typeof console = {
: // we hardcode depth:Infinity to allow the true depth to be configured by the serialization done in the browser (which is controlled by user)
util.inspect(arg, { depth: Infinity, colors: true })
)
),
)
},
])
),
}
......
......@@ -40,6 +40,21 @@ function setupLogCapture() {
}
describe(`Terminal Logging (${bundlerName})`, () => {
let originalBrowserLogsEnv: string | undefined
beforeAll(() => {
originalBrowserLogsEnv = process.env.NEXT_TEST_BROWSER_LOGS
process.env.NEXT_TEST_BROWSER_LOGS = 'true'
})
afterAll(() => {
if (originalBrowserLogsEnv === undefined) {
delete process.env.NEXT_TEST_BROWSER_LOGS
} else {
process.env.NEXT_TEST_BROWSER_LOGS = originalBrowserLogsEnv
}
})
describe('Pages Router', () => {
let next: NextInstance
let logs: string[] = []
......
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