Running jest tests in `workerd` environment?

We develop a library that should work on Cloudflare Workers. We have a huge test suite, that tests its full API in all the combination we could think of. Is there a good way to run our existing jest test suite in a workerd like environment?
9 Replies
DaniFoldi
DaniFoldi6mo ago
Hi meowwave I have some good news for you, unit test support for workers with miniflare is in the works: https://discord.com/channels/595317990191398933/1024343493251973190/1182250811946967100 To my knowledge it will be vitest-only though, so I suggest you look at migrating to it, it's faster and more modern anyways.
Jan Piotrowski (janpio)
That sounds great! If I understand correctly, this is more or less the replacement for Miniflare 2's unit testing setup? Our test suite is massive, including a lot of custom modifications, so migrating will be quite a challenge. But I'll bring it up.
DaniFoldi
DaniFoldi6mo ago
Indeed, to my knowledge this will be the last piece of the v2->v3 migration, which will take advantage of vitest's new pool feature in v1
Jan Piotrowski (janpio)
GitHub
miniflare/packages/vitest-environment-miniflare at master · cloudfl...
🔥 Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare. - cloudflare/miniflare
GitHub
GitHub - cloudflare/miniflare: 🔥 Fully-local simulator for Cloudfla...
🔥 Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare. - GitHub - cloudflare/miniflare: 🔥 Fully-local si...
Jan Piotrowski (janpio)
Are the v2 miniflare docs about this Vitest setup still online somewhere? The first link refers to https://miniflare.dev/testing/vitest, but that is a 404. I assume that would be useful for me to get some feedback before this new work is finished.
MrBBot
MrBBot6mo ago
The docs for the v2 Vitest environment are here https://legacy.miniflare.dev/testing/vitest, but the API is going to change quite a bit, so I wouldn’t start migrating to that atm. Would definitely be interested to hear any feedback/pain points you had with the Jest environment though. Still at a stage where we can make changes before we release. Specifically interested in the custom modifications you needed to make, but anything you wish was different would be helpful. 🙂
Jan Piotrowski (janpio)
Oh sorry, that was unclear it seems: We just have a huge Jest test setup that is pretty involved, generating tests and so on (take a look at the GH Actions runs of e.g. https://github.com/prisma/prisma/commit/ed33d55b8633f8417298e1b715c961249d046296, some docs at https://github.com/prisma/prisma/blob/main/TESTING.md) Cloudflare Workers is a new thing for us that we now want to add to that, and I'm starting to look into how we best make that happen.
MrBBot
MrBBot6mo ago
Ah I see! That makes more sense! 🙂
Jan Piotrowski (janpio)
Unfortunately also something you can probably help with less :p