3

Sveltekit and Cloudflare seem to be a great match. My objective is to deliver well-tested code, that runs smoothly on Cloudflare pages/workers. To do this, I use Cypress.io for e2e testing. The problem is that I can't trust the tests running locally, as using any Node.js API works fine locally (for example Buffer.from). But this code breaks the site when deploying to Cloudflare.

How can I run the Sveltekit project locally to ensure it will work once deployed?

As a bonus, would it somehow be possible to configure the typescript project so it would throw errors when accessing Node.js API's? According to this Cloudflare page, workers are running a v8 instance. We are using the "official" adapter.

Thanks for your help.

DauleDK
  • 3,313
  • 11
  • 55
  • 98

1 Answers1

4

SvelteKit is planning ways to make this easier in the long-term. You can hear Rich talk a bit about this in the most recent Svelte NYC meetup.

In the meantime, your best bet is to include something like a "postbuild" hook that points miniflare to the output file that SK produced. This will ensure that the contents are bootable according to a Cloudflare Workers emulated environment. You can run an e2e test suite against the localhost endpoint it spawns for you, too.

lukeed
  • 409
  • 2
  • 5
  • 13
  • Wait? That would be genious. I will try out the miniflare and report back :) – DauleDK Apr 16 '22 at 11:29
  • When I try using miniflare like this with the `@sveltejs/adapter-cloudflare` what file should I point miniflare to? – DauleDK Apr 16 '22 at 18:52