Cotton code
23 lines · 781 B · TypeScriptRaw
import { readFileSync } from "node:fs";import { defineConfig, type Plugin } from "vitest/config";// A `.wasm` import is a compiled WebAssembly.Module, as the Workers runtime// hands it (src/rules' one module), so the Worker's own source loads here too.const wasmModule: Plugin = {  name: "wasm-module",  enforce: "pre",  load(id) {    if (!id.endsWith(".wasm")) return null;    const bytes = readFileSync(id).toString("base64");    return `export default new WebAssembly.Module(Buffer.from(${JSON.stringify(bytes)}, "base64"));`;  },};// The scripts' own tests: plain Node (node:sqlite, node:crypto), no Workers pool.export default defineConfig({  plugins: [wasmModule],  test: {    environment: "node",    include: ["scripts/__tests__/**/*.test.ts"],  },});