-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathdocsBlocks.test.ts
87 lines (73 loc) · 2.41 KB
/
docsBlocks.test.ts
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
85
86
87
import { Block } from "bingo-stratum";
import * as fs from "node:fs/promises";
import * as prettier from "prettier";
import { describe, expect, test } from "vitest";
import { blocks, presets } from "./index.js";
const actualLines = await createActualLines();
const expectedLines = await createExpectedLines();
// This test ensures ensures docs/Blocks.md has a row for each of CTA's blocks.
// Each row should include emojis describing which preset(s) include the block.
//
// If this fails, it's likely due to adding, removing, or renaming a block.
// You may need to manually change docs/Blocks.md to match to those changes.
//
// For example, if you add a blockExample to the Common and Everything presets,
// you'll need to add a row like:
//
// ```md
// | Example | `--exclude-example` | | ✅ | 💯 |
// ```
//
// Rows are kept sorted by alphabetical order of name.
describe("docs/Blocks.md", () => {
for (const [i, line] of expectedLines.entries()) {
const name = line.split(" | ")[0].replace("| ", "").trim();
if (!name) {
continue;
}
test(name, () => {
const actualLine = actualLines.find((line) => line.includes(`| ${name}`));
const expectedLine = expectedLines[i];
expect(actualLine).toBe(expectedLine);
});
}
});
async function createActualLines() {
const actualFile = (await fs.readFile("docs/Blocks.md")).toString();
actualFile
.split("\n")
.filter((line) => !line.includes("----"))
.map((line) => line.toLowerCase());
return splitTable(actualFile);
}
async function createExpectedLines() {
const lines = [
"| Block | Exclusion Flag | Minimal | Common | Everything |",
"| ----- | -------------- | ------- | ------ | ---------- |",
];
for (const block of Object.values(blocks) as Block[]) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const name = block.about!.name!;
lines.push(
[
name,
`\`--exclude-${name.replaceAll(/\W+/g, "-").toLowerCase()}\``,
presets.minimal.blocks.includes(block) ? "✔️" : " ",
presets.common.blocks.includes(block) ? "✅" : " ",
presets.everything.blocks.includes(block) ? "💯" : " ",
"",
].join(" | "),
);
}
const expectedTable = await prettier.format(lines.join("\n"), {
parser: "markdown",
useTabs: true,
});
return splitTable(expectedTable);
}
function splitTable(table: string) {
return table
.split("\n")
.filter((line) => !line.includes("----"))
.map((line) => line.toLowerCase());
}