Skip to content

Commit

Permalink
assert log.warn prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Oct 28, 2024
1 parent 0781afe commit 6af8b2a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/unit/warn-removed-experimental-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ import {
warnOptionHasBeenMovedOutOfExperimental,
warnOptionHasBeenDeprecated,
} from 'next/dist/server/config'
import stripAnsi from 'strip-ansi'

describe('warnOptionHasBeenMovedOutOfExperimental', () => {
let spy: jest.SpyInstance
beforeAll(() => {
spy = jest.spyOn(console, 'warn').mockImplementation(() => {})
spy = jest.spyOn(console, 'warn').mockImplementation((...args) => {
const [prefix, ...restArgs] = args
const formattedFirstArg = stripAnsi(prefix)
// pass the rest of the arguments to the spied console.warn
// @ts-expect-error accessing the mocked console.warn
console.warn.mock.calls.push([formattedFirstArg, ...restArgs])
})
})

it('should not log warning message without experimental config', () => {
Expand Down Expand Up @@ -46,7 +53,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {

expect(spy).toHaveBeenCalledWith(
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.'
)
)
})
Expand All @@ -66,7 +73,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {

expect(spy).toHaveBeenCalledWith(
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.'
)
)
})
Expand Down Expand Up @@ -124,7 +131,7 @@ describe('warnOptionHasBeenMovedOutOfExperimental', () => {

expect(spy).toHaveBeenCalledWith(
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.'
)
)
})
Expand Down

0 comments on commit 6af8b2a

Please sign in to comment.