import { type } from "arktype"; export interface Options { /** * Pattern matching files to include in parsing */ include: string[]; /** * Pattern matching files to ignore when parsing */ exclude: string[]; /** * Output directory, test files are emitted alongside their source files if * not specified */ outDir: string | null; /** * File extension to emit test files with * @default * ".doc.test" */ fileExtension: string; /** * Name to use for tests. If not specified, then tests are named by what * their jsdoc comments are documenting. */ testName: string | null; /** * Whether to replace any instance of `$PROJECT_ROOT` with a relative file path to * the root of the project (e.g., for imports) */ templateRoot: boolean; /** * Lines to insert before the test file contents */ templateHeader: string[]; /** * Lines to insert after the test file contents */ templateFooter: string[]; /** * Test format to emit * - `jest`/`vitest`: Generate `test(...)` and `describe(...)` calls with `expect(...)` * - `assert`: Generate code to run `console.assert(...)`/`assert(...)`-style tests */ format: "jest" | "vitest" | "assert"; /** * Whether or not tests only containing assertions should be emitted * * The assertion syntax is determined by {@link format}, e.g. `expect(...)` * for Jest/Vitest. */ onlyGenerateTests: boolean; /** * Whether to require a markdown code block with an appropriate language to * generate tests */ requireCodeBlock: boolean; /** * Whether to include a comment with a path to the test source file in each * test */ includePath: boolean; /** * Whether or not to emit test regions for namespaces using the test harness * (e.g. `describe()` regions in jest/vitest). */ emitRegions: boolean; } export const Options = type({ include: "string[]", "exclude?": "string[]", "outDir?": "string | null", "fileExtension?": "string", "testName?": "string | null", "templateRoot?": "boolean", "templateHeader?": "string[]", "templateFooter?": "string[]", "format?": '"jest" | "vitest" | "assert"', "onlyGenerateTests?": "boolean", "requireCodeBlock?": "boolean", "includePath?": "boolean", "emitRegions?": "boolean", }); export const DEFAULT_OPTIONS: Required = { include: [], exclude: [], outDir: null, fileExtension: ".doc.test", testName: null, templateRoot: true, templateHeader: [], templateFooter: [], format: "vitest", onlyGenerateTests: false, requireCodeBlock: false, includePath: true, emitRegions: true, }; export function defineConfig( opts: Partial> & Pick, ): Options { return { ...DEFAULT_OPTIONS, ...opts, }; }