From 25ef5a4a8b83a08d7bc52b0f0047c12e28e38626 Mon Sep 17 00:00:00 2001 From: gonzaloriestra <14979109+gonzaloriestra@users.noreply.github.com> Date: Thu, 10 Sep 2026 00:31:31 +0000 Subject: [PATCH] [Tests] Add unit tests for deprecations store Adds comprehensive unit test coverage for `deprecations-store.ts` in `packages/cli-kit/src/private/node/context/deprecations-store.test.ts`. Covers initial state, empty array inputs, past dates, single future dates, updating vs preserving stored deprecation dates, and unsorted date arrays. --- .../node/context/deprecations-store.test.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 packages/cli-kit/src/private/node/context/deprecations-store.test.ts diff --git a/packages/cli-kit/src/private/node/context/deprecations-store.test.ts b/packages/cli-kit/src/private/node/context/deprecations-store.test.ts new file mode 100644 index 00000000000..0b5c3a237f3 --- /dev/null +++ b/packages/cli-kit/src/private/node/context/deprecations-store.test.ts @@ -0,0 +1,88 @@ +import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest' + +describe('deprecations-store', () => { + beforeEach(() => { + vi.resetModules() + vi.useFakeTimers() + }) + + afterEach(() => { + vi.useRealTimers() + }) + + test('getNextDeprecationDate initially returns undefined', async () => { + const {getNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + expect(getNextDeprecationDate()).toBeUndefined() + }) + + test('setNextDeprecationDate with empty array does not set deprecation date', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + setNextDeprecationDate([]) + expect(getNextDeprecationDate()).toBeUndefined() + }) + + test('setNextDeprecationDate with past dates does not set deprecation date', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 15)) + + const pastDate = new Date(2025, 0, 1) + setNextDeprecationDate([pastDate]) + + expect(getNextDeprecationDate()).toBeUndefined() + }) + + test('setNextDeprecationDate with a future date sets the deprecation date', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + const futureDate = new Date(2025, 0, 10) + setNextDeprecationDate([futureDate]) + + expect(getNextDeprecationDate()).toEqual(futureDate) + }) + + test('setNextDeprecationDate updates if a new future date is earlier than stored date', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + const laterFutureDate = new Date(2025, 0, 20) + const earlierFutureDate = new Date(2025, 0, 10) + + setNextDeprecationDate([laterFutureDate]) + expect(getNextDeprecationDate()).toEqual(laterFutureDate) + + setNextDeprecationDate([earlierFutureDate]) + expect(getNextDeprecationDate()).toEqual(earlierFutureDate) + }) + + test('setNextDeprecationDate preserves existing date if new future date is later', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + const earlierFutureDate = new Date(2025, 0, 10) + const laterFutureDate = new Date(2025, 0, 20) + + setNextDeprecationDate([earlierFutureDate]) + expect(getNextDeprecationDate()).toEqual(earlierFutureDate) + + setNextDeprecationDate([laterFutureDate]) + expect(getNextDeprecationDate()).toEqual(earlierFutureDate) + }) + + test('setNextDeprecationDate selects earliest date when given multiple unsorted future dates', async () => { + const {getNextDeprecationDate, setNextDeprecationDate} = await import('./deprecations-store.js') + vi.setSystemTime(new Date(2025, 0, 1)) + + const futureDate1 = new Date(2025, 0, 30) + const futureDate2 = new Date(2025, 0, 10) + const futureDate3 = new Date(2025, 0, 20) + + setNextDeprecationDate([futureDate1, futureDate2, futureDate3]) + + expect(getNextDeprecationDate()).toEqual(futureDate2) + }) +})