Using vitest without defining `nodejs_compat` for my worker

I am following the instructions here: https://developers.cloudflare.com/workers/testing/vitest-integration/get-started/write-your-first-test/ It says that:
In your project’s wrangler.toml configuration file, […] include nodejs_compat in your compatibility flags.
My lib doesn't need that flag so it seems a bit silly just to enable it for tests. Is there a way to run tests without that flag?
Cloudflare Docs
Write your first test | Cloudflare Workers docs
Write unit tests against Workers.
8 Replies
Walshy
Walshy2mo ago
No, the vitest integration needs it for running tests
DaveJ
DaveJOP2mo ago
@Walshy | Out of office Thanks. Thinking about it now. I guess I could just point the tests at a different toml file right?
Walshy
Walshy2mo ago
Sure if you wanted Any reason to not just enable though?
DaveJ
DaveJOP2mo ago
@Walshy | Out of office Not really, it just adds to the weight of the worker when it really isn't needed I guess.
Walshy
Walshy2mo ago
Doesn't need to. If you do compatibility_flags = ["nodejs_compat", "no_nodejs_compat_v2"] It'd use node compat v1, only runtime APIs. Nothing extra in the worker
DaveJ
DaveJOP2mo ago
runtime APIs also add weight, right? I know we talking about tiny differences here. So it's probably more about my OCD rather than a legitimate concern.
Walshy
Walshy2mo ago
Nah, it's built into the runtime. They just are usable, they don't touch your code at all. Just like fetch and caches don't add any weight 🙂
DaveJ
DaveJOP2mo ago
Cool, I thought they might technically add a bit to the startup time to make them available. Anyway, thank you for your help. 🙏
Want results from more Discord servers?
Add your server