|
| 1 | +/** |
| 2 | + * @objectql/create — Scaffolding output tests |
| 3 | + * |
| 4 | + * Verifies that the create-objectql templates exist and produce valid projects. |
| 5 | + */ |
| 6 | +import { describe, it, expect } from 'vitest'; |
| 7 | +import * as fs from 'fs'; |
| 8 | +import * as path from 'path'; |
| 9 | + |
| 10 | +const TEMPLATES_DIR = path.resolve(__dirname, '../templates'); |
| 11 | + |
| 12 | +const EXPECTED_TEMPLATES = ['hello-world', 'starter', 'enterprise']; |
| 13 | + |
| 14 | +describe('@objectql/create templates', () => { |
| 15 | + it('should have all expected template directories', () => { |
| 16 | + for (const template of EXPECTED_TEMPLATES) { |
| 17 | + const templatePath = path.join(TEMPLATES_DIR, template); |
| 18 | + expect(fs.existsSync(templatePath), `Template "${template}" should exist at ${templatePath}`).toBe(true); |
| 19 | + } |
| 20 | + }); |
| 21 | + |
| 22 | + for (const template of EXPECTED_TEMPLATES) { |
| 23 | + describe(`${template} template`, () => { |
| 24 | + const templatePath = path.join(TEMPLATES_DIR, template); |
| 25 | + |
| 26 | + it('should contain a package.json', () => { |
| 27 | + const pkgPath = path.join(templatePath, 'package.json'); |
| 28 | + expect(fs.existsSync(pkgPath)).toBe(true); |
| 29 | + |
| 30 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); |
| 31 | + expect(pkg.name).toBeDefined(); |
| 32 | + expect(pkg.dependencies || pkg.devDependencies).toBeDefined(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should contain a tsconfig.json', () => { |
| 36 | + const tsconfigPath = path.join(templatePath, 'tsconfig.json'); |
| 37 | + expect(fs.existsSync(tsconfigPath)).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should contain a src directory with entry point', () => { |
| 41 | + const srcDir = path.join(templatePath, 'src'); |
| 42 | + expect(fs.existsSync(srcDir)).toBe(true); |
| 43 | + |
| 44 | + // Check for at least one .ts file in src |
| 45 | + const srcFiles = fs.readdirSync(srcDir, { recursive: true }) as string[]; |
| 46 | + const tsFiles = srcFiles.filter(f => String(f).endsWith('.ts')); |
| 47 | + expect(tsFiles.length).toBeGreaterThan(0); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should contain objectstack.config.ts or objectql config', () => { |
| 51 | + const srcDir = path.join(templatePath, 'src'); |
| 52 | + const rootFiles = fs.readdirSync(templatePath); |
| 53 | + const srcFiles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir) : []; |
| 54 | + const allFiles = [...rootFiles, ...srcFiles]; |
| 55 | + |
| 56 | + const hasConfig = allFiles.some(f => |
| 57 | + String(f).includes('objectstack.config') || |
| 58 | + String(f).includes('objectql.config') || |
| 59 | + String(f).includes('index.ts') |
| 60 | + ); |
| 61 | + expect(hasConfig).toBe(true); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should have workspace:* dependencies for @objectql packages', () => { |
| 65 | + const pkgPath = path.join(templatePath, 'package.json'); |
| 66 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); |
| 67 | + const allDeps = { ...pkg.dependencies, ...pkg.devDependencies }; |
| 68 | + |
| 69 | + const objectqlDeps = Object.entries(allDeps).filter( |
| 70 | + ([key]) => key.startsWith('@objectql/') || key.startsWith('@objectstack/') |
| 71 | + ); |
| 72 | + |
| 73 | + // Templates in the monorepo should use workspace:* references |
| 74 | + for (const [name, version] of objectqlDeps) { |
| 75 | + expect(version, `${name} should use workspace:* in template`).toBe('workspace:*'); |
| 76 | + } |
| 77 | + }); |
| 78 | + }); |
| 79 | + } |
| 80 | +}); |
0 commit comments