|
| 1 | +import { afterEach, describe, expect, it } from 'vitest'; |
| 2 | +import { pathExists, remove } from 'fs-extra'; |
| 3 | +import { join } from 'path'; |
| 4 | +import { tmpdir } from 'os'; |
| 5 | +import { execSync } from 'child_process'; |
| 6 | +import { nodeGenerator } from './index.js'; |
| 7 | +import type { GeneratorOptions } from '../interface.js'; |
| 8 | + |
| 9 | +const tmpDir = join(tmpdir(), 'cpa-e2e-test'); |
| 10 | + |
| 11 | +afterEach(async () => { |
| 12 | + await remove(tmpDir); |
| 13 | +}); |
| 14 | + |
| 15 | +const fullOptions: GeneratorOptions = { |
| 16 | + projectName: 'test-app', |
| 17 | + database: 'postgres', |
| 18 | + webhooks: true, |
| 19 | + appExtensions: ['custom-panel', 'custom-modal'], |
| 20 | +}; |
| 21 | + |
| 22 | +const minimalOptions: GeneratorOptions = { |
| 23 | + projectName: 'test-app', |
| 24 | + database: 'sqlite', |
| 25 | + webhooks: false, |
| 26 | + appExtensions: [], |
| 27 | +}; |
| 28 | + |
| 29 | +describe('nodeGenerator', () => { |
| 30 | + it('generates all expected files for full options', async () => { |
| 31 | + await nodeGenerator.generate(tmpDir, fullOptions); |
| 32 | + |
| 33 | + const expectedFiles = [ |
| 34 | + 'src/index.ts', |
| 35 | + 'src/app.ts', |
| 36 | + 'src/oauth/index.ts', |
| 37 | + 'src/database/index.ts', |
| 38 | + 'src/webhooks/index.ts', |
| 39 | + 'src/app-extensions/panel/index.ts', |
| 40 | + 'src/app-extensions/modal/index.ts', |
| 41 | + 'package.json', |
| 42 | + 'tsconfig.json', |
| 43 | + '.env.example', |
| 44 | + 'docker-compose.yml', |
| 45 | + ]; |
| 46 | + |
| 47 | + for (const file of expectedFiles) { |
| 48 | + expect(await pathExists(join(tmpDir, file)), `Missing: ${file}`).toBe(true); |
| 49 | + } |
| 50 | + }); |
| 51 | + |
| 52 | + it('omits conditional files for minimal options', async () => { |
| 53 | + await nodeGenerator.generate(tmpDir, minimalOptions); |
| 54 | + |
| 55 | + expect(await pathExists(join(tmpDir, 'src/webhooks/index.ts'))).toBe(false); |
| 56 | + expect(await pathExists(join(tmpDir, 'src/app-extensions'))).toBe(false); |
| 57 | + expect(await pathExists(join(tmpDir, 'docker-compose.yml'))).toBe(false); |
| 58 | + }); |
| 59 | + |
| 60 | + it('generated project passes tsc --noEmit', async () => { |
| 61 | + await nodeGenerator.generate(tmpDir, fullOptions); |
| 62 | + execSync('npm install', { cwd: tmpDir, stdio: 'pipe' }); |
| 63 | + expect(() => { |
| 64 | + execSync('npx tsc --noEmit', { cwd: tmpDir, stdio: 'pipe' }); |
| 65 | + }).not.toThrow(); |
| 66 | + }, 60_000); |
| 67 | +}); |
0 commit comments