Skip to content

Commit ebbe00b

Browse files
committed
🧪 test: Add meta test to check all test scripts are run
1 parent ba97e47 commit ebbe00b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
files: test/test-sync.js
2323
- name: Duplicates
2424
files: test/test-duplicates.js
25+
- name: All test scripts are listed in test.yml
26+
files: test/test-meta.js
2527

2628
name: ${{ matrix.name }}
2729
steps:

test/test-meta.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { expect } from "expect";
2+
import fs from "fs";
3+
import path from "path";
4+
import { fileURLToPath } from "url";
5+
import YAML from "yaml";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
const rootDir = path.join(__dirname, "..");
10+
11+
describe("Meta Tests - CI Workflow Coverage", function () {
12+
// 1. Find all test files in the test directory
13+
const testDir = path.join(rootDir, "test");
14+
const allFiles = fs.readdirSync(testDir);
15+
const testFiles = allFiles.filter((file) => {
16+
// Only look for files starting with 'test-' and ending with '.js'
17+
if (!file.startsWith("test-") || !file.endsWith(".js")) return false;
18+
19+
// Check if file is empty
20+
const filePath = path.join(testDir, file);
21+
const content = fs.readFileSync(filePath, "utf8");
22+
if (content.trim().length === 0) return false;
23+
24+
// Check for ignore comment
25+
if (content.includes("//" + " test-meta:ignore")) return false;
26+
27+
return true;
28+
});
29+
30+
// 2. Read test.yml and find all listed files
31+
const workflowPath = path.join(rootDir, ".github/workflows/test.yml");
32+
const workflowContent = fs.readFileSync(workflowPath, "utf8");
33+
const workflow = YAML.parse(workflowContent);
34+
35+
const listedFiles = new Set();
36+
37+
// Extract files from the matrix strategy
38+
const matrixInclude = workflow.jobs["test-matrix"]?.strategy?.matrix?.include || [];
39+
matrixInclude.forEach((item) => {
40+
if (item.files) {
41+
item.files.split(" ").forEach((f) => listedFiles.add(f.trim()));
42+
}
43+
});
44+
45+
// Extract files from other jobs (like test-storage)
46+
Object.values(workflow.jobs).forEach((job) => {
47+
// Skip the matrix job itself as we handled it above
48+
if (job === workflow.jobs["test-matrix"]) return;
49+
50+
if (job.steps) {
51+
job.steps.forEach((step) => {
52+
if (step.with && step.with.command) {
53+
const match = step.with.command.match(/npm run test:file\s+(.+)/);
54+
if (match) {
55+
match[1].split(" ").forEach((f) => listedFiles.add(f.trim()));
56+
}
57+
}
58+
});
59+
}
60+
});
61+
62+
// 3. Generate a test for each file
63+
testFiles.forEach((file) => {
64+
it(`should list ${file} in test.yml`, function () {
65+
const relativePath = `test/${file}`;
66+
if (!listedFiles.has(relativePath)) {
67+
throw new Error(
68+
`${file} is not listed in .github/workflows/test.yml. Please add it to the workflow or add '// ` +
69+
`test-meta:ignore' to the file.`
70+
);
71+
}
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)