What's the best way to build a crapton of TypeScript tests in a cacheable way, so you only run them if their dependent files, or dependent packages change?

Aug 31, 2026 · 1:23 AM UTC

7
11
3,064
Sort replies: Relevant Recent Liked
Replying to @ryantm
You can use a build tool with tree shaking (esbuild or bun) to build a single-js-file for each test file deterministically and cache that (or a hash of it) and then only run tests when that changes - there’s some DIY but it’s not rocket science and will get you 80% effectiveness if the rest of your codebase is well structured for tree shaking (linters can help)
1
3
326
There's more needed here though because I suspect the tree shaking esbuild is going to be slow so you need to cache something faster to check.
1
61
Replying to @ryantm
Use Bazel 🤗
2
5
190
What about nx?
1
120
Replying to @ryantm
Turborepo's affected file detection with remote caching handles this well if you're already using it for builds. If not, vitest run --changed BASE_COMMIT does the same trick without adding a whole monorepo tool.
1
28
Replying to @ryantm
Hash the file the test belongs to. Save the hash with the tests which is used as a reference the test can run to verify if any dependencies have changed.
40
Replying to @ryantm
the moment your test setup needs its own distributed systems team you’ve gone too far
38