|
| 1 | +import { describe, it, expect, beforeEach } from 'vitest'; |
| 2 | +import { existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { |
| 5 | + execAsync, |
| 6 | + getRandomString, |
| 7 | + getTempDirectory, |
| 8 | +} from '@callstack/rnef-test-helpers'; |
| 9 | + |
| 10 | +const CREATE_APP_PATH = path.resolve(__dirname, '../../../dist/src/bin.js'); |
| 11 | +const TEMPLATES_DIR = path.resolve(__dirname, '../../../../../templates'); |
| 12 | +const TEMP_DIR = getTempDirectory('e2e-deploys'); |
| 13 | + |
| 14 | +beforeEach(() => { |
| 15 | + mkdirSync(TEMP_DIR, { recursive: true }); |
| 16 | +}); |
| 17 | + |
| 18 | +describe('create-app command', { timeout: 30_000 }, () => { |
| 19 | + it('should create a new project from npm template', async () => { |
| 20 | + const projectName = `test-npm-template-${getRandomString(6)}`; |
| 21 | + const projectPath = path.resolve(TEMP_DIR, projectName); |
| 22 | + |
| 23 | + if (existsSync(projectPath)) { |
| 24 | + rmSync(projectPath, { recursive: true, force: true }); |
| 25 | + } |
| 26 | + |
| 27 | + await execAsync( |
| 28 | + `node ${CREATE_APP_PATH} ${projectName} --template=@testing-library/react-native`, |
| 29 | + { cwd: TEMP_DIR } |
| 30 | + ); |
| 31 | + |
| 32 | + const packageJsonPath = path.join(projectPath, 'package.json'); |
| 33 | + expect(existsSync(packageJsonPath)).toBe(true); |
| 34 | + |
| 35 | + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); |
| 36 | + expect(packageJson.name).toBe(projectName); |
| 37 | + expect(packageJson.version).toBe('1.0.0'); |
| 38 | + expect(packageJson.private).toBe(true); |
| 39 | + expect(packageJson.description).not.toBeDefined(); |
| 40 | + expect(packageJson.author).not.toBeDefined(); |
| 41 | + expect(packageJson.license).not.toBeDefined(); |
| 42 | + expect(packageJson.repository).not.toBeDefined(); |
| 43 | + expect(packageJson.bugs).not.toBeDefined(); |
| 44 | + expect(packageJson.homepage).not.toBeDefined(); |
| 45 | + expect(packageJson.keywords).not.toBeDefined(); |
| 46 | + expect(packageJson.packageManager).not.toBeDefined(); |
| 47 | + }); |
| 48 | + |
| 49 | + it( |
| 50 | + 'should create a new project from local directory template', |
| 51 | + { timeout: 30_000 }, |
| 52 | + async () => { |
| 53 | + const projectName = `test-local-dir-template-${getRandomString(6)}`; |
| 54 | + const projectPath = path.resolve(TEMP_DIR, projectName); |
| 55 | + |
| 56 | + if (existsSync(projectPath)) { |
| 57 | + rmSync(projectPath, { recursive: true, force: true }); |
| 58 | + } |
| 59 | + |
| 60 | + const templatePath = `${TEMPLATES_DIR}/rnef-template-default`; |
| 61 | + await execAsync( |
| 62 | + `node ${CREATE_APP_PATH} ${projectName} --template="${templatePath}"`, |
| 63 | + { cwd: TEMP_DIR } |
| 64 | + ); |
| 65 | + |
| 66 | + const packageJsonPath = path.join(projectPath, 'package.json'); |
| 67 | + expect(existsSync(packageJsonPath)).toBe(true); |
| 68 | + |
| 69 | + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); |
| 70 | + expect(packageJson.name).toBe(projectName); |
| 71 | + expect(packageJson.version).toBe('1.0.0'); |
| 72 | + expect(packageJson.private).toBe(true); |
| 73 | + expect(packageJson.description).not.toBeDefined(); |
| 74 | + expect(packageJson.author).not.toBeDefined(); |
| 75 | + expect(packageJson.license).not.toBeDefined(); |
| 76 | + expect(packageJson.repository).not.toBeDefined(); |
| 77 | + expect(packageJson.bugs).not.toBeDefined(); |
| 78 | + expect(packageJson.homepage).not.toBeDefined(); |
| 79 | + expect(packageJson.keywords).not.toBeDefined(); |
| 80 | + expect(packageJson.packageManager).not.toBeDefined(); |
| 81 | + } |
| 82 | + ); |
| 83 | +}); |
0 commit comments