Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Add first-class support for testing workers #1823

Closed
huv1k opened this issue Mar 24, 2021 · 7 comments
Closed

Add first-class support for testing workers #1823

huv1k opened this issue Mar 24, 2021 · 7 comments
Labels
feature Feature requests and suggestions

Comments

@huv1k
Copy link

huv1k commented Mar 24, 2021

💡 Feature request

I would like to see first-class support for unit testing CF workers.

Describe the feature

Provide testing framework/integration to tests workers with unit and integration tests. I would like to see support for Jest or another testing feature provided out of the box by Cloudflare, right now this missing even documentation is lacking. This should cover all runtime APIs. I created this issue here because I don't know where these kinds of issues should be reported.

Describe the alternatives

There is @dollarshaveclub/cloudworker, which is not maintained anymore. You can create your own setup, but it's a little bit hard to mock all features workers provide because the implementation of workers is not open sourced.

@huv1k huv1k added the feature Feature requests and suggestions label Mar 24, 2021
@xtuc
Copy link
Member

xtuc commented Mar 24, 2021

Have you tried using wrangler dev? or wrangler preview?

@huv1k
Copy link
Author

huv1k commented Mar 26, 2021

Have you tried using wrangler dev? or wrangler preview?

I don't see how this going to solve testing. How you would test accessing to KV store and then resetting data? I can see that you are going to call some cleanups functions after these tests run, but with that in mind you are going to completely go through the roof and relying on network request in tests are not a great idea.

@Electroid
Copy link
Contributor

Thanks so much for submitting this feedback! Local and unit testing is definitely something we are investigating and recognize need to do better.

@huv1k Would it matter to you whether the code was actually running locally (e.g. emulation) or actually running on our edge? (e.g. script/resources get sent, in the background, to our edge)

@huv1k
Copy link
Author

huv1k commented Apr 7, 2021

I would prefer to have it running locally because the network is not always reliable and could fail in CI. I could see there would be a mocking function for each feature.

@dgitq
Copy link

dgitq commented Apr 24, 2021

I agree fully! There should be a way to develop and run tests locally without the requests being routed to the Cloudfare edge..
Never really understood why Cloudflare neglected this and usually points to 'wrangler preview/dev' as a replacement for a proper local environment. Back in the day there was support by the community but it is not maintained any more: https://github.com/dollarshaveclub/cloudworker

Other cloud providers such as Azure have support for local development environments. There should be an official support maintained by Cloudflare @rita3ko :)

In the mean time you can look into jdanyow's packages collection:
#1321
https://github.com/cfworker/cfworker

Thanks!

@threepointone
Copy link
Contributor

We now have an officially supported solution with miniflare https://miniflare.dev/ We will integrate this more deeply with wrangler in the future, but this is usable today.

@threepointone
Copy link
Contributor

We now have an officially supported solution for this with miniflare https://miniflare.dev/ We'll be integrating this with wrangler more deeply in the future, but this is usable today.

I'm going to close this issue for now, but feel free to drop feedback!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests and suggestions
Projects
None yet
Development

No branches or pull requests

5 participants