-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathfeature-route-contract.test.ts
More file actions
84 lines (75 loc) · 3.12 KB
/
Copy pathfeature-route-contract.test.ts
File metadata and controls
84 lines (75 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
const FEATURES = join(dirname(fileURLToPath(import.meta.url)), "features");
async function feature(name: string): Promise<string> {
return readFile(join(FEATURES, `${name}.md`), "utf8");
}
test("collection recipes canonicalize nested index routes", async () => {
for (const name of ["new-collection", "new-version", "changelog"]) {
const source = await feature(name);
assert.match(source, /entryRouteKey/);
assert.doesNotMatch(source, /withBaseRoute/);
assert.doesNotMatch(source, /\$\{entry\.id\}\/index\.md/);
}
});
test("collection recipes resolve breadcrumbs from their own collection", async () => {
for (const name of ["new-collection", "new-version"]) {
const source = await feature(name);
assert.match(source, /getBreadcrumbs\(currentSlug, \{ collection: entry\.collection \}\)/);
assert.match(source, /stripBase\(Astro\.url\.pathname, import\.meta\.env\.BASE_URL\)/);
}
});
test("collection recipes guard disabled table-of-contents configuration", async () => {
for (const name of ["new-collection", "new-version"]) {
const source = await feature(name);
assert.match(source, /getRouteFlags,/);
assert.match(
source,
/const \{ tableOfContents: tocOn \} = await getRouteFlags\(entry\);/,
);
assert.match(source, /const tocConfig = entry\.data\.tableOfContents;/);
assert.match(
source,
/const toc = tocOn && tocConfig !== false \? getTOC\(headings, tocConfig\) : false;/,
);
assert.doesNotMatch(
source,
/getTOC\(headings, entry\.data\.tableOfContents\)/,
);
}
});
test("changelog serves and links its expanded source artifact", async () => {
const source = await feature("changelog");
assert.match(source, /surface: "source"/);
assert.match(source, /sourcePath[\s\S]*index\.mdx/);
assert.match(source, /Source:.*absoluteUrl\(sourcePath\)/);
});
test("changelog reserves its index entry for the feed route", async () => {
const source = await feature("changelog");
assert.match(
source,
/### 5h\.[\s\S]*?```astro\n---\nimport type \{ GetStaticPaths \} from "astro";/,
);
assert.match(source, /getChangelogStaticPaths[\s\S]*filter\(\(path\) => path\.params\.slug\)/);
assert.equal(
source.match(/paths\.filter\(\(path\) => path\.params\.slug !== undefined\)/g)?.length,
2,
);
});
test("feature recipes base dynamic terminal links", async () => {
const changelog = await feature("changelog");
assert.doesNotMatch(changelog, /href="\/changelog/);
assert.match(changelog, /new URL\(withBase\("\/changelog\/rss\.xml"/);
assert.match(changelog, /withBase\(`\/changelog\/\$\{entry\.id\}\/`/);
assert.match(
await feature("404-page"),
/const homeHref = withBase\("\/", import\.meta\.env\.BASE_URL\)/,
);
assert.match(
await feature("component-showcase"),
/### `src\/pages\/components\.astro`[\s\S]*import \{ getSidebar, withBase \}[\s\S]*href=\{withBase\(`\/components\/\$\{entry\.id\}`/,
);
});