For Workes & Pages, what is the name of the domain?
NA
What is the issue or error you’re encountering
NA
What are the steps to reproduce the issue?
When using the workers’ vitest
integration, is it possible to access my local d1 database for testing?
import { env } from "cloudflare:test";
import { describe, it, expect } from "vitest";
import { Env } from "../src/index.js";
//This is in the docs for env
declare module "cloudflare:test" {
interface ProvidedEnv extends Env {}
}
it("Prepared statements", async () => {
//test some function that uses env, but doesn't query d1, and it works
...
//test some function which queries my local d1 db, it doesn't found the table/s used in my query,
//sql error.
const table_list = await env.MY_DB.exec("pragma table_list;");
console.log("Table list:", table_list);
// which prints: Table list: { count: 1, duration: 0 } })
There is only one recipe for d1
in the github repo linked in the docs, and it creates the db for testing using migrations within the same test. I expected to test my local d1 directly and this will know my local db from my bindings, given that wrangler.toml
is passed to vitest.config.mts
.