|
| 1 | +import plugin from "../../src"; |
| 2 | +import fs from "node:fs"; |
| 3 | +import os from "node:os"; |
| 4 | +import path from "node:path"; |
| 5 | +import { loadSchema } from "../utils"; |
| 6 | +import { describe, expect, it } from "vitest"; |
| 7 | + |
| 8 | +describe("documentation plugin: plugin options", () => { |
| 9 | + it("cleanOutput deletes existing files in the output directory before generation", async () => { |
| 10 | + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "doc-plugin-")); |
| 11 | + // create a stale file that should be removed by cleanOutput |
| 12 | + fs.writeFileSync(path.join(tmpDir, "stale.txt"), "stale"); |
| 13 | + |
| 14 | + const model = await loadSchema(` |
| 15 | + model A { |
| 16 | + id String @id @default(cuid()) |
| 17 | + } |
| 18 | + `); |
| 19 | + |
| 20 | + await plugin.generate({ |
| 21 | + defaultOutputPath: tmpDir, |
| 22 | + model, |
| 23 | + pluginOptions: { output: tmpDir, cleanOutput: true }, |
| 24 | + schemaFile: "schema.zmodel", |
| 25 | + }); |
| 26 | + |
| 27 | + // ensure output dir is prepopulated and removed by cleanOutput |
| 28 | + |
| 29 | + expect(fs.existsSync(path.join(tmpDir, "stale.txt"))).toBe(false); |
| 30 | + expect(fs.existsSync(path.join(tmpDir, "index.md"))).toBe(true); |
| 31 | + }); |
| 32 | +}); |
0 commit comments