/** * Fase 14.3.6 — guard the version.ts barrel against accidental * tree-shaking / undefined replacement. * * Vitest doesn't run through Vite's `define`, so the `__APP_*` * globals don't exist in this environment. We stub them via * `vi.stubGlobal` to mimic what `vite build` (and `vite dev`) * inject at build/dev time. * * The point of the test is two-fold: * 1. The module re-exports the three globals as an object so * consumers never reach for the `__APP_*` symbols inline. * 2. None of the three exports collapse to `undefined` or the * sentinel `'dev'` when the build-time substitution is * working — that's the canary for an accidental tree-shake * that would silently break the version chip in production. */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; describe('version barrel', () => { beforeEach(() => { vi.resetModules(); vi.stubGlobal('__APP_VERSION__', '1.2.3'); vi.stubGlobal('__APP_COMMIT__', 'abc1234'); vi.stubGlobal('__BUILD_TIME__', '2026-05-18T10:00:00.000Z'); }); afterEach(() => { vi.unstubAllGlobals(); }); it('V-01: exports version / commit / builtAt from the build-time define', async () => { const mod = await import('./version'); expect(mod.version).toBe('1.2.3'); expect(mod.commit).toBe('abc1234'); expect(mod.builtAt).toBe('2026-05-18T10:00:00.000Z'); }); it('V-02: none of the exports are undefined or the "dev" sentinel under a real build define', async () => { const mod = await import('./version'); for (const v of [mod.version, mod.commit, mod.builtAt]) { expect(v).toBeTruthy(); expect(v).not.toBe('dev'); } }); });