|
| 1 | +/** |
| 2 | + * Verify that the vite-plus/versions export works correctly. |
| 3 | + * |
| 4 | + * Tests run against the already-built dist/ directory, ensuring |
| 5 | + * that syncVersionsExport() produces correct artifacts. |
| 6 | + */ |
| 7 | +import fs from 'node:fs'; |
| 8 | +import path from 'node:path'; |
| 9 | +import url from 'node:url'; |
| 10 | + |
| 11 | +import { describe, expect, it } from '@voidzero-dev/vite-plus-test'; |
| 12 | + |
| 13 | +const cliPkgDir = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '../..'); |
| 14 | +const distDir = path.join(cliPkgDir, 'dist'); |
| 15 | +const corePkgPath = path.join(cliPkgDir, '../core/package.json'); |
| 16 | +const testPkgPath = path.join(cliPkgDir, '../test/package.json'); |
| 17 | + |
| 18 | +describe('versions export', () => { |
| 19 | + describe('build artifacts', () => { |
| 20 | + it('dist/versions.js should exist', () => { |
| 21 | + expect(fs.existsSync(path.join(distDir, 'versions.js'))).toBe(true); |
| 22 | + }); |
| 23 | + |
| 24 | + it('dist/versions.d.ts should exist', () => { |
| 25 | + expect(fs.existsSync(path.join(distDir, 'versions.d.ts'))).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it('dist/versions.js should export a versions object', () => { |
| 29 | + const content = fs.readFileSync(path.join(distDir, 'versions.js'), 'utf-8'); |
| 30 | + expect(content).toContain('export const versions'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('dist/versions.d.ts should declare a versions type', () => { |
| 34 | + const content = fs.readFileSync(path.join(distDir, 'versions.d.ts'), 'utf-8'); |
| 35 | + expect(content).toContain('export declare const versions'); |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + describe('bundledVersions consistency', () => { |
| 40 | + it('should contain all core bundledVersions', async () => { |
| 41 | + const corePkg = JSON.parse(fs.readFileSync(corePkgPath, 'utf-8')); |
| 42 | + const mod = await import('../../dist/versions.js'); |
| 43 | + const versions = mod.versions as Record<string, string>; |
| 44 | + for (const [key, value] of Object.entries( |
| 45 | + corePkg.bundledVersions as Record<string, string>, |
| 46 | + )) { |
| 47 | + expect(versions[key], `versions.${key} should match core bundledVersions`).toBe(value); |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + it('should contain all test bundledVersions', async () => { |
| 52 | + const testPkg = JSON.parse(fs.readFileSync(testPkgPath, 'utf-8')); |
| 53 | + const mod = await import('../../dist/versions.js'); |
| 54 | + const versions = mod.versions as Record<string, string>; |
| 55 | + for (const [key, value] of Object.entries( |
| 56 | + testPkg.bundledVersions as Record<string, string>, |
| 57 | + )) { |
| 58 | + expect(versions[key], `versions.${key} should match test bundledVersions`).toBe(value); |
| 59 | + } |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe('dependency tool versions', () => { |
| 64 | + it('should contain oxlint version', async () => { |
| 65 | + const mod = await import('../../dist/versions.js'); |
| 66 | + const versions = mod.versions as Record<string, string>; |
| 67 | + expect(versions.oxlint).toBeTypeOf('string'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should contain oxfmt version', async () => { |
| 71 | + const mod = await import('../../dist/versions.js'); |
| 72 | + const versions = mod.versions as Record<string, string>; |
| 73 | + expect(versions.oxfmt).toBeTypeOf('string'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should contain oxlint-tsgolint version', async () => { |
| 77 | + const mod = await import('../../dist/versions.js'); |
| 78 | + const versions = mod.versions as Record<string, string>; |
| 79 | + expect(versions['oxlint-tsgolint']).toBeTypeOf('string'); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('type declarations', () => { |
| 84 | + it('should have type fields for all bundled tools', () => { |
| 85 | + const content = fs.readFileSync(path.join(distDir, 'versions.d.ts'), 'utf-8'); |
| 86 | + const expectedKeys = [ |
| 87 | + 'vite', |
| 88 | + 'rolldown', |
| 89 | + 'tsdown', |
| 90 | + 'vitest', |
| 91 | + 'oxlint', |
| 92 | + 'oxfmt', |
| 93 | + 'oxlint-tsgolint', |
| 94 | + ]; |
| 95 | + for (const key of expectedKeys) { |
| 96 | + expect(content).toContain(key); |
| 97 | + } |
| 98 | + }); |
| 99 | + |
| 100 | + it('should declare all fields as readonly string', () => { |
| 101 | + const content = fs.readFileSync(path.join(distDir, 'versions.d.ts'), 'utf-8'); |
| 102 | + const fieldMatches = content.match(/readonly [\w'-]+: string;/g); |
| 103 | + expect(fieldMatches).not.toBeNull(); |
| 104 | + expect(fieldMatches!.length).toBeGreaterThanOrEqual(7); |
| 105 | + }); |
| 106 | + }); |
| 107 | + |
| 108 | + describe('runtime import', () => { |
| 109 | + it('should be importable and return an object with expected keys', async () => { |
| 110 | + const { versions } = await import('../../dist/versions.js'); |
| 111 | + expect(versions).toBeDefined(); |
| 112 | + expect(typeof versions).toBe('object'); |
| 113 | + expect(versions.vite).toBeTypeOf('string'); |
| 114 | + expect(versions.rolldown).toBeTypeOf('string'); |
| 115 | + expect(versions.tsdown).toBeTypeOf('string'); |
| 116 | + expect(versions.vitest).toBeTypeOf('string'); |
| 117 | + expect(versions.oxlint).toBeTypeOf('string'); |
| 118 | + expect(versions.oxfmt).toBeTypeOf('string'); |
| 119 | + expect(versions['oxlint-tsgolint']).toBeTypeOf('string'); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should have valid semver-like versions', async () => { |
| 123 | + const { versions } = await import('../../dist/versions.js'); |
| 124 | + const semverPattern = /^\d+\.\d+\.\d+/; |
| 125 | + for (const [key, value] of Object.entries(versions as Record<string, string>)) { |
| 126 | + expect(value, `${key} should be a valid version`).toMatch(semverPattern); |
| 127 | + } |
| 128 | + }); |
| 129 | + }); |
| 130 | +}); |
0 commit comments