Unit Testing Workers, in Cloudflare Workers
May 2, 2019Tim Obezuk

Summary
This post introduces a method for executing Mocha unit tests directly within the Cloudflare Worker runtime by creating a compatible test harness. It details the directory setup, necessary npm packages (Mocha, Webpack, exports-loader, mocha-loader), example Worker script, test script, and the serviceworker-mocha-harness.js script. It also covers Webpack configuration for bundling and running the tests, and how to integrate this into a CI/CD pipeline, returning JSON test reports.