apify-test-tools 0.10.2-beta.0 → 0.10.2-beta.10
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 +64 -27
- package/.github/cli/apify-test-tools.mjs +360 -0
- package/.github/scripts/check-major-tag-refs.mjs +1 -1
- package/.github/scripts/mask-config-secrets.sh +17 -0
- package/.github/scripts/run-with-apify-tokens.mjs +37 -12
- 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-claude-investigate-and-fix.yaml +13 -2
- package/.github/workflows/public_platform-tests.yaml +24 -1
- package/.github/workflows/public_pr-build-test.yaml +62 -49
- package/.github/workflows/public_push-build-latest.yaml +41 -8
- package/.husky/pre-commit +5 -0
- package/.prettierignore +3 -0
- package/CHANGELOG.md +17 -0
- package/CONTRIBUTING.md +105 -21
- package/README.md +218 -597
- package/bin/affected-actors.ts +198 -0
- package/bin/build-from-local.ts +65 -13
- package/bin/build.ts +123 -41
- package/bin/diff-changes.ts +55 -25
- package/bin/diff-json-schema.ts +5 -6
- package/bin/git.ts +69 -99
- package/bin/main.ts +96 -122
- package/bin/slack.ts +43 -10
- package/bin/stdin-input.ts +65 -0
- package/bin/test-report.ts +6 -9
- package/bin/types.ts +16 -0
- package/dist/bin/affected-actors.d.ts +46 -0
- package/dist/bin/affected-actors.d.ts.map +1 -0
- package/dist/bin/affected-actors.js +135 -0
- package/dist/bin/affected-actors.js.map +1 -0
- package/dist/bin/build-from-local.d.ts +12 -3
- package/dist/bin/build-from-local.d.ts.map +1 -1
- package/dist/bin/build-from-local.js +34 -12
- package/dist/bin/build-from-local.js.map +1 -1
- package/dist/bin/build.d.ts +30 -7
- package/dist/bin/build.d.ts.map +1 -1
- package/dist/bin/build.js +85 -26
- package/dist/bin/build.js.map +1 -1
- package/dist/bin/diff-changes.d.ts +12 -4
- package/dist/bin/diff-changes.d.ts.map +1 -1
- package/dist/bin/diff-changes.js +31 -20
- package/dist/bin/diff-changes.js.map +1 -1
- package/dist/bin/diff-json-schema.d.ts +2 -2
- package/dist/bin/diff-json-schema.d.ts.map +1 -1
- package/dist/bin/diff-json-schema.js +1 -4
- package/dist/bin/diff-json-schema.js.map +1 -1
- package/dist/bin/git.d.ts +23 -21
- package/dist/bin/git.d.ts.map +1 -1
- package/dist/bin/git.js +60 -83
- package/dist/bin/git.js.map +1 -1
- package/dist/bin/main.js +82 -93
- package/dist/bin/main.js.map +1 -1
- package/dist/bin/slack.d.ts +14 -4
- package/dist/bin/slack.d.ts.map +1 -1
- package/dist/bin/slack.js +39 -6
- package/dist/bin/slack.js.map +1 -1
- package/dist/bin/stdin-input.d.ts +17 -0
- package/dist/bin/stdin-input.d.ts.map +1 -0
- package/dist/bin/stdin-input.js +54 -0
- package/dist/bin/stdin-input.js.map +1 -0
- 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 +14 -0
- package/dist/bin/types.d.ts.map +1 -1
- package/dist/lib/extend-expect.d.ts.map +1 -1
- package/dist/lib/extend-expect.js +37 -218
- package/dist/lib/extend-expect.js.map +1 -1
- package/dist/lib/lib.d.ts +1 -2
- package/dist/lib/lib.d.ts.map +1 -1
- package/dist/lib/lib.js +15 -22
- package/dist/lib/lib.js.map +1 -1
- package/dist/lib/run-checks.d.ts +14 -0
- package/dist/lib/run-checks.d.ts.map +1 -0
- package/dist/lib/run-checks.js +82 -0
- package/dist/lib/run-checks.js.map +1 -0
- package/dist/lib/run-test-result.d.ts +3 -6
- package/dist/lib/run-test-result.d.ts.map +1 -1
- package/dist/lib/run-test-result.js +41 -54
- package/dist/lib/run-test-result.js.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 +190 -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 +138 -0
- package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -0
- package/dist/test/e2e/git-build-release.e2e.test.d.ts +2 -0
- package/dist/test/e2e/git-build-release.e2e.test.d.ts.map +1 -0
- package/dist/test/e2e/git-build-release.e2e.test.js +87 -0
- package/dist/test/e2e/git-build-release.e2e.test.js.map +1 -0
- package/dist/test/e2e/helpers.d.ts +37 -0
- package/dist/test/e2e/helpers.d.ts.map +1 -0
- package/dist/test/e2e/helpers.js +57 -0
- package/dist/test/e2e/helpers.js.map +1 -0
- package/dist/test/unit/bin/affected-actors-cli.test.d.ts +2 -0
- package/dist/test/unit/bin/affected-actors-cli.test.d.ts.map +1 -0
- package/dist/test/unit/bin/affected-actors-cli.test.js +167 -0
- package/dist/test/unit/bin/affected-actors-cli.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 +141 -0
- package/dist/test/unit/bin/affected-actors.test.js.map +1 -0
- package/dist/test/unit/bin/build-cli.test.d.ts +2 -0
- package/dist/test/unit/bin/build-cli.test.d.ts.map +1 -0
- package/dist/test/unit/bin/build-cli.test.js +44 -0
- package/dist/test/unit/bin/build-cli.test.js.map +1 -0
- package/dist/test/unit/bin/build-from-local.test.js +65 -1
- package/dist/test/unit/bin/build-from-local.test.js.map +1 -1
- package/dist/test/unit/bin/build.test.js +223 -3
- package/dist/test/unit/bin/build.test.js.map +1 -1
- package/dist/test/unit/bin/compiled-cli.d.ts +6 -0
- package/dist/test/unit/bin/compiled-cli.d.ts.map +1 -0
- package/dist/test/unit/bin/compiled-cli.js +16 -0
- package/dist/test/unit/bin/compiled-cli.js.map +1 -0
- package/dist/test/unit/bin/diff-changes.test.js +205 -85
- package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
- package/dist/test/unit/bin/diff.test.js +25 -28
- package/dist/test/unit/bin/diff.test.js.map +1 -1
- package/dist/test/unit/bin/git.test.js +69 -152
- 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 +71 -0
- package/dist/test/unit/bin/slack.test.js.map +1 -0
- package/dist/test/unit/bin/stdin-input.test.d.ts +2 -0
- package/dist/test/unit/bin/stdin-input.test.d.ts.map +1 -0
- package/dist/test/unit/bin/stdin-input.test.js +50 -0
- package/dist/test/unit/bin/stdin-input.test.js.map +1 -0
- package/dist/test/unit/github-scripts/mask-config-secrets.test.d.ts +2 -0
- package/dist/test/unit/github-scripts/mask-config-secrets.test.d.ts.map +1 -0
- package/dist/test/unit/github-scripts/mask-config-secrets.test.js +50 -0
- package/dist/test/unit/github-scripts/mask-config-secrets.test.js.map +1 -0
- package/dist/test/unit/github-scripts/run-with-apify-tokens.test.d.ts +2 -0
- package/dist/test/unit/github-scripts/run-with-apify-tokens.test.d.ts.map +1 -0
- package/dist/test/unit/github-scripts/run-with-apify-tokens.test.js +102 -0
- package/dist/test/unit/github-scripts/run-with-apify-tokens.test.js.map +1 -0
- package/dist/test/unit/run-checks.test.d.ts +2 -0
- package/dist/test/unit/run-checks.test.d.ts.map +1 -0
- package/dist/test/unit/run-checks.test.js +62 -0
- package/dist/test/unit/run-checks.test.js.map +1 -0
- package/dist/test/unit/run-test-result.test.d.ts +2 -0
- package/dist/test/unit/run-test-result.test.d.ts.map +1 -0
- package/dist/test/unit/run-test-result.test.js +34 -0
- package/dist/test/unit/run-test-result.test.js.map +1 -0
- package/dist/test/unit/should-built-and-test.test.js +41 -38
- package/dist/test/unit/should-built-and-test.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/cli.md +373 -0
- package/docs/lib.md +271 -0
- package/docs/workflows.md +367 -0
- package/lib/extend-expect.ts +48 -258
- package/lib/lib.ts +24 -28
- package/lib/run-checks.ts +101 -0
- package/lib/run-test-result.ts +45 -55
- package/package.json +15 -3
- package/test/bundle/cli-bundle.test.ts +235 -0
- package/test/e2e/cli-bundle.e2e.test.ts +207 -0
- package/test/e2e/git-build-release.e2e.test.ts +113 -0
- package/test/e2e/helpers.ts +82 -0
- package/test/unit/bin/affected-actors-cli.test.ts +201 -0
- package/test/unit/bin/affected-actors.test.ts +182 -0
- package/test/unit/bin/build-cli.test.ts +55 -0
- package/test/unit/bin/build-from-local.test.ts +71 -0
- package/test/unit/bin/build.test.ts +279 -3
- package/test/unit/bin/compiled-cli.ts +17 -0
- package/test/unit/bin/diff-changes.test.ts +229 -85
- package/test/unit/bin/diff.test.ts +25 -28
- package/test/unit/bin/git.test.ts +85 -176
- package/test/unit/bin/slack.test.ts +84 -0
- package/test/unit/bin/stdin-input.test.ts +61 -0
- package/test/unit/github-scripts/mask-config-secrets.test.ts +61 -0
- package/test/unit/github-scripts/run-with-apify-tokens.test.ts +115 -0
- package/test/unit/run-checks.test.ts +76 -0
- package/test/unit/run-test-result.test.ts +44 -0
- package/test/unit/should-built-and-test.test.ts +46 -39
- package/.github/scripts/check-package-version-bump.mjs +0 -74
- package/.github/workflows-package-version +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,71 @@
|
|
|
1
1
|
# Apify Test Tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build, test and release Apify Actors from a Git repository or local source code. The package has three parts:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. **A vitest library** for writing platform tests that run your Actors on Apify and check the results:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
testActor('myteam/web-scraper', 'scrapes the start URL', async ({ expect, run }) => {
|
|
9
|
+
const runResult = await run({ input: { startUrls: [{ url: 'https://apify.com' }] } });
|
|
10
|
+
await expect(runResult).toFinishWith({ datasetItemCount: { min: 1, max: 10 } });
|
|
11
|
+
});
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
2. **A CLI** that finds the Actors a change affects, builds them, and reports the results. It runs anywhere, so you
|
|
15
|
+
can build your own pipeline on it in any CI:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx apify-test-tools get-affected-actors --base origin/master \
|
|
19
|
+
| jq '{ actors: .functionallyChangedActors }' \
|
|
20
|
+
| npx apify-test-tools build --version-number 0.99
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. **Ready-made GitHub Actions workflows** built on the CLI and the library, so a GitHub repo needs only a few lines
|
|
24
|
+
per workflow:
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
jobs:
|
|
28
|
+
buildDevelAndTest:
|
|
29
|
+
uses: apify/apify-test-tools/.github/workflows/public_pr-build-test.yaml@workflows-v0
|
|
30
|
+
secrets:
|
|
31
|
+
TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }}
|
|
32
|
+
# One entry per secret apify-test-tools.config.json names, today each `tokenEnvVar`
|
|
33
|
+
CONFIG_SECRETS: |
|
|
34
|
+
{ "APIFY_TOKEN_MYTEAM": "${{ secrets.APIFY_TOKEN_MYTEAM }}" }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Most repos only need the library and the workflows: the workflows call the CLI for you. Use the CLI directly only to
|
|
38
|
+
build your own pipeline, e.g. on a CI platform other than GitHub, or to build and test locally.
|
|
39
|
+
|
|
40
|
+
## Only what changed is retested
|
|
41
|
+
|
|
42
|
+
Builds and platform tests cost time and money, so the tool skips everything a change can't affect:
|
|
43
|
+
|
|
44
|
+
- **Only affected Actors.** A changed file only counts for the Actors whose build context it falls in, minus their
|
|
45
|
+
`.dockerignore`. In a monorepo, a change to one Actor doesn't build or test the others.
|
|
46
|
+
- **Cosmetic changes skip tests.** README, CHANGELOG and formatting-only schema changes don't trigger tests on a PR;
|
|
47
|
+
they're only rebuilt when released.
|
|
48
|
+
- **Only new changes on a PR.** Each push to a PR retests only the Actors that changed since its last green run, not
|
|
49
|
+
the whole PR again.
|
|
50
|
+
- **Only their tests.** Only the tests of the Actors that were built run.
|
|
51
|
+
|
|
52
|
+
See [Change detection](docs/cli.md#change-detection) for the exact rules.
|
|
53
|
+
|
|
54
|
+
This README covers what you need to get a repo running. The full reference lives in `docs/`:
|
|
55
|
+
|
|
56
|
+
- [Vitest library API](docs/lib.md) — `testActor`, `testStandbyActor`, `RunTestResult`, matchers, running tests locally
|
|
57
|
+
- [CLI API](docs/cli.md) — every command, change detection, releasing, building locally
|
|
58
|
+
- [Workflow API](docs/workflows.md) — every GitHub workflow, its inputs and secrets, versioning
|
|
59
|
+
|
|
60
|
+
[Contributing](CONTRIBUTING.md)
|
|
61
|
+
|
|
62
|
+
## Getting started
|
|
63
|
+
|
|
64
|
+
Your Actors can be written in any programming language, e.g. Python: anything the platform builds from a Dockerfile
|
|
65
|
+
works. Only the tests and this tooling run on Node.js, so all a repo needs is a `package.json` at the root with
|
|
66
|
+
`apify-test-tools` and `vitest` in its `devDependencies`, and tests written in TypeScript or JavaScript. If you use the
|
|
67
|
+
[PR workflow](docs/workflows.md#public_pr-build-testyaml), also define the `build-check`, `lint` and `test` scripts
|
|
68
|
+
its static checks run, e.g. with your language's own linter and unit tests.
|
|
6
69
|
|
|
7
70
|
### 1. Install the package
|
|
8
71
|
|
|
@@ -10,118 +73,87 @@
|
|
|
10
73
|
npm i -D apify-test-tools
|
|
11
74
|
```
|
|
12
75
|
|
|
13
|
-
- Requires `vitest` version `3.2.
|
|
76
|
+
- Requires `vitest` version `3.2.4` or later (uses [annotate](https://vitest.dev/guide/test-context.html#annotate))
|
|
14
77
|
- Make sure `target` and `module` in your `tsconfig.json`'s `compilerOptions` are set to `ES2022`
|
|
15
78
|
- Every Actor must already have at least one build under its default build tag (usually `latest`), built
|
|
16
79
|
from a Git repository version whose URL points to this repository. Build it once manually on the
|
|
17
|
-
platform before CI takes over. See [Repository check](#repository-check).
|
|
80
|
+
platform before CI takes over. See [Repository check](docs/cli.md#repository-check).
|
|
18
81
|
|
|
19
82
|
### 2. Create the config file
|
|
20
83
|
|
|
21
|
-
Every repo
|
|
84
|
+
Every repo must have an `apify-test-tools.config.json` file at the root that lists its Actors. See
|
|
85
|
+
[Config file](#config-file) below.
|
|
22
86
|
|
|
23
|
-
|
|
87
|
+
### 3. Set up Actor folders
|
|
24
88
|
|
|
25
|
-
|
|
89
|
+
Each Actor in the config must have a `.actor/actor.json` file. The `dockerContextDir` field in `actor.json` defines
|
|
90
|
+
the build context boundary — this is what the tool uses to decide which files can affect the Actor's build (see
|
|
91
|
+
[Change detection](docs/cli.md#change-detection)).
|
|
26
92
|
|
|
27
|
-
|
|
93
|
+
This example has two Actors that share the code at the repo root, and one standalone Actor with its own code:
|
|
28
94
|
|
|
29
95
|
```
|
|
30
96
|
my-repo
|
|
31
97
|
├── apify-test-tools.config.json
|
|
98
|
+
├── Dockerfile <- shared by web-scraper and email-sender
|
|
99
|
+
├── package.json
|
|
100
|
+
├── src/ <- shared by web-scraper and email-sender
|
|
32
101
|
├── actors
|
|
33
102
|
│ ├── web-scraper
|
|
34
|
-
│ │
|
|
35
|
-
│ │
|
|
36
|
-
│ │ └── src/
|
|
103
|
+
│ │ └── .actor
|
|
104
|
+
│ │ └── actor.json <- points to the repo root
|
|
37
105
|
│ └── email-sender
|
|
106
|
+
│ └── .actor
|
|
107
|
+
│ └── actor.json <- points to the repo root
|
|
108
|
+
├── standalone-actors
|
|
109
|
+
│ └── orchestrator
|
|
38
110
|
│ ├── .actor
|
|
39
|
-
│ │ └── actor.json
|
|
111
|
+
│ │ └── actor.json <- default context: its own folder
|
|
112
|
+
│ ├── Dockerfile
|
|
113
|
+
│ ├── package.json
|
|
40
114
|
│ └── src/
|
|
41
115
|
└── test
|
|
42
|
-
├── unit
|
|
43
116
|
└── platform
|
|
44
|
-
├──
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
117
|
+
├── web-scraper.test.ts
|
|
118
|
+
├── email-sender.test.ts
|
|
119
|
+
└── orchestrator
|
|
120
|
+
└── orchestrator.test.ts
|
|
48
121
|
```
|
|
49
122
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### Change detection
|
|
53
|
-
|
|
54
|
-
When a PR is opened or code is pushed, the tool determines which actors need to be built and tested based on the changed files. For each changed file, for each actor:
|
|
123
|
+
The Actors that share code point their `dockerfile` and `dockerContextDir` at the repo root. Both paths are relative
|
|
124
|
+
to the `.actor` folder:
|
|
55
125
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
### 4. Create test directories
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
mkdir -p test/platform/core
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"actorSpecification": 1,
|
|
129
|
+
"name": "web-scraper",
|
|
130
|
+
"version": "0.1",
|
|
131
|
+
"dockerfile": "../../../Dockerfile",
|
|
132
|
+
"dockerContextDir": "../../.."
|
|
133
|
+
}
|
|
69
134
|
```
|
|
70
135
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
### 5. Set up GitHub workflows
|
|
75
|
-
|
|
76
|
-
See the [GitHub workflows](#github-worklows) section below.
|
|
77
|
-
|
|
78
|
-
## Config file
|
|
79
|
-
|
|
80
|
-
`apify-test-tools.config.json` lives at the repo root and tells the tool which actors live in the repo, how to identify them, and which token to use.
|
|
81
|
-
|
|
82
|
-
### Actor fields
|
|
83
|
-
|
|
84
|
-
Every actor in the config is described by these fields, whatever the mode:
|
|
85
|
-
|
|
86
|
-
| Field | Required | Description |
|
|
87
|
-
| ---------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
-
| `folder` | yes | Relative path from repo root to the actor's own project directory — the folder that directly contains `.actor/actor.json` (i.e. `<folder>/.actor/actor.json`), the actor's README/CHANGELOG, and its source. Use `"."` for a single-actor repo where `.actor/` is at the root. |
|
|
89
|
-
| `actorFullName` | yes | Full actor identifier in `owner/name` format (e.g. `"apify/web-scraper"`). This is the source of truth for the actor name — the `name` field in `actor.json` is not used. |
|
|
90
|
-
| `tokenEnvVar` | yes | Name of the environment variable holding the Apify API token for this actor. In [grouped mode](#grouped-mode) it's inherited from the group unless the actor sets its own. No fallback — if the env var is not set at build time, the build fails. |
|
|
91
|
-
| `overrideActorContext` | no | Array of paths (relative to repo root) that define which files are relevant to this actor. When set, replaces the `dockerContextDir` from `actor.json` for change detection. Useful when an actor depends on shared packages outside its Docker build context. Entries must not be prefixes of one another (e.g. `["", "code"]` or `["actors", "actors/foo"]` are rejected). The actor's own `folder` is always part of its context — if none of the listed entries reach it, it's added automatically. |
|
|
136
|
+
A change to the shared `src/` then builds and tests both of them, while a change in `standalone-actors/orchestrator`
|
|
137
|
+
counts only for the orchestrator, even though it lies inside the others' context. The orchestrator leaves
|
|
138
|
+
`dockerContextDir` out, so its context is its own folder.
|
|
92
139
|
|
|
93
|
-
|
|
140
|
+
For a single-Actor repo, set `"folder": "."` in the config and place `.actor/actor.json` at the repo root.
|
|
94
141
|
|
|
95
|
-
|
|
142
|
+
### 4. Write tests
|
|
96
143
|
|
|
97
|
-
|
|
144
|
+
Put platform tests in `test/platform`. How you organize them inside is up to you. See
|
|
145
|
+
[Writing tests](#writing-tests) below.
|
|
98
146
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
```json
|
|
102
|
-
{
|
|
103
|
-
"mode": "legacy",
|
|
104
|
-
"actors": [
|
|
105
|
-
{
|
|
106
|
-
"folder": "actors/web-scraper",
|
|
107
|
-
"actorFullName": "myteam/web-scraper",
|
|
108
|
-
"tokenEnvVar": "APIFY_TOKEN_MYTEAM"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"folder": "actors/email-sender",
|
|
112
|
-
"actorFullName": "myteam/email-sender",
|
|
113
|
-
"tokenEnvVar": "APIFY_TOKEN_MYTEAM",
|
|
114
|
-
"overrideActorContext": ["actors/email-sender", "packages/shared"]
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
```
|
|
147
|
+
### 5. Set up CI
|
|
119
148
|
|
|
120
|
-
|
|
149
|
+
On GitHub, add the [GitHub workflows](#github-workflows) below. On another CI platform, call the
|
|
150
|
+
[CLI](docs/cli.md) from your own pipeline; the workflows are a good template for the steps.
|
|
121
151
|
|
|
122
|
-
|
|
152
|
+
## Config file
|
|
123
153
|
|
|
124
|
-
|
|
154
|
+
`apify-test-tools.config.json` lives at the repo root and tells the tool which Actors live in the repo, where they
|
|
155
|
+
are, and which token builds them. Actors are organized into groups, and each group sets the token once for all of its
|
|
156
|
+
Actors:
|
|
125
157
|
|
|
126
158
|
```json
|
|
127
159
|
{
|
|
@@ -129,72 +161,57 @@ Actors are organized into `groups`, and each group sets `tokenEnvVar` and `overr
|
|
|
129
161
|
"groups": {
|
|
130
162
|
"myteam": {
|
|
131
163
|
"tokenEnvVar": "APIFY_TOKEN_MYTEAM",
|
|
132
|
-
"overrideActorContext": ["packages/shared"],
|
|
133
164
|
"actors": [
|
|
134
165
|
{ "folder": "actors/web-scraper", "actorFullName": "myteam/web-scraper" },
|
|
166
|
+
{ "folder": "actors/email-sender", "actorFullName": "myteam/email-sender" },
|
|
135
167
|
{
|
|
136
|
-
"folder": "actors/
|
|
137
|
-
"actorFullName": "myteam/
|
|
138
|
-
"overrideActorContext": ["actors/
|
|
168
|
+
"folder": "standalone-actors/orchestrator",
|
|
169
|
+
"actorFullName": "myteam/orchestrator",
|
|
170
|
+
"overrideActorContext": ["standalone-actors/orchestrator", "test/platform/orchestrator"]
|
|
139
171
|
}
|
|
140
172
|
]
|
|
141
|
-
},
|
|
142
|
-
"partner": {
|
|
143
|
-
"tokenEnvVar": "APIFY_TOKEN_PARTNER",
|
|
144
|
-
"actors": [{ "folder": "actors/partner-crawler", "actorFullName": "partner/crawler" }]
|
|
145
173
|
}
|
|
146
174
|
}
|
|
147
175
|
}
|
|
148
176
|
```
|
|
149
177
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
178
|
+
The group key (`myteam` above) is only a label for readability; it doesn't need to match any folder or username. Each
|
|
179
|
+
group needs a `tokenEnvVar` and at least one Actor. Add another group for Actors that need a different token, e.g.
|
|
180
|
+
Actors owned by another account.
|
|
153
181
|
|
|
154
|
-
|
|
182
|
+
The orchestrator sets `overrideActorContext` because its tests live outside its own folder: without it, a change to
|
|
183
|
+
only `test/platform/orchestrator` wouldn't build and test it. The other two already have the whole repo, tests
|
|
184
|
+
included, as their context.
|
|
155
185
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
186
|
+
| Field | Where | Required | Description |
|
|
187
|
+
| ---------------------- | -------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
188
|
+
| `folder` | Actor | yes | Relative path from repo root to the Actor's own project directory — the folder that directly contains `.actor/actor.json` (i.e. `<folder>/.actor/actor.json`), the Actor's README/CHANGELOG, and its source. Use `"."` for a single-Actor repo where `.actor/` is at the root. |
|
|
189
|
+
| `actorFullName` | Actor | yes | Full Actor identifier in `owner/name` format (e.g. `"apify/web-scraper"`). This is the source of truth for the Actor name — the `name` field in `actor.json` is not used. |
|
|
190
|
+
| `tokenEnvVar` | group or Actor | yes | Name of the environment variable holding the Apify API token that builds the group's Actors. No fallback — if the env var is not set at build time, the build fails. |
|
|
191
|
+
| `overrideActorContext` | group or Actor | no | Array of paths (relative to repo root) that define which files are relevant to the Actor. When set, replaces the `dockerContextDir` from `actor.json` for change detection. Useful when an Actor depends on shared packages outside its Docker build context. Entries must not be prefixes of one another (e.g. `["", "code"]` or `["actors", "actors/foo"]` are rejected). The Actor's own `folder` is always part of its context — if none of the listed entries reach it, it's added automatically. |
|
|
160
192
|
|
|
161
|
-
|
|
193
|
+
A value set on an Actor replaces the group's for that Actor only. Values are replaced, not merged: if the `myteam`
|
|
194
|
+
group also set `overrideActorContext`, the orchestrator would still get only the two paths it lists.
|
|
162
195
|
|
|
163
|
-
|
|
196
|
+
No two Actors may share a `folder`, and no two entries may point at the same `actorFullName`.
|
|
164
197
|
|
|
165
|
-
|
|
166
|
-
name: Platform tests - Core
|
|
198
|
+
## GitHub workflows
|
|
167
199
|
|
|
168
|
-
|
|
169
|
-
schedule:
|
|
170
|
-
# Runs at the start of every hour
|
|
171
|
-
- cron: '0 * * * *'
|
|
172
|
-
workflow_dispatch:
|
|
200
|
+
The workflows take every change straight to production, with tests in between:
|
|
173
201
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
202
|
+
- **Every push to a PR** builds the Actors the PR changes into a test version (`0.99`) that users never run, and runs
|
|
203
|
+
their platform tests against those builds. Only the Actors whose files changed are built and tested, and a later
|
|
204
|
+
push only re-tests what changed since the last green run.
|
|
205
|
+
- **Every merge to `master`** builds the changed Actors into their default version (`latest`), which is what users
|
|
206
|
+
run, and announces the release on Slack. There is no separate release step.
|
|
207
|
+
- **Scheduled runs** (optional) run the tests against the released builds to catch what breaks without a code change,
|
|
208
|
+
like a website changing its layout.
|
|
181
209
|
|
|
182
|
-
|
|
210
|
+
These are GitHub Actions workflows. On another CI platform, build the same flow with the [CLI](docs/cli.md).
|
|
183
211
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
on:
|
|
188
|
-
schedule:
|
|
189
|
-
# Runs at 00:00 UTC every day
|
|
190
|
-
- cron: '0 0 * * *'
|
|
191
|
-
workflow_dispatch:
|
|
192
|
-
|
|
193
|
-
jobs:
|
|
194
|
-
platformTestsDaily:
|
|
195
|
-
uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0
|
|
196
|
-
secrets: inherit
|
|
197
|
-
```
|
|
212
|
+
Add these files to `.github/workflows` in your repo. They call the reusable workflows in this repo, pinned at the
|
|
213
|
+
`@workflows-v0` major tag — never at `@master`. Every input, the optional Claude workflows, and how the tag moves are
|
|
214
|
+
in the [Workflow API](docs/workflows.md).
|
|
198
215
|
|
|
199
216
|
### `pr-build-devel-test.yaml`
|
|
200
217
|
|
|
@@ -208,7 +225,14 @@ on:
|
|
|
208
225
|
jobs:
|
|
209
226
|
buildDevelAndTest:
|
|
210
227
|
uses: apify/apify-test-tools/.github/workflows/public_pr-build-test.yaml@workflows-v0
|
|
211
|
-
secrets:
|
|
228
|
+
secrets:
|
|
229
|
+
TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }}
|
|
230
|
+
# One entry per secret apify-test-tools.config.json names, today each `tokenEnvVar`
|
|
231
|
+
CONFIG_SECRETS: |
|
|
232
|
+
{
|
|
233
|
+
"APIFY_TOKEN_MYTEAM": "${{ secrets.APIFY_TOKEN_MYTEAM }}",
|
|
234
|
+
"APIFY_TOKEN_PARTNER": "${{ secrets.APIFY_TOKEN_PARTNER }}"
|
|
235
|
+
}
|
|
212
236
|
```
|
|
213
237
|
|
|
214
238
|
### `release-latest.yaml`
|
|
@@ -223,506 +247,103 @@ on:
|
|
|
223
247
|
jobs:
|
|
224
248
|
buildLatest:
|
|
225
249
|
uses: apify/apify-test-tools/.github/workflows/public_push-build-latest.yaml@workflows-v0
|
|
226
|
-
secrets:
|
|
250
|
+
secrets:
|
|
251
|
+
SLACK_TOKEN_RELEASES_BOT: ${{ secrets.SLACK_TOKEN_RELEASES_BOT }}
|
|
252
|
+
# One entry per secret apify-test-tools.config.json names, today each `tokenEnvVar`
|
|
253
|
+
CONFIG_SECRETS: |
|
|
254
|
+
{
|
|
255
|
+
"APIFY_TOKEN_MYTEAM": "${{ secrets.APIFY_TOKEN_MYTEAM }}",
|
|
256
|
+
"APIFY_TOKEN_PARTNER": "${{ secrets.APIFY_TOKEN_PARTNER }}"
|
|
257
|
+
}
|
|
227
258
|
```
|
|
228
259
|
|
|
229
|
-
|
|
230
|
-
[Releasing Actors](#releasing-actors-release) for how the released range is determined and what to
|
|
231
|
-
pass if you call the CLI from somewhere else.
|
|
232
|
-
|
|
233
|
-
### `claude-review.yaml`
|
|
260
|
+
### Scheduled tests (optional)
|
|
234
261
|
|
|
235
|
-
|
|
236
|
-
every push while that label is on.
|
|
262
|
+
How often to run which tests is up to you. For example, you can run every test once a day:
|
|
237
263
|
|
|
238
264
|
```yaml
|
|
239
|
-
name:
|
|
265
|
+
name: Platform tests - Daily
|
|
240
266
|
|
|
241
267
|
on:
|
|
242
|
-
|
|
243
|
-
|
|
268
|
+
schedule:
|
|
269
|
+
# Runs at 00:00 UTC every day
|
|
270
|
+
- cron: '0 0 * * *'
|
|
271
|
+
workflow_dispatch:
|
|
244
272
|
|
|
245
273
|
jobs:
|
|
246
|
-
|
|
247
|
-
uses: apify/apify-test-tools/.github/workflows/
|
|
248
|
-
secrets:
|
|
274
|
+
platformTestsDaily:
|
|
275
|
+
uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0
|
|
276
|
+
secrets:
|
|
277
|
+
TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }}
|
|
278
|
+
SLACK_TOKEN_TESTS_BOT: ${{ secrets.SLACK_TOKEN_TESTS_BOT }}
|
|
249
279
|
```
|
|
250
280
|
|
|
251
|
-
|
|
252
|
-
because a reusable workflow doesn't get its own repo checked out. `prompt-ref` selects which ref to
|
|
253
|
-
fetch them from and defaults to `workflows-v0`, so the instructions match the workflow you're calling — point
|
|
254
|
-
it at a branch only to test a prompt change.
|
|
255
|
-
|
|
256
|
-
### Secrets
|
|
257
|
-
|
|
258
|
-
Callers pass `secrets: inherit`. The workflows do not turn every inherited secret into job-wide
|
|
259
|
-
environment variables, so a secret is only visible to the step that needs it:
|
|
260
|
-
|
|
261
|
-
| Secret | Reaches |
|
|
262
|
-
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
263
|
-
| `NPM_TOKEN` | dependency install steps only, as both `NPM_TOKEN` and `NODE_AUTH_TOKEN`. Use a read-only token: npm granular tokens can be read-only, classic automation tokens can publish. |
|
|
264
|
-
| the Actor tokens named by `tokenEnvVar` in `apify-test-tools.config.json` | the `build`, `release`, and `delete-old-builds` steps only |
|
|
265
|
-
| `TESTER_APIFY_TOKEN` | the vitest step, and the Claude investigation step: the Apify MCP server's bearer token for reading the failing run, its log and its storages, and Claude's token for re-running it to measure how often the failure happens |
|
|
266
|
-
| `SLACK_TOKEN_TESTS_BOT` / `SLACK_TOKEN_RELEASES_BOT` | the reporting and release steps only |
|
|
267
|
-
|
|
268
|
-
The Actor tokens are the one set that cannot be listed in the workflow, because each Actor names its
|
|
269
|
-
own token via `tokenEnvVar` in `apify-test-tools.config.json`. Those steps pass
|
|
270
|
-
`${{ toJSON(secrets) }}` as `ALL_SECRETS` and run the command through
|
|
271
|
-
`.github/scripts/run-with-apify-tokens.mjs`, which reads that same config file to decide which
|
|
272
|
-
secrets to pass on:
|
|
281
|
+
and a few critical tests, kept in e.g. `test/platform/hourly`, every hour:
|
|
273
282
|
|
|
274
283
|
```yaml
|
|
275
|
-
|
|
276
|
-
env:
|
|
277
|
-
ALL_SECRETS: ${{ toJSON(secrets) }}
|
|
278
|
-
run: |
|
|
279
|
-
node "${{ steps.setup.outputs.scripts-path }}/run-with-apify-tokens.mjs" \
|
|
280
|
-
npx apify-test-tools build --target-branch ...
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
The wrapper passes only the tokens the config declares and drops `ALL_SECRETS`, so neither `npx` nor
|
|
284
|
-
anything under `node_modules` sees the blob. Nothing is written to `$GITHUB_ENV`, so the tokens stay
|
|
285
|
-
inside that one command rather than leaking into later steps. Reading the same file
|
|
286
|
-
`apify-test-tools` reads means the two can't drift, and a secret that merely looks like an Actor
|
|
287
|
-
token is not passed just because of its name.
|
|
288
|
-
|
|
289
|
-
A token the config declares but the repo hasn't set is a warning, not a failure: a repo can carry an
|
|
290
|
-
Actor whose token isn't configured and still build fine as long as that Actor never changes, and
|
|
291
|
-
`apify-test-tools` raises a precise error naming the Actor at the point it actually needs the token.
|
|
292
|
-
|
|
293
|
-
`scripts-path` comes from the setup action (give the step `id: setup`) and points at this repo's
|
|
294
|
-
`.github/scripts/` directory inside the runner's action checkout, so workflows can run these helpers
|
|
295
|
-
without checking this repo out again. The caller's workspace holds the caller's repo, not this one.
|
|
296
|
-
|
|
297
|
-
Two tidier-looking alternatives don't work, so don't reach for them:
|
|
298
|
-
|
|
299
|
-
- **Exporting to `$GITHUB_ENV`** would let the steps call `npx` directly with no wrapper, but
|
|
300
|
-
`$GITHUB_ENV` applies to every later step in the job. In `pr-build-test` the vitest step runs after
|
|
301
|
-
the build, so it would inherit Actor tokens it has no use for.
|
|
302
|
-
- **Returning the tokens as a step output** would be scoped correctly, but the runner refuses to set
|
|
303
|
-
an output whose value contains a registered secret. It logs `Skip output <name> since it may
|
|
304
|
-
contain secret` and leaves the output empty, so anything reading it downstream gets nothing.
|
|
305
|
-
|
|
306
|
-
The `unitTest` job runs static checks and needs `NPM_TOKEN` only. No job runs `npm ci` with Apify or
|
|
307
|
-
Slack credentials in scope, so a postinstall script in the dependency tree cannot read them.
|
|
308
|
-
|
|
309
|
-
## Versioning and releases
|
|
310
|
-
|
|
311
|
-
The workflows and the npm package live in one repo but ship on their own schedules. Two pointers
|
|
312
|
-
decide what a consumer repo actually runs:
|
|
313
|
-
|
|
314
|
-
| Pointer | What it selects | Moves when |
|
|
315
|
-
| ----------------------------------- | ---------------------------------------------- | -------------------------------------------------------- |
|
|
316
|
-
| the `@workflows-v0` tag in `uses:` | which workflows run | a master push, once the version below is published |
|
|
317
|
-
| `.github/workflows-package-version` | which `apify-test-tools` the workflows install | a stable release writes it; you may set it ahead of time |
|
|
318
|
-
|
|
319
|
-
The setup action installs that **exact** version — not a range. A tag is therefore a complete
|
|
320
|
-
statement: these workflows _and_ this library. The stable release writes the file into the same
|
|
321
|
-
commit that bumps `package.json` and `CHANGELOG.md`, so a released commit always names the version
|
|
322
|
-
it published, and rollout latency is unchanged: the release publishes and moves the tag in one run.
|
|
323
|
-
|
|
324
|
-
Prereleases are excluded. Master pushes publish a `-beta` that consumer repos must never install, so
|
|
325
|
-
the pin only moves on a stable release; betas stay reachable through the lockfile path in the setup
|
|
326
|
-
action, which is how branch testing works.
|
|
327
|
-
|
|
328
|
-
Nothing is coupled that doesn't need to be:
|
|
329
|
-
|
|
330
|
-
- **Workflow-only change** — merge it. `workflows-v0` moves, it goes live, no release needed.
|
|
331
|
-
- **Package-only change** — merge it, then cut a release when you want it out. The workflows are
|
|
332
|
-
unchanged, so consumers see nothing until the release lands.
|
|
333
|
-
- **A workflow that calls a new CLI feature** — the one case that can break consumers, and the only
|
|
334
|
-
one with any ceremony. Put the package change, the workflow change, and the new pin in one PR. On
|
|
335
|
-
merge the tag is **held**: the CI job reports that the pinned version isn't on npm and leaves `workflows-v0`
|
|
336
|
-
where it is, so consumers keep running the previous workflows. Cut a stable release, and the tag
|
|
337
|
-
moves on its own. Run **Move major version tag** if you don't want to wait for the next master
|
|
338
|
-
push.
|
|
339
|
-
|
|
340
|
-
`workflows-v0` moving on every master push means `@workflows-v0` is as live as `@master` was —
|
|
341
|
-
there's no staging step, just a gate on the package version. What the tag buys you is a
|
|
342
|
-
`workflows-v1` for breaking workflow changes, so repos migrate one at a time instead of all at once,
|
|
343
|
-
and a way to roll back by pointing the tag at an earlier commit. Bump `MAJOR_TAG` in
|
|
344
|
-
`.github/workflows/_move_major_tag.yaml` to cut the next major; the old tag then freezes where it is
|
|
345
|
-
and keeps working.
|
|
346
|
-
|
|
347
|
-
Freezing is real, which is the whole reason the version is pinned rather than a floor. A frozen `workflows-v0`
|
|
348
|
-
points at a commit whose pinned version never changes, so it keeps installing the library it was
|
|
349
|
-
tested against no matter how far the package moves on. Had the workflows installed `>=<floor>`, a
|
|
350
|
-
frozen `workflows-v0` would still resolve to whatever is newest — and since the release that enables
|
|
351
|
-
`workflows-v1` is usually the same release that breaks `workflows-v0`, the migration window would
|
|
352
|
-
have been zero.
|
|
353
|
-
|
|
354
|
-
The tag tracks the **workflows'** contract, not the npm package version. They move independently on
|
|
355
|
-
purpose, so `@workflows-v0` is expected to stay `@workflows-v0` after the package reaches 1.0 —
|
|
356
|
-
bump it when a workflow breaks its callers, not when the package does. Because `uses:` cannot take an expression, every ref
|
|
357
|
-
into this repo repeats the tag literally; `check-major-tag-refs.mjs` fails the build if `MAJOR_TAG`
|
|
358
|
-
and those refs disagree, which is the mistake that would otherwise ship silently during a bump.
|
|
359
|
-
|
|
360
|
-
### Testing workflow changes
|
|
361
|
-
|
|
362
|
-
- Point [testing-repo-for-github-actions](https://github.com/apify-store/testing-repo-for-github-actions)
|
|
363
|
-
at your branch (`uses: ...@your-branch`). It has real attached Actors and tests. Because the
|
|
364
|
-
package lives here too, a master push publishes a `beta`, and the lockfile-beta path in the setup
|
|
365
|
-
action installs that exact version — so one branch tests both halves of a change together.
|
|
366
|
-
- To change the composite action itself, repoint the `uses:` refs inside the reusable workflows at
|
|
367
|
-
your branch as well, and change them back before merging.
|
|
368
|
-
- Make sure the shell code actually works on your laptop first.
|
|
369
|
-
- After merging, watch the workflow on a real project before moving on.
|
|
370
|
-
|
|
371
|
-
## Writing tests
|
|
372
|
-
|
|
373
|
-
### Test structure
|
|
374
|
-
|
|
375
|
-
`testActor` runs the actor and provides extended `expect` and `run` inside the callback.
|
|
376
|
-
|
|
377
|
-
```ts
|
|
378
|
-
import { describe, testActor } from 'apify-test-tools';
|
|
379
|
-
|
|
380
|
-
describe('test', () => {
|
|
381
|
-
testActor(actorId, 'actor test 1', async ({ expect, run }) => {
|
|
382
|
-
const runResult = await run({ input });
|
|
383
|
-
|
|
384
|
-
// your checks
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
testActor(actorId, 'actor test 2', async ({ expect, run }) => {
|
|
388
|
-
const runResult = await run({ input });
|
|
389
|
-
|
|
390
|
-
// your checks
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
---
|
|
396
|
-
|
|
397
|
-
### Validating basic run attributes
|
|
398
|
-
|
|
399
|
-
`toFinishWith` validates common run properties in a single call:
|
|
400
|
-
|
|
401
|
-
```ts
|
|
402
|
-
await expect(runResult).toFinishWith({
|
|
403
|
-
datasetItemCount: 100,
|
|
404
|
-
});
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
You can also specify a range:
|
|
408
|
-
|
|
409
|
-
```ts
|
|
410
|
-
await expect(runResult).toFinishWith({
|
|
411
|
-
datasetItemCount: { min: 80, max: 120 },
|
|
412
|
-
});
|
|
413
|
-
```
|
|
284
|
+
name: Platform tests - Hourly
|
|
414
285
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
status: 'SUCCEEDED',
|
|
421
|
-
duration: {
|
|
422
|
-
min: 600, // 0.6 sec
|
|
423
|
-
max: 600_000, // 10 min
|
|
424
|
-
},
|
|
425
|
-
failedRequests: 0,
|
|
426
|
-
requestsRetries: { max: 3 },
|
|
427
|
-
forbiddenLogs: ['ReferenceError', 'TypeError'],
|
|
428
|
-
|
|
429
|
-
// only datasetItemCount is required
|
|
430
|
-
datasetItemCount: { min: 80, max: 120 },
|
|
431
|
-
|
|
432
|
-
// optional
|
|
433
|
-
chargedEventCounts: {
|
|
434
|
-
'actor-start': 1,
|
|
435
|
-
'place-scraped': 9,
|
|
436
|
-
},
|
|
437
|
-
});
|
|
438
|
-
```
|
|
439
|
-
|
|
440
|
-
---
|
|
441
|
-
|
|
442
|
-
### Custom validations
|
|
443
|
-
|
|
444
|
-
```ts
|
|
445
|
-
expect(place.title, `London Eye's title`).toEqual('lastminute.com London Eye');
|
|
446
|
-
```
|
|
447
|
-
|
|
448
|
-
---
|
|
449
|
-
|
|
450
|
-
### Custom validation functions
|
|
451
|
-
|
|
452
|
-
You can create your own functions wrapping a common validation logic in e.g. `test/platform/utils.ts` and import it in test files.
|
|
453
|
-
|
|
454
|
-
```ts
|
|
455
|
-
import { ExpectStatic } from 'apify-test-tools'
|
|
456
|
-
|
|
457
|
-
export const validateItem = (expect: ExpectStatic, item: any) {
|
|
458
|
-
expect(item.title, 'Item title').toBeString();
|
|
459
|
-
}
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
---
|
|
463
|
-
|
|
464
|
-
### Test options
|
|
465
|
-
|
|
466
|
-
You can pass options as the fourth argument to `testActor`:
|
|
467
|
-
|
|
468
|
-
```ts
|
|
469
|
-
testActor(
|
|
470
|
-
actorId,
|
|
471
|
-
'slow actor test',
|
|
472
|
-
async ({ expect, run }) => {
|
|
473
|
-
const runResult = await run({ input });
|
|
474
|
-
await expect(runResult).toFinishWith({ datasetItemCount: 100 });
|
|
475
|
-
},
|
|
476
|
-
{
|
|
477
|
-
timeout: 2 * 60 * 60 * 1000, // 2 hours (default is 1 hour)
|
|
478
|
-
retry: 3, // retry up to 3 times (default is 1)
|
|
479
|
-
},
|
|
480
|
-
);
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
---
|
|
484
|
-
|
|
485
|
-
### Using prefilled input
|
|
486
|
-
|
|
487
|
-
If the actor has a prefilled input on the platform, you can merge it with your test input:
|
|
286
|
+
on:
|
|
287
|
+
schedule:
|
|
288
|
+
# Runs at the start of every hour
|
|
289
|
+
- cron: '0 * * * *'
|
|
290
|
+
workflow_dispatch:
|
|
488
291
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
292
|
+
jobs:
|
|
293
|
+
platformTestsHourly:
|
|
294
|
+
uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0
|
|
295
|
+
with:
|
|
296
|
+
test-files-glob: hourly
|
|
297
|
+
secrets:
|
|
298
|
+
TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }}
|
|
299
|
+
SLACK_TOKEN_TESTS_BOT: ${{ secrets.SLACK_TOKEN_TESTS_BOT }}
|
|
497
300
|
```
|
|
498
301
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
### Testing an existing run
|
|
302
|
+
### Secrets
|
|
502
303
|
|
|
503
|
-
|
|
304
|
+
Set these as repository or organization secrets and pass them in each job's `secrets:` block, as in the examples
|
|
305
|
+
above. The Actor tokens go packed in one JSON object, `CONFIG_SECRETS`, because their names differ per repo:
|
|
504
306
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
307
|
+
| Secret | Needed for |
|
|
308
|
+
| ------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
309
|
+
| the Actor tokens named by `tokenEnvVar` in `apify-test-tools.config.json` | building Actors and deleting their old builds |
|
|
310
|
+
| `TESTER_APIFY_TOKEN` | running the platform tests |
|
|
311
|
+
| `SLACK_TOKEN_RELEASES_BOT` | announcing releases on Slack |
|
|
312
|
+
| `SLACK_TOKEN_TESTS_BOT` | reporting scheduled test results to Slack |
|
|
313
|
+
| `NPM_TOKEN` | optional, installing private npm packages. Use a read-only token |
|
|
511
314
|
|
|
512
|
-
|
|
315
|
+
Repos in the `apify` org can pass `secrets: inherit` instead. Each secret only reaches the step that needs it. See
|
|
316
|
+
[Secrets](docs/workflows.md#secrets) for both, and for passing `CONFIG_SECRETS` without listing the tokens.
|
|
513
317
|
|
|
514
|
-
|
|
318
|
+
## Writing tests
|
|
515
319
|
|
|
516
|
-
`
|
|
320
|
+
Platform tests use `describe` and `testActor` from `apify-test-tools` instead of the ones from `vitest`. `testActor`
|
|
321
|
+
registers a test that only runs when that Actor was built for it (or when you ask for all tests), and gives the
|
|
322
|
+
callback an extended `expect` and a `run` function that starts the Actor.
|
|
517
323
|
|
|
518
324
|
```ts
|
|
519
|
-
|
|
520
|
-
const runResult = await run({ input });
|
|
521
|
-
|
|
522
|
-
// Access dataset items
|
|
523
|
-
const { items } = await runResult.getDataset();
|
|
524
|
-
expect(items[0].title).toBeNonEmptyString();
|
|
525
|
-
|
|
526
|
-
// Access run log
|
|
527
|
-
const log = await runResult.getLog();
|
|
528
|
-
expect(log).toContain('Crawl finished');
|
|
529
|
-
|
|
530
|
-
// Access crawler statistics
|
|
531
|
-
const stats = await runResult.getStatistics();
|
|
532
|
-
expect(stats?.requestsFinished).toBeGreaterThan(0);
|
|
533
|
-
|
|
534
|
-
// Access key-value store
|
|
535
|
-
const kvs = runResult.getKeyValueStoreClient();
|
|
536
|
-
const record = await kvs.getRecord('OUTPUT');
|
|
537
|
-
|
|
538
|
-
// Access run info (refreshed from API)
|
|
539
|
-
const runInfo = await runResult.getRunInfo();
|
|
540
|
-
});
|
|
541
|
-
```
|
|
542
|
-
|
|
543
|
-
---
|
|
325
|
+
import { describe, testActor } from 'apify-test-tools';
|
|
544
326
|
|
|
545
|
-
|
|
327
|
+
describe('web-scraper', () => {
|
|
328
|
+
testActor('myteam/web-scraper', 'scrapes the start URL', async ({ expect, run }) => {
|
|
329
|
+
const runResult = await run({ input: { startUrls: [{ url: 'https://apify.com' }] } });
|
|
546
330
|
|
|
547
|
-
|
|
331
|
+
// Status SUCCEEDED, a sane duration, no failed requests, no errors in the log, and the item count
|
|
332
|
+
await expect(runResult).toFinishWith({ datasetItemCount: { min: 1, max: 10 } });
|
|
548
333
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
describe('standby tests', () => {
|
|
553
|
-
testStandbyActor(actorId, 'standby request', async ({ expect, callStandby }) => {
|
|
554
|
-
const { data, status } = await callStandby({
|
|
555
|
-
input: { query: 'test' },
|
|
556
|
-
path: '/search',
|
|
557
|
-
headers: { 'Content-Type': 'application/json' },
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
expect(status).toBe(200);
|
|
561
|
-
expect(data.results).toBeNonEmptyArray();
|
|
334
|
+
const { items } = await runResult.getDataset();
|
|
335
|
+
expect(items[0].title, 'Page title').toBeNonEmptyString();
|
|
562
336
|
});
|
|
563
337
|
});
|
|
564
338
|
```
|
|
565
339
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
### Custom matchers
|
|
569
|
-
|
|
570
|
-
`testActor` extends `expect` with the following custom matchers:
|
|
571
|
-
|
|
572
|
-
- `toBeArray()` / `toBeEmptyArray()` / `toBeNonEmptyArray()`
|
|
573
|
-
- `toBeString()` / `toBeNonEmptyString()` / `toStartWith(prefix)`
|
|
574
|
-
- `toBeNumber()` / `toBeWholeNumber()` / `toBeWithinRange(min, max)`
|
|
575
|
-
- `toBeBoolean()` / `toBeTrue()` / `toBeFalse()`
|
|
576
|
-
- `toBeObject()` / `toBeNonEmptyObject()`
|
|
577
|
-
- `toFinishWith(options)` - validates run status, duration, dataset, logs, etc.
|
|
340
|
+
Platform tests are skipped unless `TESTER_APIFY_TOKEN` is set, so your regular unit test run stays unaffected.
|
|
578
341
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
The package includes a CLI binary used by CI workflows to build Actors, detect changes, and report test results. You can also run it locally.
|
|
582
|
-
|
|
583
|
-
### Running locally
|
|
584
|
-
|
|
585
|
-
Running the testing library locally is useful when you only want to update the testing code in /test because you can iterate on it without pushing new code to the remote.
|
|
586
|
-
|
|
587
|
-
If you don't need to change any source files and only iterate on /test code, you can skip steps 1-4. But if you want to test vs changed /src, you have to push that GitHub branch since it needs to build the Actors with that code.
|
|
588
|
-
|
|
589
|
-
The main local flow is:
|
|
590
|
-
|
|
591
|
-
1. Switch to a dummy branch that you will push and can later delete
|
|
592
|
-
2. `npm i apify-test-tools@latest -D`
|
|
593
|
-
3. Push your code (changes you want to test)
|
|
594
|
-
4. Build Actors on Apify (with your new code)
|
|
595
|
-
5. Run tests against those builds. You can change tests and run on the same builds.
|
|
596
|
-
|
|
597
|
-
Run every command from the root of the actor repository you want to work with.
|
|
598
|
-
|
|
599
|
-
#### 4. Build affected Actors
|
|
600
|
-
|
|
601
|
-
If you want to test vs existing src code, you can skip this and instead construct the output JSON manually from existing builds only for the Actors you need to test.
|
|
602
|
-
|
|
603
|
-
Requires `APIFY_TOKEN_<USERNAME>` for all Apify users that own your Actors (e.g. `apify`, `compass`, `lukaskrivka` users). The username is derived from the actor name — uppercased with non-word chars replaced by `_` (e.g. Actor `john.doe/my-actor` needs `APIFY_TOKEN_JOHN_DOE`).
|
|
604
|
-
|
|
605
|
-
```bash
|
|
606
|
-
APIFY_TOKEN_JOHN_DOE=<token> \
|
|
607
|
-
npx apify-test-tools build \
|
|
608
|
-
--target-branch origin/master \
|
|
609
|
-
--source-branch origin/my-dummy-branch \
|
|
610
|
-
--dry-run
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
Remove `--dry-run` to actually trigger builds and update the branch names/ The command outputs a JSON array of build objects to stdout:
|
|
614
|
-
|
|
615
|
-
```json
|
|
616
|
-
[{ "buildId": "...", "actorRawId": "...", "buildNumber": "...", "actorFullName": "john.doe/my-actor" }]
|
|
617
|
-
```
|
|
618
|
-
|
|
619
|
-
#### Build from local source (no push needed)
|
|
620
|
-
|
|
621
|
-
If you don't want to push a dummy branch just to test a change and wait for all the tests to finish, `build-from-local` builds Actors directly from your local files (zipped into the Actor's `actor-<id>-source` key-value store and built as `TARBALL`, like `apify push`), skipping steps 1-4 above.
|
|
622
|
-
|
|
623
|
-
```bash
|
|
624
|
-
APIFY_TOKEN_JOHN_DOE=<token> \
|
|
625
|
-
npx apify-test-tools build-from-local --actors john.doe/my-actor
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
Pass a hardcoded actor name via `--actors` to build only that Actor (comma-separate multiple names). Omit `--actors` to build all Actors in the repo, or add `--dry-run` to preview without building. It outputs the same JSON build array as `build`, so you run tests against it the same way as in step 5 below:
|
|
342
|
+
To run them locally against the Actors' current default builds:
|
|
629
343
|
|
|
630
344
|
```bash
|
|
631
|
-
|
|
632
|
-
BUILDS=$(APIFY_TOKEN_JOHN_DOE=apify_api_xxx \
|
|
633
|
-
npx apify-test-tools build-from-local --actors apify/my-actor)
|
|
345
|
+
RUN_ALL_PLATFORM_TESTS=1 TESTER_APIFY_TOKEN=<token> npx vitest --run test/platform
|
|
634
346
|
```
|
|
635
347
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
#### 5. Run tests against the builds
|
|
639
|
-
|
|
640
|
-
Pass the build output as `ACTOR_BUILDS` and provide `TESTER_APIFY_TOKEN`. The token can point to your own account (if you have enough memory) or you can use the testing account (xRGg9iAfJSymqartk). Platform test suites are skipped unless `TESTER_APIFY_TOKEN` is set, so regular unit test runs stay unaffected.
|
|
641
|
-
|
|
642
|
-
If you want to run only certain tests, change the `test/platform` to be more specific.
|
|
643
|
-
|
|
644
|
-
```bash
|
|
645
|
-
ACTOR_BUILDS='<JSON output from build command>' \
|
|
646
|
-
TESTER_APIFY_TOKEN=<token> \
|
|
647
|
-
npx vitest --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 test/platform
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
#### Full example
|
|
651
|
-
|
|
652
|
-
```bash
|
|
653
|
-
# Build and capture output
|
|
654
|
-
BUILDS=$(APIFY_TOKEN_JOHN_DOE=apify_api_xxx \
|
|
655
|
-
npx apify-test-tools build \
|
|
656
|
-
--target-branch origin/master \
|
|
657
|
-
--source-branch origin/my-dummy-branch)
|
|
658
|
-
|
|
659
|
-
# Run tests with the builds
|
|
660
|
-
ACTOR_BUILDS="$BUILDS" \
|
|
661
|
-
TESTER_APIFY_TOKEN=apify_api_yyy \
|
|
662
|
-
npx vitest --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 test/platform
|
|
663
|
-
```
|
|
664
|
-
|
|
665
|
-
### Releasing Actors (`release`)
|
|
666
|
-
|
|
667
|
-
`release` builds the `latest` (default) version of every Actor changed since the last release and
|
|
668
|
-
posts release notes to Slack. It reads everything else from git: the branch from the checked-out
|
|
669
|
-
`HEAD`, the commits and changed files from the range `<base-commit>..HEAD`, and the repository from
|
|
670
|
-
the `origin` remote.
|
|
671
|
-
|
|
672
|
-
```bash
|
|
673
|
-
npx apify-test-tools release --base-commit <sha> --release-slack-channel "#releases" --dry-run
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
#### `--base-commit`
|
|
677
|
-
|
|
678
|
-
The last commit that is **already released**. Everything after it, up to `HEAD`, is released. It is
|
|
679
|
-
required: git alone can't tell which commits a push brought, and guessing wrong silently leaves Actors
|
|
680
|
-
on old code.
|
|
681
|
-
|
|
682
|
-
The changed files come from diffing `<base-commit>` and `HEAD` directly, so this works for every
|
|
683
|
-
merge strategy as long as the base commit is the branch tip from **before** the push:
|
|
684
|
-
|
|
685
|
-
| Merge strategy | What lands on the branch | What to pass |
|
|
686
|
-
| ------------------------------ | --------------------------------- | ---------------------------------------------------------------------- |
|
|
687
|
-
| Squash and merge | 1 new commit | the push's "before" commit (`HEAD~1` also works) |
|
|
688
|
-
| Merge commit | the PR's commits + 1 merge commit | the push's "before" commit (`HEAD^1`, the first parent, also works) |
|
|
689
|
-
| Rebase and merge / direct push | N new commits | the push's "before" commit (`HEAD~1` would miss the first N-1 commits) |
|
|
690
|
-
|
|
691
|
-
On GitHub, the push's "before" commit is `${{ github.event.before }}`, which the reusable workflow
|
|
692
|
-
passes for you. On other CIs use the equivalent, e.g. `$CI_COMMIT_BEFORE_SHA` on GitLab. The checkout
|
|
693
|
-
needs the full history (`fetch-depth: 0` in `actions/checkout`) so the base commit is available locally.
|
|
694
|
-
|
|
695
|
-
`release` fails instead of guessing when:
|
|
696
|
-
|
|
697
|
-
- the base commit is all zeros (GitHub sends this for a push that created the branch)
|
|
698
|
-
- the base commit isn't in the local history (shallow checkout) or isn't an ancestor of `HEAD`
|
|
699
|
-
(the branch was force-pushed)
|
|
700
|
-
|
|
701
|
-
In those cases, rerun `release` with a `--base-commit` you pick yourself: an ancestor of `HEAD` from
|
|
702
|
-
before the changes you want to release (for a shallow checkout, fetch the full history instead).
|
|
703
|
-
`--actors` only narrows which of the changed Actors get released; it never forces a build, so on its
|
|
704
|
-
own it doesn't get past these errors.
|
|
705
|
-
If `HEAD` is the base commit, there is nothing to release and the command exits successfully.
|
|
706
|
-
|
|
707
|
-
A failed release isn't retried by the next push: that push's base commit is the failed one's head, so
|
|
708
|
-
its changes are skipped. Re-run the failed workflow run, or release the Actors manually.
|
|
709
|
-
|
|
710
|
-
#### Repository check
|
|
711
|
-
|
|
712
|
-
`release` and `build` point each Actor's version at the `origin` remote. Because a build overwrites the
|
|
713
|
-
version's Git URL, building from a fork or a mirror would repoint the Actor. So, before building, the
|
|
714
|
-
remote is compared with the Git URL of the Actor's default version (the one its default build tag
|
|
715
|
-
points to), and the command fails if they differ or if the default version isn't built from a Git
|
|
716
|
-
repository. The URL form doesn't matter (`https://github.com/org/repo` equals
|
|
717
|
-
`git@github.com:org/repo.git`).
|
|
718
|
-
|
|
719
|
-
To build from a different repository on purpose, e.g. when moving an Actor, pass `--repo-url`. That
|
|
720
|
-
skips the check.
|
|
721
|
-
|
|
722
|
-
#### Dev mode
|
|
723
|
-
|
|
724
|
-
For development on `apify-test-tools` itself, use `tsx` directly:
|
|
725
|
-
|
|
726
|
-
```bash
|
|
727
|
-
cd local-clone && tsx ../bin/main.ts get-actor-configs
|
|
728
|
-
```
|
|
348
|
+
The [Vitest library API](docs/lib.md) covers everything `toFinishWith` checks, the other matchers, standby Actors,
|
|
349
|
+
reading run data, and running tests locally against builds of your own changes.
|