import { describe, expect, it } from 'vitest'; import { cloneBreakpointQueue, isSameBreakpoint, markQueueSkipped, } from '../breakpoints'; import type { BreakpointQueueEntry } from '../breakpoints'; describe('isSameBreakpoint', () => { it('matches identical phase breakpoints', () => { expect( isSameBreakpoint( { id: 'beforeInstall', type: 'phase' }, { id: 'beforeInstall', type: 'phase' }, ), ).toBe(true); }); it('fails when breakpoint types differ', () => { expect( isSameBreakpoint( { id: 'beforeInstall', type: 'phase' }, { id: 'todesktop:beforeInstall', position: 'before', type: 'hook' }, ), ).toBe(false); }); it('considers hook positions', () => { expect( isSameBreakpoint( { id: 'todesktop:beforeBuild', position: 'before', type: 'hook' }, { id: 'todesktop:beforeBuild', position: 'after', type: 'hook' }, ), ).toBe(false); }); it('returns false when either side is undefined', () => { expect( isSameBreakpoint(undefined, { id: 'afterInstall', type: 'phase' }), ).toBe(false); }); }); describe('cloneBreakpointQueue', () => { it('produces a deep copy of the queue', () => { const original: ReadonlyArray = [ { hitAt: undefined, id: 'beforeInstall', type: 'phase' }, { id: 'todesktop:afterPack', position: 'after', skipped: true, type: 'hook', }, ]; const copy = cloneBreakpointQueue(original); expect(copy).toEqual(original); expect(copy).not.toBe(original); expect(copy[0]).not.toBe(original[0]); }); }); describe('markQueueSkipped', () => { it('marks the starting entry as skipped and adds fallback timestamps', () => { const queue: ReadonlyArray = [ { id: 'beforeInstall', type: 'phase' }, { id: 'afterInstall', type: 'phase' }, ]; const fallbackHitAt = '2024-01-01T00:00:00.000Z'; const updated = markQueueSkipped(queue, 0, { fallbackHitAt }); expect(updated[0]).toMatchObject({ hitAt: fallbackHitAt, skipped: true, }); expect(updated[1]).toMatchObject({ skipped: true }); expect(queue[0].skipped).toBeUndefined(); }); it('returns a cloned queue when index is out of bounds', () => { const queue: ReadonlyArray = [ { id: 'beforeInstall', type: 'phase' }, ]; const updated = markQueueSkipped(queue, 2); expect(updated).toEqual(queue); expect(updated).not.toBe(queue); }); });