|
| 1 | +import { execSync } from 'child_process'; |
| 2 | +import { existsSync, mkdirSync, rmSync } from 'fs'; |
| 3 | +import { join } from 'path'; |
| 4 | + |
| 5 | +describe('Qwik UI CLI Smoke test', () => { |
| 6 | + let projectDirectory: string; |
| 7 | + let tempDirectory: string; |
| 8 | + |
| 9 | + beforeAll(() => { |
| 10 | + const { projectDirectory: projDir, tempDir } = createTestQwikProject(); |
| 11 | + |
| 12 | + projectDirectory = projDir; |
| 13 | + tempDirectory = tempDir; |
| 14 | + }); |
| 15 | + |
| 16 | + afterAll(() => { |
| 17 | + // Cleanup the test project |
| 18 | + rmSync(tempDirectory, { |
| 19 | + recursive: true, |
| 20 | + force: true, |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should be installed and add the button file', () => { |
| 25 | + execSync( |
| 26 | + 'npx -y qwik-ui@e2e init --e2e --projectRoot ./ --uiComponentsPath "src/components/ui" --rootCssPath "src/global.css" --installTailwind --style "simple" --components=button', |
| 27 | + { |
| 28 | + cwd: projectDirectory, |
| 29 | + env: process.env, |
| 30 | + stdio: 'inherit', |
| 31 | + }, |
| 32 | + ); |
| 33 | + execSync('npx -y qwik-ui@e2e add button', { |
| 34 | + cwd: projectDirectory, |
| 35 | + env: process.env, |
| 36 | + stdio: 'inherit', |
| 37 | + }); |
| 38 | + const buttonIsInTheRightPlace = existsSync( |
| 39 | + join(projectDirectory, 'src/components/ui/button/button.tsx'), |
| 40 | + ); |
| 41 | + expect(buttonIsInTheRightPlace).toBeTruthy(); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +/** |
| 46 | + * Creates a test project |
| 47 | + * @returns The directory where the test project was created |
| 48 | + */ |
| 49 | +function createTestQwikProject() { |
| 50 | + const projectName = 'test-qwik-project'; |
| 51 | + const tempDir = join('/tmp', 'tmp-qwik-ui-cli-e2e'); |
| 52 | + |
| 53 | + // Ensure projectDirectory is empty |
| 54 | + rmSync(tempDir, { |
| 55 | + recursive: true, |
| 56 | + force: true, |
| 57 | + }); |
| 58 | + mkdirSync(tempDir, { |
| 59 | + recursive: true, |
| 60 | + }); |
| 61 | + |
| 62 | + execSync(`pnpm create qwik@latest empty ${projectName}`, { |
| 63 | + cwd: tempDir, |
| 64 | + stdio: 'inherit', |
| 65 | + env: process.env, |
| 66 | + }); |
| 67 | + console.log(`Created test project in "${tempDir}"`); |
| 68 | + |
| 69 | + const projectDirectory = join(tempDir, projectName); |
| 70 | + |
| 71 | + return { |
| 72 | + projectDirectory, |
| 73 | + tempDir, |
| 74 | + }; |
| 75 | +} |
0 commit comments