-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin-options.test.ts
More file actions
61 lines (51 loc) · 1.94 KB
/
plugin-options.test.ts
File metadata and controls
61 lines (51 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import plugin from '../../src';
import { loadSchema } from '../utils';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
describe('documentation plugin: plugin options', () => {
it('cleanOutput deletes existing files in the output directory before generation', async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'doc-plugin-'));
// create a stale file that should be removed by cleanOutput
fs.writeFileSync(path.join(tmpDir, 'stale.txt'), 'stale');
const model = await loadSchema(`
model A {
id String @id @default(cuid())
}
`);
await plugin.generate({
defaultOutputPath: tmpDir,
model,
pluginOptions: { cleanOutput: true, output: tmpDir },
schemaFile: 'schema.zmodel',
});
// ensure output dir is prepopulated and removed by cleanOutput
expect(fs.existsSync(path.join(tmpDir, 'stale.txt'))).toBe(false);
expect(fs.existsSync(path.join(tmpDir, 'index.md'))).toBe(true);
});
it("models with @@meta('doc:ignore', true) are treated as internal and excluded when includeInternalModels is false", async () => {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'doc-plugin-'));
const schema = `
model Public {
id String @id @default(cuid())
}
model Internal {
id String @id @default(cuid())
@@meta('doc:ignore', true)
}
`;
const model = await loadSchema(schema);
await plugin.generate({
defaultOutputPath: tmpDir,
model,
pluginOptions: { includeInternalModels: false, output: tmpDir },
schemaFile: 'schema.zmodel',
});
// Public model should be present, internal model should be excluded
expect(fs.existsSync(path.join(tmpDir, 'models', 'Public.md'))).toBe(true);
expect(fs.existsSync(path.join(tmpDir, 'models', 'Internal.md'))).toBe(
false,
);
});
});