FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ci: run the site's unit tests · unjs/unifont@d7ae8c4 · GitHub

/ unifont Public

Commit d7ae8c4

Browse files
committed
ci: run the site's unit tests
1 parent fda903c commit d7ae8c4

11 files changed

Lines changed: 44 additions & 26 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ jobs:
5555
env:
5656
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5757

58+
- name: 🧪 Test site
59+
run: pnpm --filter unifont-site test
60+
61+
- name: 🔍 Typecheck site
62+
run: pnpm --filter unifont-site test:types
63+
5864
a11y:
5965
runs-on: ubuntu-latest
6066

@@ -70,10 +76,10 @@ jobs:
7076
run: pnpm install
7177

7278
- name: 🎭 Install Chromium
73-
run: pnpm --filter docs exec playwright install --with-deps chromium
79+
run: pnpm --filter unifont-site exec playwright install --with-deps chromium
7480

7581
- name: ♿ Accessibility
76-
run: pnpm --filter docs test:a11y
82+
run: pnpm --filter unifont-site test:a11y
7783

7884
- name: 📄 Upload report
7985
if: failure()

‎docs/nuxt.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ export default defineNuxtConfig({
229229
// The content pages and the endpoints behind them, so no request has to read markdown from a
230230
// filesystem a serverless deployment does not have.
231231
'prerender:routes': async ({ routes }) => {
232-
const { content } = await import('./server/utils/content.ts')
232+
const { fsContent } = await import('./server/utils/content-fs.ts')
233233
const pages = new Set(proseRoutes)
234-
const paths = (await content.list()).map((file: { path: string }) => file.path)
234+
const paths = (await fsContent().list()).map((file: { path: string }) => file.path)
235235
for (const path of paths) {
236236
routes.add(path)
237237
// Each endpoint is prerendered to a file, so `/docs`, which is also the parent of every

‎docs/server/middleware/markdown.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineEventHandler(async (event) => {
1919
return
2020
}
2121

22-
const origin = useRuntimeConfig(event).public.siteUrl || url.origin
22+
const origin = useRuntimeConfig().public.siteUrl || url.origin
2323
const source = await markdownForPath(path, origin)
2424
if (!source) {
2525
return

‎docs/server/plugins/markdown-negotiation.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { H3Event } from 'nitro/h3'
12
import { definePlugin } from 'nitro'
23
import { markdownPath, prefersMarkdown } from '#server/utils/negotiation'
34

@@ -12,16 +13,20 @@ export default definePlugin((nitro) => {
1213
return
1314
}
1415

15-
const twin = markdownPath(event.url.pathname)
16+
// Nitro types the hook with the minimal `HTTPEvent`, the request and nothing else. What it
17+
// dispatches is an `H3Event`, whose `url` is the one routing and the static handler read.
18+
const { url, res } = event as H3Event
19+
20+
const twin = markdownPath(url.pathname)
1621
if (!twin) {
1722
return
1823
}
1924

2025
// On the HTML variant too: a shared cache must not serve it to a client asking for markdown.
21-
event.res.headers.set('vary', 'Accept, Accept-Encoding')
26+
res.headers.set('vary', 'Accept, Accept-Encoding')
2227

2328
if (prefersMarkdown(event.req.headers.get('accept'))) {
24-
event.url.pathname = twin
29+
url.pathname = twin
2530
}
2631
})
2732
})

‎docs/server/routes/llms-full.txt.get.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { listMarkdownSources, renderMarkdown } from '../utils/markdown'
44

55
/** Every prose page on the site, concatenated into one request. */
66
export default defineEventHandler(async (event) => {
7-
const origin = (useRuntimeConfig(event).public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
7+
const origin = (useRuntimeConfig().public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
88
const sources = await listMarkdownSources(origin)
99

1010
const body = sources

‎docs/server/routes/llms.txt.get.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { listDocs, listPages } from '../utils/markdown'
77
* blockquote summary, prose, then H2 sections of annotated links.
88
*/
99
export default defineEventHandler(async (event) => {
10-
const origin = (useRuntimeConfig(event).public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
10+
const origin = (useRuntimeConfig().public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
1111
const url = (path: string) => `${origin}${path}`
1212

1313
const docs = await listDocs()

‎docs/server/routes/openapi.json.get.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { openApiDocument } from '../utils/openapi'
44

55
/** The OpenAPI description of the public API. Mirrored at `/api/openapi.json`. */
66
export default defineEventHandler((event) => {
7-
const origin = useRuntimeConfig(event).public.siteUrl || getRequestURL(event).origin
7+
const origin = useRuntimeConfig().public.siteUrl || getRequestURL(event).origin
88

99
event.res.headers.set('content-type', 'application/json; charset=utf-8')
1010
event.res.headers.set('cache-control', 'public, max-age=3600, stale-while-revalidate=86400')

‎docs/server/routes/robots.txt.get.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useRuntimeConfig } from 'nitro/runtime-config'
33

44
/** Everything here is public; the file exists to point at the machine-readable indexes. */
55
export default defineEventHandler((event) => {
6-
const origin = (useRuntimeConfig(event).public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
6+
const origin = (useRuntimeConfig().public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
77

88
event.res.headers.set('content-type', 'text/plain; charset=utf-8')
99
event.res.headers.set('cache-control', 'public, max-age=86400')

‎docs/server/routes/sitemap.xml.get.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const escape = (value: string) =>
1414

1515
/** Every indexable URL. A family page costs a provider lookup, so only the featured ones are listed. */
1616
export default defineEventHandler(async (event) => {
17-
const config = useRuntimeConfig(event)
17+
const config = useRuntimeConfig()
1818
const origin = (config.public.siteUrl || getRequestURL(event).origin).replace(/\/+$/, '')
1919
const lastmod = config.buildTime || new Date().toISOString()
2020

‎docs/server/utils/content-fs.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { comarkContent } from 'comark-content'
3+
import fsSource from 'comark-content/sources/fs'
4+
5+
/**
6+
* `content/` is next to this module only when it is loaded from source. Anywhere the server has
7+
* been bundled the markdown is read back from a server asset instead, because a deployment has no
8+
* `content/` directory.
9+
*/
10+
export const contentDir = fileURLToPath(new URL('../../content', import.meta.url))
11+
12+
/**
13+
* The markdown as it sits on disk. Kept apart from `content.ts` so that `nuxt.config`, which reads
14+
* this to list the pages to prerender, does not have to load a nitro runtime import through it.
15+
*/
16+
export const fsContent = () => comarkContent({ source: fsSource(contentDir) })

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL