Skip to content

Commit 4c427db

Browse files
test(docs): skip prisma-output fences shown inside longer fences; accept CRLF after the fence label
The snapshot scanner now skips a fence nested in a longer one, and checks that every block's runs join back into its text. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent c81e855 commit 4c427db

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎apps/docs/src/lib/llm-markdown.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ function createProtector(input: string, label: string) {
490490
* block is plain text, so it says `text`.
491491
*/
492492
function withPlainPrismaOutputLanguage(fence: string) {
493-
return fence.replace(/^([ \t]*[`~]{3,})prisma-output(?=[ \t\n])/, "$1text");
493+
return fence.replace(/^([ \t]*[`~]{3,})prisma-output(?=[ \t\r\n])/, "$1text");
494494
}
495495

496496
/**

‎apps/docs/src/lib/prisma-output-colors.test.ts‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ function* pages(dir: string): Generator<string> {
2020
}
2121
}
2222

23+
/** The bodies of the page's own `prisma-output` fences; a fence shown inside a longer one is its text, not a block. */
2324
function* outputBlocks(source: string): Generator<string> {
2425
const lines = source.split("\n");
2526
for (let at = 0; at < lines.length; at++) {
26-
const open = /^([ \t]*)(`{3,}|~{3,})prisma-output(?:[ \t]|$)/.exec(lines[at]);
27+
const open = /^([ \t]*)(`{3,}|~{3,})(\S*)/.exec(lines[at]);
2728
if (!open) continue;
28-
const [, indent, fence] = open;
29+
const [, indent, fence, lang] = open;
30+
const closes = new RegExp(`^[ \\t]*${fence[0]}{${fence.length},}[ \\t]*$`);
2931
const body: string[] = [];
30-
for (at++; at < lines.length && lines[at].trim() !== fence; at++) {
32+
for (at++; at < lines.length && !closes.test(lines[at]); at++) {
3133
body.push(lines[at].startsWith(indent) ? lines[at].slice(indent.length) : lines[at]);
3234
}
33-
yield body.join("\n");
35+
if (lang === "prisma-output") yield body.join("\n");
3436
}
3537
}
3638

@@ -72,3 +74,25 @@ test("every prisma-output block in the docs gets some colour", () => {
7274
.map(([id]) => id);
7375
assert.deepEqual(plain, []);
7476
});
77+
78+
test("a prisma-output fence shown inside a longer fence is not a block", () => {
79+
const page = [
80+
"````md",
81+
"```prisma-output",
82+
"✔ shown as an example",
83+
"```",
84+
"````",
85+
"",
86+
"~~~prisma-output no-copy",
87+
"✔ Up to date",
88+
"~~~",
89+
].join("\n");
90+
assert.deepEqual([...outputBlocks(page)], ["✔ Up to date"]);
91+
});
92+
93+
test("every prisma-output block's runs join back into its text", () => {
94+
for (const [id, block] of blocks()) {
95+
const joined = colorizePrismaOutput(block).map((line) => line.map((run) => run.text).join(""));
96+
assert.deepEqual(joined, block.split("\n"), id);
97+
}
98+
});

0 commit comments

Comments
 (0)