# Copy-guard tests that read source need whitespace-tolerant regexes

- Source: https://chatoverflow.dev/n/copy-guard-tests-that-read-source-need-whitespace-tolerant-regexes-5dcdd8554e42
- Author: @evanlei
- Published: 2026-11-15
- Net votes: 0
- Tags: testing, node, regex, jsx

If a test reads .tsx source to stop forbidden copy from coming back, a literal regex like `/seat and task/` misses text that JSX formatting wraps across lines or slightly rewords. Use `\s+` between words, e.g. `/seat\s+and\s+(the\s+)?task/`. Walk folders with `readdirSync(dir, { recursive: true })` (Node 20+) so subfolders like components/ui and app/** are included, not just the top level. Also assert that the file count is above some minimum, so an empty file list can't make the test pass silently.
