Running tests using workerd #229
Replies: 2 comments 7 replies
-
Straw man design: What if you could define a "test handler", like:
Then there was a new
This runs the test handler for the specified service and exits with status zero (success) if and only if the test handler returns true. If the test throws an exception or returns anything other than Of course, you will probably want to use some sort of testing framework within this, but this gives you the mechanism to invoke such tests from the command line. Note that you don't necessarily have to embed your test handler within your service code. You could define a separate test service in your config file, which talks to the service under test via a binding. Or maybe if you are unit testing a library, then you only have a test service, which bundles the library and makes calls to it. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
This is a great start. So far, we've tried a similar strategy. Other libraries like Jose are doing it too. The most significant challenges we are facing have to do with using established JS testing frameworks. For example, Mocha and Jest require async IO, timers, and random generation outside the worker handler if you need to unit test Fetch API calls or async flows. We managed to enable these features in Miniflare but ideally, tests should run more easily on the worker daemon directly. This raises the question of whether this is a workerd issue or an issue of the JS testing frameworks. However, since the tooling has been around for years, finding a middle ground sounds ideal. |
Beta Was this translation helpful? Give feedback.
-
The new capabilities that edge runtimes bring to the table are very exciting. Modern-web software is already leveraging the new available APIs but tooling for testing is not standardized yet.
Our mission at Clerk is to provide authentication across all modern runtimes. In the JS world, this translates to an interoperable NPM package that works across all JS runtimes such as Node, Deno, and Cloudflare workers.
So far, testing the code was done manually or via alternate semi-automated solutions such as Miniflare. The purpose of this discussion is to focus on how to use
workerd
to run test suites faster and ensure the quality of the shipped packages.Existing JS testing tools such as Mocha, or Jest do not work in a CF worker environment out of the box. This discussion started from #158.
Beta Was this translation helpful? Give feedback.
All reactions