apify-test-tools 0.10.2-beta.1 → 0.10.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/.github/actions/checkout-restore-dependencies/action.yaml +13 -29
- package/.github/cli/apify-test-tools.mjs +361 -0
- package/.github/scripts/run-with-apify-tokens.mjs +2 -2
- package/.github/workflows/_check_code.yaml +25 -0
- package/.github/workflows/_move_major_tag.yaml +3 -81
- package/.github/workflows/_tests.yaml +34 -0
- package/.github/workflows/_update_release_metadata.yaml +0 -12
- package/.github/workflows/manual_move_major_tag.yaml +3 -3
- package/.github/workflows/manual_release_stable.yaml +3 -13
- package/.github/workflows/on_master.yaml +9 -5
- package/.github/workflows/on_pull_request.yaml +3 -48
- package/.github/workflows/public_platform-tests.yaml +1 -1
- package/.github/workflows/public_pr-build-test.yaml +2 -2
- package/.github/workflows/public_push-build-latest.yaml +2 -2
- package/.husky/pre-commit +5 -0
- package/.prettierignore +3 -0
- package/CHANGELOG.md +5 -0
- package/CONTRIBUTING.md +8 -18
- package/README.md +94 -44
- package/bin/affected-actors.ts +166 -0
- package/bin/build-from-local.ts +47 -13
- package/bin/build.ts +35 -19
- package/bin/diff-changes.ts +25 -17
- package/bin/git.ts +52 -41
- package/bin/main.ts +63 -78
- package/bin/slack.ts +28 -6
- package/bin/test-report.ts +6 -9
- package/bin/types.ts +9 -0
- package/dist/bin/affected-actors.d.ts +50 -0
- package/dist/bin/affected-actors.d.ts.map +1 -0
- package/dist/bin/affected-actors.js +89 -0
- package/dist/bin/affected-actors.js.map +1 -0
- package/dist/bin/build-from-local.d.ts +10 -2
- package/dist/bin/build-from-local.d.ts.map +1 -1
- package/dist/bin/build-from-local.js +29 -11
- package/dist/bin/build-from-local.js.map +1 -1
- package/dist/bin/build.d.ts +15 -5
- package/dist/bin/build.d.ts.map +1 -1
- package/dist/bin/build.js +24 -15
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/diff-changes.d.ts +8 -2
- package/dist/bin/diff-changes.d.ts.map +1 -1
- package/dist/bin/diff-changes.js +16 -16
- package/dist/bin/diff-changes.js.map +1 -1
- package/dist/bin/git.d.ts +23 -13
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +44 -32
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/main.js +57 -57
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +8 -1
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +26 -5
- package/dist/bin/slack.js.map +1 -1
- package/dist/bin/test-report.d.ts.map +1 -1
- package/dist/bin/test-report.js +6 -8
- package/dist/bin/test-report.js.map +1 -1
- package/dist/bin/types.d.ts +8 -0
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/test/bundle/cli-bundle.test.d.ts +2 -0
- package/dist/test/bundle/cli-bundle.test.d.ts.map +1 -0
- package/dist/test/bundle/cli-bundle.test.js +169 -0
- package/dist/test/bundle/cli-bundle.test.js.map +1 -0
- package/dist/test/e2e/cli-bundle.e2e.test.d.ts +2 -0
- package/dist/test/e2e/cli-bundle.e2e.test.d.ts.map +1 -0
- package/dist/test/e2e/cli-bundle.e2e.test.js +172 -0
- package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -0
- package/dist/test/unit/bin/affected-actors.test.d.ts +2 -0
- package/dist/test/unit/bin/affected-actors.test.d.ts.map +1 -0
- package/dist/test/unit/bin/affected-actors.test.js +160 -0
- package/dist/test/unit/bin/affected-actors.test.js.map +1 -0
- package/dist/test/unit/bin/build-from-local.test.js +53 -1
- package/dist/test/unit/bin/build-from-local.test.js.map +1 -1
- package/dist/test/unit/bin/build.test.js +113 -3
- package/dist/test/unit/bin/build.test.js.map +1 -1
- package/dist/test/unit/bin/diff-changes.test.js +78 -49
- package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
- package/dist/test/unit/bin/git.test.js +50 -53
- package/dist/test/unit/bin/git.test.js.map +1 -1
- package/dist/test/unit/bin/slack.test.d.ts +2 -0
- package/dist/test/unit/bin/slack.test.d.ts.map +1 -0
- package/dist/test/unit/bin/slack.test.js +54 -0
- package/dist/test/unit/bin/slack.test.js.map +1 -0
- package/dist/test/unit/should-built-and-test.test.js +23 -17
- package/dist/test/unit/should-built-and-test.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -3
- package/test/bundle/cli-bundle.test.ts +199 -0
- package/test/e2e/cli-bundle.e2e.test.ts +237 -0
- package/test/unit/bin/affected-actors.test.ts +190 -0
- package/test/unit/bin/build-from-local.test.ts +55 -0
- package/test/unit/bin/build.test.ts +135 -3
- package/test/unit/bin/diff-changes.test.ts +87 -49
- package/test/unit/bin/git.test.ts +56 -53
- package/test/unit/bin/slack.test.ts +65 -0
- package/test/unit/should-built-and-test.test.ts +27 -17
- package/.github/scripts/check-package-version-bump.mjs +0 -74
- package/.github/workflows-package-version +0 -1
|
@@ -4,11 +4,13 @@ import path from 'node:path';
|
|
|
4
4
|
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
|
|
7
|
+
import { ApifyBuilder } from '../../../bin/build.js';
|
|
7
8
|
import {
|
|
8
9
|
collectNonIgnoredFiles,
|
|
9
10
|
collectSourceFiles,
|
|
10
11
|
flattenMonorepoContext,
|
|
11
12
|
rewriteActorJsonPaths,
|
|
13
|
+
runBuildsFromLocal,
|
|
12
14
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
15
|
// @ts-ignore: editor-only TS6059 — test/tsconfig.json's rootDir doesn't span bin/, but the root
|
|
14
16
|
// tsconfig (used for the real build and for eslint's type-aware linting) has no such restriction.
|
|
@@ -235,4 +237,57 @@ describe('build-from-local helpers', () => {
|
|
|
235
237
|
expect(rewritten.changelog).toBe('./CHANGELOG.md');
|
|
236
238
|
});
|
|
237
239
|
});
|
|
240
|
+
|
|
241
|
+
describe('runBuildsFromLocal dry run', () => {
|
|
242
|
+
it('looks the Actor up and zips its sources, but builds nothing', async () => {
|
|
243
|
+
const repoRoot = await mkTempDir('apify-test-tools-dry-run-');
|
|
244
|
+
tempDirs.push(repoRoot);
|
|
245
|
+
const actorDir = path.join(repoRoot, 'actors', 'owner_actor');
|
|
246
|
+
await fs.mkdir(path.join(actorDir, '.actor'), { recursive: true });
|
|
247
|
+
await fs.writeFile(path.join(actorDir, '.actor', 'actor.json'), JSON.stringify({ name: 'actor' }));
|
|
248
|
+
await fs.writeFile(path.join(actorDir, 'main.js'), '');
|
|
249
|
+
vi.spyOn(Utils, 'listRepoFilePaths').mockResolvedValue([
|
|
250
|
+
'actors/owner_actor/.actor/actor.json',
|
|
251
|
+
'actors/owner_actor/main.js',
|
|
252
|
+
]);
|
|
253
|
+
vi.spyOn(Utils, 'getGitignoredPaths').mockResolvedValue(new Set());
|
|
254
|
+
|
|
255
|
+
const getActorInfo = vi.fn(async () => ({}));
|
|
256
|
+
const fromActorConfig = vi
|
|
257
|
+
.spyOn(ApifyBuilder, 'fromActorConfig')
|
|
258
|
+
.mockReturnValue({ getActorInfo } as unknown as ApifyBuilder);
|
|
259
|
+
|
|
260
|
+
const originalCwd = process.cwd();
|
|
261
|
+
process.chdir(repoRoot);
|
|
262
|
+
try {
|
|
263
|
+
const plan = await runBuildsFromLocal({
|
|
264
|
+
actorConfigs: [
|
|
265
|
+
{
|
|
266
|
+
actorFullName: 'owner/actor',
|
|
267
|
+
folder: new ExistingDir('actors/owner_actor'),
|
|
268
|
+
tokenEnvVar: 'APIFY_TOKEN_OWNER',
|
|
269
|
+
actorJson: {
|
|
270
|
+
file: new ExistingFile('actors/owner_actor/.actor/actor.json'),
|
|
271
|
+
dockerContextDir: new RelativeDir('actors/owner_actor'),
|
|
272
|
+
},
|
|
273
|
+
dockerContextDir: new RelativeDir('actors/owner_actor'),
|
|
274
|
+
contextPaths: [new RelativeDir('actors/owner_actor')],
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
dryRun: true,
|
|
278
|
+
});
|
|
279
|
+
expect(plan).toEqual({
|
|
280
|
+
dryRun: true,
|
|
281
|
+
builds: [
|
|
282
|
+
expect.objectContaining({ actorFullName: 'owner/actor', versionNumber: '0.98', fileCount: 2 }),
|
|
283
|
+
],
|
|
284
|
+
});
|
|
285
|
+
} finally {
|
|
286
|
+
process.chdir(originalCwd);
|
|
287
|
+
}
|
|
288
|
+
expect(getActorInfo).toHaveBeenCalledTimes(1);
|
|
289
|
+
// Only the read-only lookup ran: builders for uploads and builds are created after the dry-run cutoff
|
|
290
|
+
expect(fromActorConfig).toHaveBeenCalledTimes(1);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
238
293
|
});
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
1
5
|
import type * as ApifyClientTypes from 'apify-client';
|
|
2
|
-
import { ActorSourceType } from 'apify-client';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { ActorSourceType, ApifyClient } from 'apify-client';
|
|
7
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
assertRepoUrlMatchesDefaultVersion,
|
|
11
|
+
deleteOldBuilds,
|
|
12
|
+
resolveDefaultVersion,
|
|
13
|
+
runBuilds,
|
|
14
|
+
} from '../../../bin/build.js';
|
|
15
|
+
import type { ActorConfig } from '../../../bin/types.js';
|
|
16
|
+
import { ExistingDir, ExistingFile, RelativeDir } from '../../../bin/utils/path/repo-relative.js';
|
|
4
17
|
|
|
5
|
-
|
|
18
|
+
// Only the client is faked, so the tests exercise the real builder code against a stubbed API
|
|
19
|
+
vi.mock('apify-client', async (importOriginal) => {
|
|
20
|
+
const actual = await importOriginal<typeof ApifyClientTypes>();
|
|
21
|
+
return { ...actual, ApifyClient: vi.fn() };
|
|
22
|
+
});
|
|
6
23
|
|
|
7
24
|
const ACTOR = 'owner/actor';
|
|
8
25
|
const REPO_URL = 'git@github.com:owner/repo';
|
|
@@ -66,3 +83,118 @@ describe('assertRepoUrlMatchesDefaultVersion', () => {
|
|
|
66
83
|
expect(() => assertRepoUrlMatchesDefaultVersion(ACTOR, undefined, REPO_URL)).toThrow('no longer exists');
|
|
67
84
|
});
|
|
68
85
|
});
|
|
86
|
+
|
|
87
|
+
describe('dry run', () => {
|
|
88
|
+
const TOKEN_ENV_VAR = 'APIFY_TOKEN_OWNER';
|
|
89
|
+
const originalCwd = process.cwd();
|
|
90
|
+
let fixtureRoot: string;
|
|
91
|
+
let actorConfig: ActorConfig;
|
|
92
|
+
|
|
93
|
+
// ExistingDir checks the folder exists, so the config is built inside a throwaway repo root
|
|
94
|
+
beforeAll(() => {
|
|
95
|
+
fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'apify-build-dry-run-'));
|
|
96
|
+
process.chdir(fixtureRoot);
|
|
97
|
+
fs.mkdirSync('actors/a/.actor', { recursive: true });
|
|
98
|
+
fs.writeFileSync('actors/a/.actor/actor.json', '{}');
|
|
99
|
+
actorConfig = {
|
|
100
|
+
actorFullName: ACTOR,
|
|
101
|
+
folder: new ExistingDir('actors/a'),
|
|
102
|
+
tokenEnvVar: TOKEN_ENV_VAR,
|
|
103
|
+
actorJson: {
|
|
104
|
+
file: new ExistingFile('actors/a/.actor/actor.json'),
|
|
105
|
+
dockerContextDir: new RelativeDir('actors/a'),
|
|
106
|
+
},
|
|
107
|
+
dockerContextDir: new RelativeDir('actors/a'),
|
|
108
|
+
contextPaths: [new RelativeDir('actors/a')],
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
afterAll(() => {
|
|
113
|
+
process.chdir(originalCwd);
|
|
114
|
+
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
|
115
|
+
});
|
|
116
|
+
const deleteBuild = vi.fn();
|
|
117
|
+
const startBuild = vi.fn();
|
|
118
|
+
const createVersion = vi.fn();
|
|
119
|
+
const buildClient = vi.fn(() => ({ delete: deleteBuild }));
|
|
120
|
+
|
|
121
|
+
beforeEach(() => {
|
|
122
|
+
vi.stubEnv(TOKEN_ENV_VAR, 'token');
|
|
123
|
+
const fakeClient = {
|
|
124
|
+
actor: () => ({
|
|
125
|
+
get: async () => makeActorInfo(),
|
|
126
|
+
// Old enough to be deleted, and not the default build 0.1.5
|
|
127
|
+
builds: () => ({
|
|
128
|
+
list: async () => ({ items: [{ id: 'old-build', buildNumber: '0.0.1', startedAt: new Date(0) }] }),
|
|
129
|
+
}),
|
|
130
|
+
versions: () => ({ create: createVersion }),
|
|
131
|
+
version: () => ({ update: createVersion }),
|
|
132
|
+
build: startBuild,
|
|
133
|
+
}),
|
|
134
|
+
build: buildClient,
|
|
135
|
+
};
|
|
136
|
+
vi.mocked(ApifyClient).mockImplementation(function () {
|
|
137
|
+
return fakeClient;
|
|
138
|
+
} as never);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
afterEach(() => {
|
|
142
|
+
vi.unstubAllEnvs();
|
|
143
|
+
vi.clearAllMocks();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const runDryBuilds = async () =>
|
|
147
|
+
runBuilds({
|
|
148
|
+
actorConfigs: [actorConfig],
|
|
149
|
+
repoUrl: REPO_URL,
|
|
150
|
+
shouldVerifyRepoUrl: true,
|
|
151
|
+
branch: 'feature',
|
|
152
|
+
dryRun: true,
|
|
153
|
+
useDockerCache: false,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should return a build plan without creating versions or builds', async () => {
|
|
157
|
+
expect(await runDryBuilds()).toEqual({
|
|
158
|
+
dryRun: true,
|
|
159
|
+
builds: [
|
|
160
|
+
{
|
|
161
|
+
actorFullName: ACTOR,
|
|
162
|
+
versionNumber: '0.99',
|
|
163
|
+
gitRepoUrl: `${REPO_URL}#feature:actors/a`,
|
|
164
|
+
useDockerCache: false,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
});
|
|
168
|
+
expect(createVersion).not.toHaveBeenCalled();
|
|
169
|
+
expect(startBuild).not.toHaveBeenCalled();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should still require the Apify token', async () => {
|
|
173
|
+
vi.stubEnv(TOKEN_ENV_VAR, '');
|
|
174
|
+
await expect(runDryBuilds()).rejects.toThrow(`Env var ${TOKEN_ENV_VAR} is not set`);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should still check the repository URL', async () => {
|
|
178
|
+
await expect(
|
|
179
|
+
runBuilds({
|
|
180
|
+
actorConfigs: [actorConfig],
|
|
181
|
+
repoUrl: 'git@github.com:fork/repo',
|
|
182
|
+
shouldVerifyRepoUrl: true,
|
|
183
|
+
branch: 'feature',
|
|
184
|
+
dryRun: true,
|
|
185
|
+
useDockerCache: false,
|
|
186
|
+
}),
|
|
187
|
+
).rejects.toThrow('Repository mismatch');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should not delete old builds', async () => {
|
|
191
|
+
await deleteOldBuilds([actorConfig], { dryRun: true });
|
|
192
|
+
expect(deleteBuild).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should delete old builds outside of a dry run', async () => {
|
|
196
|
+
await deleteOldBuilds([actorConfig], { dryRun: false });
|
|
197
|
+
expect(buildClient).toHaveBeenCalledWith('old-build');
|
|
198
|
+
expect(deleteBuild).toHaveBeenCalledTimes(1);
|
|
199
|
+
});
|
|
200
|
+
});
|