|
| 1 | +import { describe, expect, it, beforeAll } from 'vitest'; |
| 2 | +import { discoverVersions, getStarlightVersions } from '../version-discovery.mjs'; |
| 3 | +import * as semver from 'semver'; |
| 4 | + |
| 5 | +describe('Version Discovery', () => { |
| 6 | + let coreRepoPath; |
| 7 | + |
| 8 | + beforeAll(() => { |
| 9 | + coreRepoPath = process.env.CORE || process.env.PEPR_CORE_PATH; |
| 10 | + }); |
| 11 | + |
| 12 | + describe('discoverVersions', () => { |
| 13 | + it('should return versions and retired arrays', async () => { |
| 14 | + if (!coreRepoPath) { |
| 15 | + console.log('Skipping test: No CORE repository path provided'); |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + const result = await discoverVersions(coreRepoPath, 2); |
| 20 | + expect(result).toHaveProperty('versions'); |
| 21 | + expect(result).toHaveProperty('retired'); |
| 22 | + expect(Array.isArray(result.versions)).toBe(true); |
| 23 | + expect(Array.isArray(result.retired)).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should include "latest" in versions', async () => { |
| 27 | + if (!coreRepoPath) { |
| 28 | + console.log('Skipping test: No CORE repository path provided'); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + const { versions } = await discoverVersions(coreRepoPath, 2); |
| 33 | + expect(versions).toContain('latest'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should respect cutoff parameter', async () => { |
| 37 | + if (!coreRepoPath) { |
| 38 | + console.log('Skipping test: No CORE repository path provided'); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + const cutoff = 2; |
| 43 | + const { versions } = await discoverVersions(coreRepoPath, cutoff); |
| 44 | + const versionCount = versions.filter(v => v !== 'latest').length; |
| 45 | + expect(versionCount).toBe(cutoff); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should return major.minor format for retired versions', async () => { |
| 49 | + if (!coreRepoPath) { |
| 50 | + console.log('Skipping test: No CORE repository path provided'); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + const { retired } = await discoverVersions(coreRepoPath, 2); |
| 55 | + retired.forEach(version => { |
| 56 | + expect(version).toMatch(/^\d+\.\d+$/); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should return full semver for active versions', async () => { |
| 61 | + if (!coreRepoPath) { |
| 62 | + console.log('Skipping test: No CORE repository path provided'); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + const { versions } = await discoverVersions(coreRepoPath, 2); |
| 67 | + const semverVersions = versions.filter(v => v !== 'latest'); |
| 68 | + semverVersions.forEach(version => { |
| 69 | + expect(version).toMatch(/^v?\d+\.\d+\.\d+/); |
| 70 | + }); |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('getStarlightVersions', () => { |
| 75 | + it('should format versions with major.minor slugs', async () => { |
| 76 | + if (!coreRepoPath) { |
| 77 | + console.log('Skipping test: No CORE repository path provided'); |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 82 | + starlightVersions.forEach(v => { |
| 83 | + expect(v).toHaveProperty('slug'); |
| 84 | + expect(v).toHaveProperty('label'); |
| 85 | + expect(v.slug).toMatch(/^v\d+\.\d+$/); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should not include "latest" in starlight versions', async () => { |
| 90 | + if (!coreRepoPath) { |
| 91 | + console.log('Skipping test: No CORE repository path provided'); |
| 92 | + return; |
| 93 | + } |
| 94 | + |
| 95 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 96 | + const hasLatest = starlightVersions.some(v => |
| 97 | + v.slug === 'latest' || v.label === 'latest' |
| 98 | + ); |
| 99 | + expect(hasLatest).toBe(false); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should use full version for label', async () => { |
| 103 | + if (!coreRepoPath) { |
| 104 | + console.log('Skipping test: No CORE repository path provided'); |
| 105 | + return; |
| 106 | + } |
| 107 | + |
| 108 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 109 | + starlightVersions.forEach(v => { |
| 110 | + expect(v.label).toMatch(/^v?\d+\.\d+\.\d+/); |
| 111 | + }); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should filter out prerelease versions', async () => { |
| 115 | + if (!coreRepoPath) { |
| 116 | + console.log('Skipping test: No CORE repository path provided'); |
| 117 | + return; |
| 118 | + } |
| 119 | + |
| 120 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 121 | + starlightVersions.forEach(v => { |
| 122 | + expect(semver.prerelease(v.label)).toBeNull(); |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + it('should return array of version objects', async () => { |
| 127 | + if (!coreRepoPath) { |
| 128 | + console.log('Skipping test: No CORE repository path provided'); |
| 129 | + return; |
| 130 | + } |
| 131 | + |
| 132 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 133 | + expect(Array.isArray(starlightVersions)).toBe(true); |
| 134 | + expect(starlightVersions.length).toBeGreaterThan(0); |
| 135 | + }); |
| 136 | + |
| 137 | + it('should maintain consistency between slug and label major.minor', async () => { |
| 138 | + if (!coreRepoPath) { |
| 139 | + console.log('Skipping test: No CORE repository path provided'); |
| 140 | + return; |
| 141 | + } |
| 142 | + |
| 143 | + const starlightVersions = await getStarlightVersions(coreRepoPath, 2); |
| 144 | + starlightVersions.forEach(v => { |
| 145 | + const slugMajMin = v.slug.match(/(\d+\.\d+)/)?.[1]; |
| 146 | + const labelMajMin = v.label.match(/(\d+\.\d+)/)?.[1]; |
| 147 | + expect(slugMajMin).toBe(labelMajMin); |
| 148 | + }); |
| 149 | + }); |
| 150 | + }); |
| 151 | +}); |
0 commit comments