UNPKG

@cloudflare/vitest-pool-workers

Version:

Workers Vitest integration for writing Vitest unit and integration tests that run inside the Workers runtime

86 lines (85 loc) 4.26 kB
import { z } from "zod"; import type { ModuleRule, WorkerOptions } from "miniflare"; import type { WorkspaceProject } from "vitest/node"; export interface WorkersConfigPluginAPI { setMain(newMain?: string): void; } export declare const OPTIONS_PATH: string; declare const WorkersPoolOptionsSchema: z.ZodObject<{ /** * Entrypoint to Worker run in the same isolate/context as tests. This is * required to use `import { SELF } from "cloudflare:test"`, or Durable * Objects without an explicit `scriptName`. Note this goes through Vite * transforms and can be a TypeScript file. Note also * `import module from "<path-to-main>"` inside tests gives exactly the same * `module` instance as is used internally for the `SELF` and Durable Object * bindings. */ main: z.ZodOptional<z.ZodString>; /** * Enables per-test isolated storage. If enabled, any writes to storage * performed in a test will be undone at the end of the test. The test storage * environment is copied from the containing suite, meaning `beforeAll()` * hooks can be used to seed data. If this is disabled, all tests will share * the same storage. */ isolatedStorage: z.ZodDefault<z.ZodBoolean>; /** * Runs all tests in this project serially in the same worker, using the same * module cache. This can significantly speed up tests if you've got lots of * small test files. */ singleWorker: z.ZodDefault<z.ZodBoolean>; miniflare: z.ZodOptional<z.ZodObject<{ workers: z.ZodOptional<z.ZodArray<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, "many">>; }, "passthrough", z.ZodTypeAny, z.objectOutputType<{ workers: z.ZodOptional<z.ZodArray<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, "many">>; }, z.ZodTypeAny, "passthrough">, z.objectInputType<{ workers: z.ZodOptional<z.ZodArray<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, "many">>; }, z.ZodTypeAny, "passthrough">>>; wrangler: z.ZodOptional<z.ZodObject<{ configPath: z.ZodOptional<z.ZodString>; environment: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { configPath?: string | undefined; environment?: string | undefined; }, { configPath?: string | undefined; environment?: string | undefined; }>>; }, "strip", z.ZodTypeAny, { isolatedStorage: boolean; singleWorker: boolean; main?: string | undefined; miniflare?: z.objectOutputType<{ workers: z.ZodOptional<z.ZodArray<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, "many">>; }, z.ZodTypeAny, "passthrough"> | undefined; wrangler?: { configPath?: string | undefined; environment?: string | undefined; } | undefined; }, { main?: string | undefined; isolatedStorage?: boolean | undefined; singleWorker?: boolean | undefined; miniflare?: z.objectInputType<{ workers: z.ZodOptional<z.ZodArray<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>, "many">>; }, z.ZodTypeAny, "passthrough"> | undefined; wrangler?: { configPath?: string | undefined; environment?: string | undefined; } | undefined; }>; export type SourcelessWorkerOptions = Omit<WorkerOptions, "script" | "scriptPath" | "modules" | "modulesRoot"> & { modulesRules?: ModuleRule[]; }; export type WorkersPoolOptions = z.input<typeof WorkersPoolOptionsSchema> & { miniflare?: SourcelessWorkerOptions & { workers?: WorkerOptions[]; }; }; export type WorkersPoolOptionsWithDefines = WorkersPoolOptions & { defines?: Record<string, string>; }; export declare function parseProjectOptions(project: WorkspaceProject): Promise<WorkersPoolOptionsWithDefines>; export {};