-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ninth work session; start creating tests
- Loading branch information
1 parent
018d343
commit d564605
Showing
17 changed files
with
647 additions
and
1 deletion.
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
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,107 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { ValidationErrorType } from '../libs/validation' | ||
|
||
import { buildFixture, expectValidationErrorCount, expectValidationErrors } from './utils' | ||
|
||
test('builds with valid English content', async () => { | ||
const { status } = await buildFixture('valid-content') | ||
|
||
expect(status).toBe('success') | ||
}) | ||
|
||
test('builds with valid German content', async () => { | ||
const { status } = await buildFixture('valid-content-de') | ||
|
||
expect(status).toBe('success') | ||
}) | ||
|
||
test('builds with valid French content', async () => { | ||
const { status } = await buildFixture('valid-content-fr') | ||
|
||
expect(status).toBe('success') | ||
}) | ||
|
||
// test('does not build with invalid links', async () => { | ||
// const { output, status } = await buildFixture('invalid-links') | ||
|
||
// expect(status).toBe('error') | ||
|
||
// expectValidationErrorCount(output, 64, 4) | ||
|
||
// expectValidationErrors(output, 'test/', [ | ||
// ['/https://starlight.astro.build/', ValidationErrorType.InvalidLink], | ||
// ['/', ValidationErrorType.InvalidLink], | ||
// ['/unknown', ValidationErrorType.InvalidLink], | ||
// ['/unknown/', ValidationErrorType.InvalidLink], | ||
// ['/unknown#title', ValidationErrorType.InvalidLink], | ||
// ['/unknown/#title', ValidationErrorType.InvalidLink], | ||
// ['/draft', ValidationErrorType.InvalidLink], | ||
// ['/draft/', ValidationErrorType.InvalidLink], | ||
// ['#links', ValidationErrorType.InvalidHash], | ||
// ['/guides/example/#links', ValidationErrorType.InvalidHash], | ||
// ['/icon.svg', ValidationErrorType.InvalidLink], | ||
// ['/guidelines/ui.pdf', ValidationErrorType.InvalidLink], | ||
// ['/unknown-ref', ValidationErrorType.InvalidLink], | ||
// ['#unknown-ref', ValidationErrorType.InvalidHash], | ||
// ['#anotherDiv', ValidationErrorType.InvalidHash], | ||
// ['/guides/page-with-custom-slug', ValidationErrorType.InvalidLink], | ||
// ['/release/@pkg/v0.2.0', ValidationErrorType.InvalidLink], | ||
// ['/?query=string', ValidationErrorType.InvalidLink], | ||
// ['/unknown?query=string', ValidationErrorType.InvalidLink], | ||
// ['/unknown/?query=string', ValidationErrorType.InvalidLink], | ||
// ['/unknown?query=string#title', ValidationErrorType.InvalidLink], | ||
// ['/unknown/?query=string#title', ValidationErrorType.InvalidLink], | ||
// ['?query=string#links', ValidationErrorType.InvalidHash], | ||
// ['/guides/example/?query=string#links', ValidationErrorType.InvalidHash], | ||
// ['/icon.svg?query=string', ValidationErrorType.InvalidLink], | ||
// ['/guidelines/ui.pdf?query=string', ValidationErrorType.InvalidLink], | ||
// ['/unknown-ref?query=string', ValidationErrorType.InvalidLink], | ||
// ['?query=string#unknown-ref', ValidationErrorType.InvalidHash], | ||
// ['http://localhost', ValidationErrorType.LocalLink], | ||
// ['http://localhost:4321/', ValidationErrorType.LocalLink], | ||
// ['https://127.0.0.1:4321/getting-started', ValidationErrorType.LocalLink], | ||
// ]) | ||
|
||
// expectValidationErrors(output, 'guides/example/', [ | ||
// ['#links', ValidationErrorType.InvalidHash], | ||
// ['/unknown/#links', ValidationErrorType.InvalidLink], | ||
// ['/unknown', ValidationErrorType.InvalidLink], | ||
// ['#anotherBlock', ValidationErrorType.InvalidHash], | ||
// ['/icon.svg', ValidationErrorType.InvalidLink], | ||
// ['/guidelines/ui.pdf', ValidationErrorType.InvalidLink], | ||
// ['/linkcard/', ValidationErrorType.InvalidLink], | ||
// ['/linkcard/#links', ValidationErrorType.InvalidLink], | ||
// ['#linkcard', ValidationErrorType.InvalidHash], | ||
// ['/linkbutton/', ValidationErrorType.InvalidLink], | ||
// ['/linkbutton/#links', ValidationErrorType.InvalidLink], | ||
// ['#linkbutton', ValidationErrorType.InvalidHash], | ||
// ['?query=string#links', ValidationErrorType.InvalidHash], | ||
// ['/unknown/?query=string#links', ValidationErrorType.InvalidLink], | ||
// ['/unknown?query=string', ValidationErrorType.InvalidLink], | ||
// ['/icon.svg?query=string', ValidationErrorType.InvalidLink], | ||
// ['/guidelines/ui.pdf?query=string', ValidationErrorType.InvalidLink], | ||
// ['/linkcard/?query=string', ValidationErrorType.InvalidLink], | ||
// ['/linkbutton/?query=string', ValidationErrorType.InvalidLink], | ||
// ]) | ||
|
||
// expectValidationErrors(output, 'guides/namespacetest/', [ | ||
// ['#some-other-content', ValidationErrorType.InvalidHash], | ||
// ['/guides/namespacetest/#another-content', ValidationErrorType.InvalidHash], | ||
// ]) | ||
|
||
// expectValidationErrors(output, 'relative/', [ | ||
// ['.', ValidationErrorType.RelativeLink], | ||
// ['./relative', ValidationErrorType.RelativeLink], | ||
// ['./test', ValidationErrorType.RelativeLink], | ||
// ['./guides/example', ValidationErrorType.RelativeLink], | ||
// ['../test', ValidationErrorType.RelativeLink], | ||
// ['test', ValidationErrorType.RelativeLink], | ||
// ['.?query=string', ValidationErrorType.RelativeLink], | ||
// ['./relative?query=string', ValidationErrorType.RelativeLink], | ||
// ['./test?query=string', ValidationErrorType.RelativeLink], | ||
// ['./guides/example?query=string', ValidationErrorType.RelativeLink], | ||
// ['../test?query=string', ValidationErrorType.RelativeLink], | ||
// ['test?query=string', ValidationErrorType.RelativeLink], | ||
// ]) | ||
// }) |
13 changes: 13 additions & 0 deletions
13
packages/starlight-spell-checker/tests/fixtures/valid-content-de/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,13 @@ | ||
import starlight from "@astrojs/starlight"; | ||
import { defineConfig } from "astro/config"; | ||
import starlightSpellChecker from "starlight-spell-checker"; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
pagefind: false, | ||
plugins: [starlightSpellChecker()], | ||
title: "Starlight Spell Checker Tests - valid content de", | ||
}), | ||
], | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/starlight-spell-checker/tests/fixtures/valid-content-de/package.json
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,10 @@ | ||
{ | ||
"name": "@starlight-spell-checker-tests/valid-content-de", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@astrojs/starlight": "^0.30.2", | ||
"astro": "^5.1.1", | ||
"starlight-spell-checker": "workspace:*" | ||
}, | ||
"private": true | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/starlight-spell-checker/tests/fixtures/valid-content-de/src/content.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,7 @@ | ||
import { docsLoader } from '@astrojs/starlight/loaders' | ||
import { docsSchema } from '@astrojs/starlight/schema' | ||
import { defineCollection } from 'astro:content' | ||
|
||
export const collections = { | ||
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), | ||
} |
5 changes: 5 additions & 0 deletions
5
...arlight-spell-checker/tests/fixtures/valid-content-de/src/content/docs/index.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,5 @@ | ||
--- | ||
title: Verzeichnis | ||
--- | ||
|
||
Die Sonne tauchte unter den Horizont und malte den Himmel in orangefarbenen und rosafarbenen Tönen, während die Abendbrise durch die Bäume rauschte. |
13 changes: 13 additions & 0 deletions
13
packages/starlight-spell-checker/tests/fixtures/valid-content-fr/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,13 @@ | ||
import starlight from "@astrojs/starlight"; | ||
import { defineConfig } from "astro/config"; | ||
import starlightSpellChecker from "starlight-spell-checker"; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
pagefind: false, | ||
plugins: [starlightSpellChecker()], | ||
title: "Starlight Spell Checker Tests - valid content fr", | ||
}), | ||
], | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/starlight-spell-checker/tests/fixtures/valid-content-fr/package.json
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,10 @@ | ||
{ | ||
"name": "@starlight-spell-checker-tests/valid-content-fr", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@astrojs/starlight": "^0.30.2", | ||
"astro": "^5.1.1", | ||
"starlight-spell-checker": "workspace:*" | ||
}, | ||
"private": true | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/starlight-spell-checker/tests/fixtures/valid-content-fr/src/content.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,7 @@ | ||
import { docsLoader } from '@astrojs/starlight/loaders' | ||
import { docsSchema } from '@astrojs/starlight/schema' | ||
import { defineCollection } from 'astro:content' | ||
|
||
export const collections = { | ||
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), | ||
} |
5 changes: 5 additions & 0 deletions
5
...arlight-spell-checker/tests/fixtures/valid-content-fr/src/content/docs/index.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,5 @@ | ||
--- | ||
title: Indice | ||
--- | ||
|
||
Le soleil a plongé sous l'horizon, peignant le ciel dans des teintes orange et roses tandis que la brise du soir murmurait à travers les arbres. |
13 changes: 13 additions & 0 deletions
13
packages/starlight-spell-checker/tests/fixtures/valid-content/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,13 @@ | ||
import starlight from "@astrojs/starlight"; | ||
import { defineConfig } from "astro/config"; | ||
import starlightSpellChecker from "starlight-spell-checker"; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
starlight({ | ||
pagefind: false, | ||
plugins: [starlightSpellChecker()], | ||
title: "Starlight Spell Checker Tests - valid content", | ||
}), | ||
], | ||
}); |
10 changes: 10 additions & 0 deletions
10
packages/starlight-spell-checker/tests/fixtures/valid-content/package.json
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,10 @@ | ||
{ | ||
"name": "@starlight-spell-checker-tests/valid-content", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@astrojs/starlight": "^0.30.2", | ||
"astro": "^5.1.1", | ||
"starlight-spell-checker": "workspace:*" | ||
}, | ||
"private": true | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/starlight-spell-checker/tests/fixtures/valid-content/src/content.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,7 @@ | ||
import { docsLoader } from '@astrojs/starlight/loaders' | ||
import { docsSchema } from '@astrojs/starlight/schema' | ||
import { defineCollection } from 'astro:content' | ||
|
||
export const collections = { | ||
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }), | ||
} |
5 changes: 5 additions & 0 deletions
5
.../starlight-spell-checker/tests/fixtures/valid-content/src/content/docs/index.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,5 @@ | ||
--- | ||
title: Index | ||
--- | ||
|
||
The sun dipped below the horizon, painting the sky in hues of orange and pink as the evening breeze whispered through the trees. |
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,124 @@ | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import { build } from "astro"; | ||
import { expect, vi } from "vitest"; | ||
|
||
import type { ValidationErrorType } from "../libs/validation"; | ||
|
||
export async function buildFixture(name: string) { | ||
const fixturePath = fileURLToPath( | ||
new URL(`fixtures/${name}/`, import.meta.url) | ||
); | ||
|
||
let output = ""; | ||
let status: "success" | "error"; | ||
|
||
function writeOutput(chunk: string | Uint8Array) { | ||
output += String(chunk); | ||
return true; | ||
} | ||
|
||
const stdoutWriteSpy = vi | ||
.spyOn(process.stdout, "write") | ||
.mockImplementation(writeOutput); | ||
const stderrWriteSpy = vi | ||
.spyOn(process.stderr, "write") | ||
.mockImplementation(writeOutput); | ||
|
||
try { | ||
await build({ root: fixturePath }); | ||
status = "success"; | ||
} catch { | ||
status = "error"; | ||
} | ||
|
||
stderrWriteSpy.mockRestore(); | ||
stdoutWriteSpy.mockRestore(); | ||
|
||
return { output, status }; | ||
} | ||
|
||
export function expectValidationWarningCount( | ||
output: string, | ||
count: number, | ||
filesCount: number | ||
) { | ||
expect(output).toMatch( | ||
new RegExp( | ||
`Found ${count} ${ | ||
count === 1 ? "warning" : "warnings" | ||
} in ${filesCount} ${filesCount === 1 ? "file" : "files"}.` | ||
) | ||
); | ||
} | ||
|
||
export function expectValidationWarnings( | ||
output: string, | ||
path: string, | ||
validationWarnings: [ | ||
word: string, | ||
type: ValidationErrorType, | ||
suggestions?: string[] | ||
][] | ||
) { | ||
expect(output).toMatch( | ||
new RegExp(`▶ ${path} | ||
${validationWarnings | ||
.map( | ||
([word, type, suggestions], index) => | ||
`.* ${ | ||
index < validationWarnings.length - 1 ? "├" : "└" | ||
}─ ${word.replaceAll("?", String.raw`\?`)} - ${type}${ | ||
suggestions | ||
? suggestions.length > 0 | ||
? ` \(${suggestions.join(", ")}\)` | ||
: " no suggestions" | ||
: "" | ||
}` | ||
) | ||
.join("\n")}`) | ||
); | ||
} | ||
|
||
export function expectValidationErrorCount( | ||
output: string, | ||
count: number, | ||
filesCount: number | ||
) { | ||
expect(output).toMatch( | ||
new RegExp( | ||
`Found ${count} ${count === 1 ? "error" : "errors"} in ${filesCount} ${ | ||
filesCount === 1 ? "file" : "files" | ||
}.` | ||
) | ||
); | ||
} | ||
|
||
export function expectValidationErrors( | ||
output: string, | ||
path: string, | ||
validationErrors: [ | ||
word: string, | ||
type: ValidationErrorType, | ||
suggestions?: string[] | ||
][] | ||
) { | ||
expect(output).toMatch( | ||
new RegExp(`▶ ${path} | ||
${validationErrors | ||
.map( | ||
([word, type, suggestions], index) => | ||
`.* ${index < validationErrors.length - 1 ? "├" : "└"}─ ${word.replaceAll( | ||
"?", | ||
String.raw`\?` | ||
)} - ${type}${ | ||
suggestions | ||
? suggestions.length > 0 | ||
? ` \(${suggestions.join(", ")}\)` | ||
: " no suggestions" | ||
: "" | ||
}` | ||
) | ||
.join("\n")}`) | ||
); | ||
} |
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,13 @@ | ||
import { defineConfig } from "vitest/config"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
poolOptions: { | ||
forks: { | ||
maxForks: 1, | ||
minForks: 1, | ||
}, | ||
}, | ||
testTimeout: 60_000, | ||
}, | ||
}); |
Oops, something went wrong.