Skip to content

Commit 98460bb

Browse files
authored
test: add-e2e-tests-batch-1 (#1085)
1 parent 63c748c commit 98460bb

14 files changed

Lines changed: 367 additions & 8 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { runCli } from '../../__helpers__/run-cli.js';
2+
import { createTestActor, removeTestActor, type TestActor } from '../../__helpers__/test-actor.js';
3+
4+
describe('[e2e] actor calculate-memory', () => {
5+
let actor: TestActor;
6+
7+
beforeAll(async () => {
8+
actor = await createTestActor();
9+
});
10+
11+
afterAll(async () => {
12+
if (actor) await removeTestActor(actor);
13+
});
14+
15+
it('calculates memory with --default-memory-mbytes flag', async () => {
16+
const result = await runCli('apify', ['actor', 'calculate-memory', '--default-memory-mbytes', '256'], {
17+
cwd: actor.dir,
18+
});
19+
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
20+
expect(result.stdout).toContain('Calculated memory');
21+
expect(result.stdout).toContain('256');
22+
});
23+
24+
it('errors when no memory expression is found', async () => {
25+
const result = await runCli('apify', ['actor', 'calculate-memory'], {
26+
cwd: actor.dir,
27+
});
28+
expect(result.exitCode).not.toBe(0);
29+
expect(result.stderr).toContain('No memory-calculation expression found');
30+
});
31+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { runCli } from '../../__helpers__/run-cli.js';
2+
import { createTestActor, removeTestActor, type TestActor } from '../../__helpers__/test-actor.js';
3+
4+
describe('[e2e] actor get-value', () => {
5+
let actor: TestActor;
6+
7+
beforeAll(async () => {
8+
actor = await createTestActor();
9+
10+
// Run the actor once so storage is initialized
11+
const runResult = await runCli('apify', ['run'], { cwd: actor.dir });
12+
if (runResult.exitCode !== 0) {
13+
throw new Error(`Test actor failed to run:\n${runResult.stderr}`);
14+
}
15+
});
16+
17+
afterAll(async () => {
18+
if (actor) await removeTestActor(actor);
19+
});
20+
21+
it('gets the value back from the default key-value store', async () => {
22+
// First make sure the value is set
23+
await runCli('apify', ['actor', 'set-value', 'MY_KEY', '{"hello":"world"}'], {
24+
cwd: actor.dir,
25+
});
26+
27+
const result = await runCli('apify', ['actor', 'get-value', 'MY_KEY'], {
28+
cwd: actor.dir,
29+
});
30+
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
31+
expect(result.stdout).toContain('hello');
32+
expect(result.stdout).toContain('world');
33+
});
34+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { mkdir, readdir } from 'node:fs/promises';
2+
import path from 'node:path';
3+
4+
import { runCli } from '../../__helpers__/run-cli.js';
5+
import { createTestActor, removeTestActor, type TestActor } from '../../__helpers__/test-actor.js';
6+
7+
describe('[e2e] actor push-data', () => {
8+
let actor: TestActor;
9+
10+
beforeAll(async () => {
11+
actor = await createTestActor();
12+
13+
// Run the actor once so storage is initialized
14+
const runResult = await runCli('apify', ['run'], { cwd: actor.dir });
15+
if (runResult.exitCode !== 0) {
16+
throw new Error(`Test actor failed to run:\n${runResult.stderr}`);
17+
}
18+
19+
// Ensure the default dataset directory exists for push-data tests
20+
await mkdir(path.join(actor.dir, 'storage', 'datasets', 'default'), { recursive: true });
21+
});
22+
23+
afterAll(async () => {
24+
if (actor) await removeTestActor(actor);
25+
});
26+
27+
it('pushes data to the default dataset', async () => {
28+
const result = await runCli('apify', ['actor', 'push-data', '{"item":"test"}'], {
29+
cwd: actor.dir,
30+
});
31+
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
32+
33+
// Verify a file exists in the dataset directory
34+
const datasetDir = path.join(actor.dir, 'storage', 'datasets', 'default');
35+
const files = await readdir(datasetDir);
36+
expect(files.length).toBeGreaterThan(0);
37+
});
38+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { writeFile } from 'node:fs/promises';
22
import path from 'node:path';
33

4-
import { runCli } from './__helpers__/run-cli.js';
4+
import { runCli } from '../../__helpers__/run-cli.js';
55
import {
66
cleanRunResults,
77
createTestActor,
88
getRunResults,
99
removeTestActor,
1010
type TestActor,
11-
} from './__helpers__/test-actor.js';
11+
} from '../../__helpers__/test-actor.js';
1212

1313
describe('[e2e] actor run input', () => {
1414
let actor: TestActor;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { runCli } from '../../__helpers__/run-cli.js';
2+
import { createTestActor, removeTestActor, type TestActor } from '../../__helpers__/test-actor.js';
3+
4+
describe('[e2e] actor set-value', () => {
5+
let actor: TestActor;
6+
7+
beforeAll(async () => {
8+
actor = await createTestActor();
9+
10+
// Run the actor once so storage is initialized
11+
const runResult = await runCli('apify', ['run'], { cwd: actor.dir });
12+
if (runResult.exitCode !== 0) {
13+
throw new Error(`Test actor failed to run:\n${runResult.stderr}`);
14+
}
15+
});
16+
17+
afterAll(async () => {
18+
if (actor) await removeTestActor(actor);
19+
});
20+
21+
it('sets a value in the default key-value store', async () => {
22+
const result = await runCli('apify', ['actor', 'set-value', 'MY_KEY', '{"hello":"world"}'], {
23+
cwd: actor.dir,
24+
});
25+
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
26+
});
27+
});

test/e2e/builds.test.ts renamed to test/e2e/commands/builds/create-info-ls.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { randomBytes } from 'node:crypto';
22

33
import { ApifyClient } from 'apify-client';
44

5-
import { getApifyClientOptions } from '../../src/lib/utils.js';
6-
import { runCli } from './__helpers__/run-cli.js';
7-
import { createTestActor, removeTestActor, type TestActor } from './__helpers__/test-actor.js';
5+
import { getApifyClientOptions } from '../../../../src/lib/utils.js';
6+
import { runCli } from '../../__helpers__/run-cli.js';
7+
import { createTestActor, removeTestActor, type TestActor } from '../../__helpers__/test-actor.js';
88

99
describe('[e2e][api] builds namespace', () => {
1010
let actor: TestActor;

test/e2e/commands/create.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { runCli } from './__helpers__/run-cli.js';
1+
import { runCli } from '../__helpers__/run-cli.js';
22

33
describe.concurrent('[e2e] help command', () => {
44
it('apify help prints the full help message', async () => {

test/e2e/commands/init.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 init', () => {
11+
let tmpDir: string;
12+
13+
beforeAll(async () => {
14+
const dirName = `e2e-init-${randomBytes(6).toString('hex')}`;
15+
tmpDir = path.join(TestTmpRoot, dirName);
16+
await mkdir(tmpDir, { recursive: true });
17+
});
18+
19+
afterAll(async () => {
20+
await rm(tmpDir, { recursive: true, force: true });
21+
});
22+
23+
it('initializes an actor project in an empty directory with --yes', async () => {
24+
const result = await runCli('apify', ['init', 'my-test-actor', '--yes'], { cwd: tmpDir });
25+
26+
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
27+
expect(result.stderr).toContain('The Actor has been initialized in the current directory.');
28+
29+
// Verify .actor/actor.json exists
30+
await expect(access(path.join(tmpDir, '.actor', 'actor.json'))).resolves.toBeUndefined();
31+
});
32+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { runCli } from './__helpers__/run-cli.js';
2-
import { corruptActorJson, createTestActor, removeTestActor, type TestActor } from './__helpers__/test-actor.js';
1+
import { runCli } from '../__helpers__/run-cli.js';
2+
import { corruptActorJson, createTestActor, removeTestActor, type TestActor } from '../__helpers__/test-actor.js';
33

44
describe('[e2e] invalid actor.json', () => {
55
let actor: TestActor;

0 commit comments

Comments
 (0)