|
| 1 | +import { randomBytes } from 'node:crypto'; |
| 2 | +import { access, mkdir, rm } from 'node:fs/promises'; |
| 3 | +import path from 'node:path'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +import { runCli } from '../__helpers__/run-cli.js'; |
| 7 | + |
| 8 | +const TestTmpRoot = fileURLToPath(new URL('../../../tmp/', import.meta.url)); |
| 9 | + |
| 10 | +describe('[e2e] apify create', () => { |
| 11 | + let tmpDir: string; |
| 12 | + const createdDirs: string[] = []; |
| 13 | + |
| 14 | + beforeAll(async () => { |
| 15 | + const dirName = `e2e-create-${randomBytes(6).toString('hex')}`; |
| 16 | + tmpDir = path.join(TestTmpRoot, dirName); |
| 17 | + await mkdir(tmpDir, { recursive: true }); |
| 18 | + }); |
| 19 | + |
| 20 | + afterAll(async () => { |
| 21 | + for (const dir of createdDirs) { |
| 22 | + await rm(dir, { recursive: true, force: true }); |
| 23 | + } |
| 24 | + await rm(tmpDir, { recursive: true, force: true }); |
| 25 | + }); |
| 26 | + |
| 27 | + it('creates an actor project with --template project_empty --skip-dependency-install', async () => { |
| 28 | + const actorName = `test-actor-${randomBytes(4).toString('hex')}`; |
| 29 | + const actorDir = path.join(tmpDir, actorName); |
| 30 | + createdDirs.push(actorDir); |
| 31 | + |
| 32 | + const result = await runCli( |
| 33 | + 'apify', |
| 34 | + ['create', actorName, '--template', 'project_empty', '--skip-dependency-install'], |
| 35 | + { |
| 36 | + cwd: tmpDir, |
| 37 | + }, |
| 38 | + ); |
| 39 | + |
| 40 | + expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0); |
| 41 | + expect(result.stderr).toContain('created successfully'); |
| 42 | + |
| 43 | + // Verify directory structure |
| 44 | + await expect(access(actorDir)).resolves.toBeUndefined(); |
| 45 | + await expect(access(path.join(actorDir, '.actor', 'actor.json'))).resolves.toBeUndefined(); |
| 46 | + await expect(access(path.join(actorDir, 'src'))).resolves.toBeUndefined(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('fails when creating in a directory that already exists with content', async () => { |
| 50 | + const actorName = `test-actor-${randomBytes(4).toString('hex')}`; |
| 51 | + const actorDir = path.join(tmpDir, actorName); |
| 52 | + createdDirs.push(actorDir); |
| 53 | + |
| 54 | + // First create succeeds |
| 55 | + const first = await runCli( |
| 56 | + 'apify', |
| 57 | + ['create', actorName, '--template', 'project_empty', '--skip-dependency-install'], |
| 58 | + { |
| 59 | + cwd: tmpDir, |
| 60 | + }, |
| 61 | + ); |
| 62 | + expect(first.exitCode, `stderr: ${first.stderr}`).toBe(0); |
| 63 | + |
| 64 | + // Second create in same dir should fail |
| 65 | + const second = await runCli( |
| 66 | + 'apify', |
| 67 | + ['create', actorName, '--template', 'project_empty', '--skip-dependency-install'], |
| 68 | + { |
| 69 | + cwd: tmpDir, |
| 70 | + }, |
| 71 | + ); |
| 72 | + expect(second.exitCode).not.toBe(0); |
| 73 | + }); |
| 74 | +}); |
0 commit comments