-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappExtensions.test.ts
More file actions
57 lines (52 loc) · 2.01 KB
/
Copy pathappExtensions.test.ts
File metadata and controls
57 lines (52 loc) · 2.01 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
import { afterEach, describe, expect, it } from 'vitest';
import { access, rm } from 'node:fs/promises';
import { join } from 'path';
import { tmpdir } from 'os';
import type { GeneratorOptions } from '../interface.js';
const tmpDir = join(tmpdir(), 'cpa-appext-test');
const exists = (p: string) =>
access(p).then(
() => true,
() => false,
);
afterEach(async () => {
await rm(tmpDir, { recursive: true, force: true });
});
describe('generateAppExtensions', () => {
it('creates panel stub when custom-panel is selected', async () => {
const { generateAppExtensions } = await import('./appExtensions.js');
const options: GeneratorOptions = {
projectName: 'test-app',
database: 'postgres',
webhooks: false,
appExtensions: ['custom-panel'],
};
await generateAppExtensions(tmpDir, options);
expect(await exists(join(tmpDir, 'src/app-extensions/panel/index.ts'))).toBe(true);
expect(await exists(join(tmpDir, 'src/app-extensions/modal/index.ts'))).toBe(false);
});
it('creates modal stub when custom-modal is selected', async () => {
const { generateAppExtensions } = await import('./appExtensions.js');
const options: GeneratorOptions = {
projectName: 'test-app',
database: 'postgres',
webhooks: false,
appExtensions: ['custom-modal'],
};
await generateAppExtensions(tmpDir, options);
expect(await exists(join(tmpDir, 'src/app-extensions/modal/index.ts'))).toBe(true);
expect(await exists(join(tmpDir, 'src/app-extensions/panel/index.ts'))).toBe(false);
});
it('creates both stubs when both types are selected', async () => {
const { generateAppExtensions } = await import('./appExtensions.js');
const options: GeneratorOptions = {
projectName: 'test-app',
database: 'postgres',
webhooks: false,
appExtensions: ['custom-panel', 'custom-modal'],
};
await generateAppExtensions(tmpDir, options);
expect(await exists(join(tmpDir, 'src/app-extensions/panel/index.ts'))).toBe(true);
expect(await exists(join(tmpDir, 'src/app-extensions/modal/index.ts'))).toBe(true);
});
});