Hi! I've spent quite a few hours looking up this specific use-case but could not find much help on

Hi!

I've spent quite a few hours looking up this specific use-case but could not find much help online so I'd like to ask:

How can I work with D1 in the context of integration/e2e tests?
Let's say I have a JSON REST API written in a Worker.

As for the Worker itself I can use wranglers unstable_dev() API to set up everything for testing.

My code currently looks like this:

describe("backend json rest api", () => {
  let worker;

  before(async () => {
    worker = await unstable_dev("src/index.ts", {
      experimental: { disableExperimentalWarning: true },
    });
  });

  after(async () => {
    await worker.stop();
  });

  // ... actual tests here
});


At the very least it would be nice to have a fresh database ready at the start of the test. So like create a new SQLite file and run all the migrations. Currently the worker in the code above simply accesses my local D1 file.

How could I accomplish this in a way that would later fit into CI/CD etc?
Was this page helpful?