|
| 1 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { exec } from 'tinyexec'; |
| 4 | +import path from 'node:path'; |
| 5 | +import fs from 'node:fs'; |
| 6 | +import { parseJson } from '../../core/tooling/index.ts'; |
| 7 | + |
| 8 | +const monoRepoPath = path.resolve(__dirname, '..', '..', '..'); |
| 9 | + |
| 10 | +beforeAll(() => { |
| 11 | + const testOutputCliPath = path.resolve(monoRepoPath, '.test-output', 'cli'); |
| 12 | + |
| 13 | + if (fs.existsSync(testOutputCliPath)) { |
| 14 | + fs.rmSync(testOutputCliPath, { force: true, recursive: true }); |
| 15 | + } |
| 16 | +}); |
| 17 | + |
| 18 | +describe('cli', () => { |
| 19 | + it('should be able to create a new project with cli command', async () => { |
| 20 | + const svBinPath = path.resolve(monoRepoPath, 'packages', 'cli', 'dist', 'bin.js'); |
| 21 | + const testOutputPath = path.resolve(monoRepoPath, '.test-output', 'cli', 'test-project'); |
| 22 | + |
| 23 | + const result = await exec( |
| 24 | + 'node', |
| 25 | + [ |
| 26 | + svBinPath, |
| 27 | + 'create', |
| 28 | + testOutputPath, |
| 29 | + '--template', |
| 30 | + 'minimal', |
| 31 | + '--types', |
| 32 | + 'ts', |
| 33 | + '--no-install', |
| 34 | + '--no-add-ons' |
| 35 | + ], |
| 36 | + { nodeOptions: { stdio: 'ignore' } } |
| 37 | + ); |
| 38 | + |
| 39 | + // cli finished well |
| 40 | + expect(result.exitCode).toBe(0); |
| 41 | + |
| 42 | + // test output path exists |
| 43 | + expect(fs.existsSync(testOutputPath)).toBe(true); |
| 44 | + |
| 45 | + // package.json has a name |
| 46 | + const packageJsonPath = path.resolve(testOutputPath, 'package.json'); |
| 47 | + const packageJson = parseJson(fs.readFileSync(packageJsonPath, 'utf-8')); |
| 48 | + expect(packageJson.name).toBe('test-project'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments