E2e Testing a Worker

I can manually test a worker that returns HTML using e.g
wrangler preview --watch --env local --url https://mydomain.local
… and mess with it in the Testing tab, trying out valid/invalid paths.

But I’d like to automate the testing using something like webdriver.io. Yes, it’s technically for Node but it can be used for any browser testing.

What base URL do I use to run those tests? I see the default domain it uses https://example.com and that can be overridden using the --url flag, as above, however in the browser it’s not simply that domain. It’s the huge one starting https://cloudflareworkers.com/?.… and then with a long series of characters with a wrangler session ID. And so the CI process can’t find https://mydomain.local. As it’s not running on that domain.

How do other people do this?

Thanks!

Ah … for anyone else thinking about this, I see there is a wrangler dev command which appears to run a local server and so should work with CI. For some reason I’d only seen wrangler preview. I didn’t look through the docs enough.

Ha, life is never simple. Actually that does work … but I hadn’t appreciated wrangler dev actually runs on the edge and so needs actual domains to resolve for sub-requests. So in your wrangler.toml, you can’t specify it should call e.g api.local or some other local-only domain while developing. As the real server it seems to run on of course won’t be able to resolve that. Hmm.

1 Like