Unit Testing Worker Functions
Cloudflare Workers, which allow running JavaScript in all 165+ of their data centers, have seen creative applications as use cases grow in complexity. As a result, the need to smoke test code also increases. This post demonstrates how to unit test Cloudflare Workers and their individual functions using Cloudworker, created by the Dollar Shave Club engineering team. The example script contains two functions that contribute to the response to the client. To set up the directory for testing, create a new npm project in a new directory with a worker.js file containing the script and a test folder with a worker-test.js file. Install Cloudworker and Mocha testing framework, then write tests using mocha's async/await support. This allows for more confidence when deploying complex workers as each component can be tested individually.
Company
Cloudflare
Date published
March 15, 2019
Author(s)
Tom Brightbill, Tim Obezuk
Word count
611
Hacker News points
None found.
Language
English