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