diff --git a/packages/next/src/build/output/log.ts b/packages/next/src/build/output/log.ts index eaf63aaac88a8..b62c42316dcc6 100644 --- a/packages/next/src/build/output/log.ts +++ b/packages/next/src/build/output/log.ts @@ -77,12 +77,11 @@ export function trace(...message: any[]) { prefixedLog('trace', ...message) } -const warnOnceCache = new LRUCache(10_000, (message) => message.length) - +const warnOnceCache = new LRUCache(10_000, (value) => value.length) export function warnOnce(...message: any[]) { const key = message.join(' ') if (!warnOnceCache.has(key)) { - warnOnceCache.set(key) + warnOnceCache.set(key, key) warn(...message) } } diff --git a/test/unit/build-output-log.test.ts b/test/unit/build-output-log.test.ts new file mode 100644 index 0000000000000..c30a790fea545 --- /dev/null +++ b/test/unit/build-output-log.test.ts @@ -0,0 +1,27 @@ +import { warnOnce } from 'next/dist/build/output/log' + +describe('build/output/log', () => { + it('warnOnce', () => { + const original = console.warn + try { + const messages = [] + console.warn = (m: any) => messages.push(m) + warnOnce('test') + expect(messages.length).toEqual(1) + warnOnce('test again') + expect(messages.length).toEqual(2) + warnOnce('test', 'more') + expect(messages.length).toEqual(3) + warnOnce('test') + expect(messages.length).toEqual(3) + warnOnce('test again') + expect(messages.length).toEqual(3) + warnOnce('test', 'more') + expect(messages.length).toEqual(3) + warnOnce('test', 'should', 'add', 'another') + expect(messages.length).toEqual(4) + } finally { + console.warn = original + } + }) +})