From 6af8b2a994f8fd5e0755ac54c04a65ca9a503394 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Mon, 28 Oct 2024 22:44:05 +0100 Subject: [PATCH] assert log.warn prefix --- .../unit/warn-removed-experimental-config.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/unit/warn-removed-experimental-config.test.ts b/test/unit/warn-removed-experimental-config.test.ts index 8d86530c2b0f6..e7cfc2924d78f 100644 --- a/test/unit/warn-removed-experimental-config.test.ts +++ b/test/unit/warn-removed-experimental-config.test.ts @@ -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', () => { @@ -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.' ) ) }) @@ -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.' ) ) }) @@ -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.' ) ) })