-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent validation issues when using the
trailingSlash
option …
…set to `never`
- Loading branch information
Showing
9 changed files
with
125 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
export function ensureTrailingSlash(path: string): string { | ||
return path.endsWith('/') ? path : `${path}/` | ||
} |
This file contains 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
14 changes: 14 additions & 0 deletions
14
packages/starlight-links-validator/tests/fixtures/trailing-always/astro.config.ts
This file contains 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,14 @@ | ||
import starlight from '@astrojs/starlight' | ||
import { defineConfig } from 'astro/config' | ||
|
||
import starlightLinksValidator from '../..' | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
plugins: [starlightLinksValidator()], | ||
title: 'Starlight Links Validator Tests - trailing always', | ||
}), | ||
], | ||
trailingSlash: 'always', | ||
}) |
7 changes: 7 additions & 0 deletions
7
...nks-validator/tests/fixtures/trailing-always/src/content/docs/guides/example.md
This file contains 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,7 @@ | ||
--- | ||
title: Example | ||
--- | ||
|
||
## Description | ||
|
||
This is an example page. |
19 changes: 19 additions & 0 deletions
19
...arlight-links-validator/tests/fixtures/trailing-always/src/content/docs/test.md
This file contains 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,19 @@ | ||
--- | ||
title: Test | ||
--- | ||
|
||
# Some links | ||
|
||
- [External link](https://starlight.astro.build/) | ||
|
||
- [Example page](/guides/example) | ||
- [Example page](/guides/example/) | ||
|
||
- [Example page with hash](/guides/example#description) | ||
- [Example page with hash](/guides/example/#description) | ||
|
||
- [Unknown page](/unknown) | ||
- [Unknown page](/unknown/) | ||
|
||
- [Example page with unknown hash](/guides/example#unknown) | ||
- [Example page with unknown hash](/guides/example/#unknown) |
14 changes: 14 additions & 0 deletions
14
packages/starlight-links-validator/tests/fixtures/trailing-never/astro.config.ts
This file contains 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,14 @@ | ||
import starlight from '@astrojs/starlight' | ||
import { defineConfig } from 'astro/config' | ||
|
||
import starlightLinksValidator from '../..' | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
plugins: [starlightLinksValidator()], | ||
title: 'Starlight Links Validator Tests - trailing never', | ||
}), | ||
], | ||
trailingSlash: 'never', | ||
}) |
7 changes: 7 additions & 0 deletions
7
...inks-validator/tests/fixtures/trailing-never/src/content/docs/guides/example.md
This file contains 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,7 @@ | ||
--- | ||
title: Example | ||
--- | ||
|
||
## Description | ||
|
||
This is an example page. |
19 changes: 19 additions & 0 deletions
19
...tarlight-links-validator/tests/fixtures/trailing-never/src/content/docs/test.md
This file contains 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,19 @@ | ||
--- | ||
title: Test | ||
--- | ||
|
||
# Some links | ||
|
||
- [External link](https://starlight.astro.build/) | ||
|
||
- [Example page](/guides/example) | ||
- [Example page](/guides/example/) | ||
|
||
- [Example page with hash](/guides/example#description) | ||
- [Example page with hash](/guides/example/#description) | ||
|
||
- [Unknown page](/unknown) | ||
- [Unknown page](/unknown/) | ||
|
||
- [Example page with unknown hash](/guides/example#unknown) | ||
- [Example page with unknown hash](/guides/example/#unknown) |
This file contains 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,39 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { loadFixture } from './utils' | ||
|
||
test('should validate links when the `trailingSlash` option is set to `never`', async () => { | ||
expect.assertions(2) | ||
|
||
try { | ||
await loadFixture('trailing-never') | ||
} catch (error) { | ||
expect(error).toMatch(/Found 4 invalid links in 1 file./) | ||
|
||
expect(error).toMatch( | ||
new RegExp(`▶ test/ | ||
├─ /unknown | ||
├─ /unknown/ | ||
├─ /guides/example#unknown | ||
└─ /guides/example/#unknown`), | ||
) | ||
} | ||
}) | ||
|
||
test('should validate links when the `trailingSlash` option is set to `always`', async () => { | ||
expect.assertions(2) | ||
|
||
try { | ||
await loadFixture('trailing-always') | ||
} catch (error) { | ||
expect(error).toMatch(/Found 4 invalid links in 1 file./) | ||
|
||
expect(error).toMatch( | ||
new RegExp(`▶ test/ | ||
├─ /unknown | ||
├─ /unknown/ | ||
├─ /guides/example#unknown | ||
└─ /guides/example/#unknown`), | ||
) | ||
} | ||
}) |