-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtoast-error-duration.test.ts
More file actions
63 lines (54 loc) · 1.99 KB
/
Copy pathtoast-error-duration.test.ts
File metadata and controls
63 lines (54 loc) · 1.99 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
import { describe, it, expect } from "vitest";
import { readFileSync, readdirSync, statSync } from "fs";
import { join, relative } from "path";
/**
* Regression test for issue #87: toast.error() calls must specify
* { duration: 8000 } per the design spec (8 seconds for errors).
*
* Scans all .tsx/.ts source files under src/ for toast.error() calls
* and verifies each one includes the duration option.
*/
function collectFiles(dir: string, ext: string[]): string[] {
const results: string[] = [];
for (const entry of readdirSync(dir)) {
const full = join(dir, entry);
if (statSync(full).isDirectory()) {
if (entry === "node_modules" || entry === ".next") continue;
results.push(...collectFiles(full, ext));
} else if (ext.some((e) => full.endsWith(e))) {
results.push(full);
}
}
return results;
}
describe("toast.error() duration matches design spec", () => {
const srcDir = join(__dirname, "..");
const files = collectFiles(srcDir, [".ts", ".tsx"]).filter(
(f) => !f.endsWith(".test.ts") && !f.endsWith(".test.tsx")
);
it("every toast.error() call includes { duration: 8000 }", () => {
const violations: string[] = [];
for (const file of files) {
const content = readFileSync(file, "utf-8");
const lines = content.split("\n");
for (let i = 0; i < lines.length; i++) {
if (!lines[i].includes("toast.error(")) continue;
// Collect the full statement (may span multiple lines)
let statement = lines[i];
let j = i;
while (j < lines.length - 1 && !statement.includes(");")) {
j++;
statement += " " + lines[j];
}
if (!statement.includes("duration: 8000")) {
const rel = relative(srcDir, file);
violations.push(`${rel}:${i + 1}: ${lines[i].trim()}`);
}
}
}
expect(
violations,
`toast.error() calls missing { duration: 8000 } (design spec: 8s for errors):\n${violations.join("\n")}`
).toHaveLength(0);
});
});