-
Notifications
You must be signed in to change notification settings - Fork 1
51 improve redirects #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| const projectRoot = path.resolve(import.meta.dirname, '../..'); | ||
| const netlifyRedirectsPath = path.join(projectRoot, 'public/_redirects'); | ||
|
|
||
| async function getNetlifyRedirectsContent() { | ||
| return await fs.readFile(netlifyRedirectsPath, 'utf8'); | ||
| } | ||
|
|
||
| describe('Netlify _redirects File', () => { | ||
| const testCases = [ | ||
| { name: 'should be auto-generated with warnings', expected: 'Auto-generated' }, | ||
| { name: 'should use Netlify splat redirects with 301', expected: '/:splat 301' }, | ||
| ]; | ||
|
|
||
| it.each(testCases)('$name', async ({ expected }) => { | ||
| const content = await getNetlifyRedirectsContent(); | ||
| expect(content).toContain(expected); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import * as fs from 'node:fs/promises'; | ||
| import * as path from 'node:path'; | ||
|
|
||
| const projectRoot = path.resolve(import.meta.dirname, '../..'); | ||
| const retiredRedirectsPath = path.join(projectRoot, 'retired-redirects.js'); | ||
|
|
||
| async function getRetiredRedirectsContent() { | ||
| return await fs.readFile(retiredRedirectsPath, 'utf8'); | ||
| } | ||
|
|
||
| describe('Retired Version Redirects Generation', () => { | ||
| const testCases = [ | ||
| { name: 'should export retiredVersionRedirects', expected: 'export const retiredVersionRedirects' }, | ||
| { name: 'should export retiredVersions', expected: 'export const retiredVersions' }, | ||
| { name: 'should use wildcard redirects to root', expected: '/:path*' }, | ||
| { name: 'should be auto-generated', expected: 'Auto-generated' }, | ||
| ]; | ||
samayer12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| it.each(testCases)('$name', async ({ expected }) => { | ||
| const content = await getRetiredRedirectsContent(); | ||
| expect(content).toContain(expected); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { describe, expect, it, beforeAll } from 'vitest'; | ||
| import { discoverVersions, getStarlightVersions } from '../version-discovery.mjs'; | ||
| import * as semver from 'semver'; | ||
|
|
||
| describe('Version Discovery', () => { | ||
| let coreRepoPath; | ||
|
|
||
| beforeAll(() => { | ||
| coreRepoPath = process.env.CORE || process.env.PEPR_CORE_PATH; | ||
samayer12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| describe('discoverVersions', () => { | ||
| it('should return versions and retired arrays', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const result = await discoverVersions(coreRepoPath, 2); | ||
| expect(result).toHaveProperty('versions'); | ||
| expect(result).toHaveProperty('retired'); | ||
| expect(Array.isArray(result.versions)).toBe(true); | ||
| expect(Array.isArray(result.retired)).toBe(true); | ||
| }); | ||
|
|
||
| it('should include "latest" in versions', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const { versions } = await discoverVersions(coreRepoPath, 2); | ||
| expect(versions).toContain('latest'); | ||
| }); | ||
|
|
||
| it('should respect cutoff parameter', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const cutoff = 2; | ||
| const { versions } = await discoverVersions(coreRepoPath, cutoff); | ||
| const versionCount = versions.filter(v => v !== 'latest').length; | ||
| expect(versionCount).toBe(cutoff); | ||
| }); | ||
|
|
||
| it('should return major.minor format for retired versions', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const { retired } = await discoverVersions(coreRepoPath, 2); | ||
| retired.forEach(version => { | ||
| expect(version).toMatch(/^\d+\.\d+$/); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return full semver for active versions', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const { versions } = await discoverVersions(coreRepoPath, 2); | ||
| const semverVersions = versions.filter(v => v !== 'latest'); | ||
| semverVersions.forEach(version => { | ||
| expect(version).toMatch(/^v?\d+\.\d+\.\d+/); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getStarlightVersions', () => { | ||
| it('should format versions with major.minor slugs', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| starlightVersions.forEach(v => { | ||
| expect(v).toHaveProperty('slug'); | ||
| expect(v).toHaveProperty('label'); | ||
| expect(v.slug).toMatch(/^v\d+\.\d+$/); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not include "latest" in starlight versions', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| const hasLatest = starlightVersions.some(v => | ||
| v.slug === 'latest' || v.label === 'latest' | ||
| ); | ||
| expect(hasLatest).toBe(false); | ||
| }); | ||
|
|
||
| it('should use full version for label', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| starlightVersions.forEach(v => { | ||
| expect(v.label).toMatch(/^v?\d+\.\d+\.\d+/); | ||
| }); | ||
| }); | ||
|
|
||
| it('should filter out prerelease versions', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| starlightVersions.forEach(v => { | ||
| expect(semver.prerelease(v.label)).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return array of version objects', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| expect(Array.isArray(starlightVersions)).toBe(true); | ||
| expect(starlightVersions.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('should maintain consistency between slug and label major.minor', async () => { | ||
| if (!coreRepoPath) { | ||
| console.log('Skipping test: No CORE repository path provided'); | ||
| return; | ||
| } | ||
|
|
||
| const starlightVersions = await getStarlightVersions(coreRepoPath, 2); | ||
| starlightVersions.forEach(v => { | ||
| const slugMajMin = v.slug.match(/(\d+\.\d+)/)?.[1]; | ||
| const labelMajMin = v.label.match(/(\d+\.\d+)/)?.[1]; | ||
| expect(slugMajMin).toBe(labelMajMin); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.