|
| 1 | +import fs from 'node:fs'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | +import { beforeEach, expect, test } from '@rstest/core'; |
| 5 | +import { create } from '../src'; |
| 6 | + |
| 7 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 8 | +const fixturesDir = path.join(__dirname, 'fixtures', 'cli'); |
| 9 | +const testDir = path.join(fixturesDir, 'test-temp-output'); |
| 10 | + |
| 11 | +beforeEach(() => { |
| 12 | + // Clean up test directory before each test |
| 13 | + if (fs.existsSync(testDir)) { |
| 14 | + fs.rmSync(testDir, { recursive: true }); |
| 15 | + } |
| 16 | + fs.mkdirSync(testDir, { recursive: true }); |
| 17 | + |
| 18 | + // Return cleanup function |
| 19 | + return () => { |
| 20 | + if (fs.existsSync(testDir)) { |
| 21 | + fs.rmSync(testDir, { recursive: true }); |
| 22 | + } |
| 23 | + }; |
| 24 | +}); |
| 25 | + |
| 26 | +test('should accept comma separated tools option', async () => { |
| 27 | + const projectDir = path.join(testDir, 'comma-separated-tools'); |
| 28 | + |
| 29 | + await create({ |
| 30 | + name: 'test', |
| 31 | + root: fixturesDir, |
| 32 | + templates: ['vanilla'], |
| 33 | + getTemplateName: async () => 'vanilla', |
| 34 | + argv: [ |
| 35 | + 'node', |
| 36 | + 'test', |
| 37 | + '--dir', |
| 38 | + projectDir, |
| 39 | + '--template', |
| 40 | + 'vanilla', |
| 41 | + '--tools', |
| 42 | + 'eslint,prettier', |
| 43 | + ], |
| 44 | + }); |
| 45 | + |
| 46 | + expect(fs.existsSync(path.join(projectDir, 'eslint.config.mjs'))).toBe(true); |
| 47 | + expect(fs.existsSync(path.join(projectDir, '.prettierrc'))).toBe(true); |
| 48 | +}); |
| 49 | + |
| 50 | +test('should skip tools selection', async () => { |
| 51 | + const projectDir = path.join(testDir, 'comma-separated-tools'); |
| 52 | + |
| 53 | + await create({ |
| 54 | + name: 'test', |
| 55 | + root: fixturesDir, |
| 56 | + templates: ['vanilla'], |
| 57 | + getTemplateName: async () => 'vanilla', |
| 58 | + argv: [ |
| 59 | + 'node', |
| 60 | + 'test', |
| 61 | + '--dir', |
| 62 | + projectDir, |
| 63 | + '--template', |
| 64 | + 'vanilla', |
| 65 | + '--tools', |
| 66 | + '""', |
| 67 | + ], |
| 68 | + }); |
| 69 | + |
| 70 | + expect(fs.existsSync(path.join(projectDir, 'eslint.config.mjs'))).toBe(false); |
| 71 | + expect(fs.existsSync(path.join(projectDir, '.prettierrc'))).toBe(false); |
| 72 | +}); |
0 commit comments