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.
Files changed (187) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/actions/checkout-restore-dependencies/action.yaml +64 -27
  3. package/.github/cli/apify-test-tools.mjs +360 -0
  4. package/.github/scripts/check-major-tag-refs.mjs +1 -1
  5. package/.github/scripts/mask-config-secrets.sh +17 -0
  6. package/.github/scripts/run-with-apify-tokens.mjs +37 -12
  7. package/.github/workflows/_check_code.yaml +25 -0
  8. package/.github/workflows/_move_major_tag.yaml +3 -81
  9. package/.github/workflows/_tests.yaml +34 -0
  10. package/.github/workflows/_update_release_metadata.yaml +0 -12
  11. package/.github/workflows/manual_move_major_tag.yaml +3 -3
  12. package/.github/workflows/manual_release_stable.yaml +3 -13
  13. package/.github/workflows/on_master.yaml +9 -5
  14. package/.github/workflows/on_pull_request.yaml +3 -48
  15. package/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml +13 -2
  16. package/.github/workflows/public_platform-tests.yaml +24 -1
  17. package/.github/workflows/public_pr-build-test.yaml +62 -49
  18. package/.github/workflows/public_push-build-latest.yaml +41 -8
  19. package/.husky/pre-commit +5 -0
  20. package/.prettierignore +3 -0
  21. package/CHANGELOG.md +17 -0
  22. package/CONTRIBUTING.md +105 -21
  23. package/README.md +218 -597
  24. package/bin/affected-actors.ts +198 -0
  25. package/bin/build-from-local.ts +65 -13
  26. package/bin/build.ts +123 -41
  27. package/bin/diff-changes.ts +55 -25
  28. package/bin/diff-json-schema.ts +5 -6
  29. package/bin/git.ts +69 -99
  30. package/bin/main.ts +96 -122
  31. package/bin/slack.ts +43 -10
  32. package/bin/stdin-input.ts +65 -0
  33. package/bin/test-report.ts +6 -9
  34. package/bin/types.ts +16 -0
  35. package/dist/bin/affected-actors.d.ts +46 -0
  36. package/dist/bin/affected-actors.d.ts.map +1 -0
  37. package/dist/bin/affected-actors.js +135 -0
  38. package/dist/bin/affected-actors.js.map +1 -0
  39. package/dist/bin/build-from-local.d.ts +12 -3
  40. package/dist/bin/build-from-local.d.ts.map +1 -1
  41. package/dist/bin/build-from-local.js +34 -12
  42. package/dist/bin/build-from-local.js.map +1 -1
  43. package/dist/bin/build.d.ts +30 -7
  44. package/dist/bin/build.d.ts.map +1 -1
  45. package/dist/bin/build.js +85 -26
  46. package/dist/bin/build.js.map +1 -1
  47. package/dist/bin/diff-changes.d.ts +12 -4
  48. package/dist/bin/diff-changes.d.ts.map +1 -1
  49. package/dist/bin/diff-changes.js +31 -20
  50. package/dist/bin/diff-changes.js.map +1 -1
  51. package/dist/bin/diff-json-schema.d.ts +2 -2
  52. package/dist/bin/diff-json-schema.d.ts.map +1 -1
  53. package/dist/bin/diff-json-schema.js +1 -4
  54. package/dist/bin/diff-json-schema.js.map +1 -1
  55. package/dist/bin/git.d.ts +23 -21
  56. package/dist/bin/git.d.ts.map +1 -1
  57. package/dist/bin/git.js +60 -83
  58. package/dist/bin/git.js.map +1 -1
  59. package/dist/bin/main.js +82 -93
  60. package/dist/bin/main.js.map +1 -1
  61. package/dist/bin/slack.d.ts +14 -4
  62. package/dist/bin/slack.d.ts.map +1 -1
  63. package/dist/bin/slack.js +39 -6
  64. package/dist/bin/slack.js.map +1 -1
  65. package/dist/bin/stdin-input.d.ts +17 -0
  66. package/dist/bin/stdin-input.d.ts.map +1 -0
  67. package/dist/bin/stdin-input.js +54 -0
  68. package/dist/bin/stdin-input.js.map +1 -0
  69. package/dist/bin/test-report.d.ts.map +1 -1
  70. package/dist/bin/test-report.js +6 -8
  71. package/dist/bin/test-report.js.map +1 -1
  72. package/dist/bin/types.d.ts +14 -0
  73. package/dist/bin/types.d.ts.map +1 -1
  74. package/dist/lib/extend-expect.d.ts.map +1 -1
  75. package/dist/lib/extend-expect.js +37 -218
  76. package/dist/lib/extend-expect.js.map +1 -1
  77. package/dist/lib/lib.d.ts +1 -2
  78. package/dist/lib/lib.d.ts.map +1 -1
  79. package/dist/lib/lib.js +15 -22
  80. package/dist/lib/lib.js.map +1 -1
  81. package/dist/lib/run-checks.d.ts +14 -0
  82. package/dist/lib/run-checks.d.ts.map +1 -0
  83. package/dist/lib/run-checks.js +82 -0
  84. package/dist/lib/run-checks.js.map +1 -0
  85. package/dist/lib/run-test-result.d.ts +3 -6
  86. package/dist/lib/run-test-result.d.ts.map +1 -1
  87. package/dist/lib/run-test-result.js +41 -54
  88. package/dist/lib/run-test-result.js.map +1 -1
  89. package/dist/test/bundle/cli-bundle.test.d.ts +2 -0
  90. package/dist/test/bundle/cli-bundle.test.d.ts.map +1 -0
  91. package/dist/test/bundle/cli-bundle.test.js +190 -0
  92. package/dist/test/bundle/cli-bundle.test.js.map +1 -0
  93. package/dist/test/e2e/cli-bundle.e2e.test.d.ts +2 -0
  94. package/dist/test/e2e/cli-bundle.e2e.test.d.ts.map +1 -0
  95. package/dist/test/e2e/cli-bundle.e2e.test.js +138 -0
  96. package/dist/test/e2e/cli-bundle.e2e.test.js.map +1 -0
  97. package/dist/test/e2e/git-build-release.e2e.test.d.ts +2 -0
  98. package/dist/test/e2e/git-build-release.e2e.test.d.ts.map +1 -0
  99. package/dist/test/e2e/git-build-release.e2e.test.js +87 -0
  100. package/dist/test/e2e/git-build-release.e2e.test.js.map +1 -0
  101. package/dist/test/e2e/helpers.d.ts +37 -0
  102. package/dist/test/e2e/helpers.d.ts.map +1 -0
  103. package/dist/test/e2e/helpers.js +57 -0
  104. package/dist/test/e2e/helpers.js.map +1 -0
  105. package/dist/test/unit/bin/affected-actors-cli.test.d.ts +2 -0
  106. package/dist/test/unit/bin/affected-actors-cli.test.d.ts.map +1 -0
  107. package/dist/test/unit/bin/affected-actors-cli.test.js +167 -0
  108. package/dist/test/unit/bin/affected-actors-cli.test.js.map +1 -0
  109. package/dist/test/unit/bin/affected-actors.test.d.ts +2 -0
  110. package/dist/test/unit/bin/affected-actors.test.d.ts.map +1 -0
  111. package/dist/test/unit/bin/affected-actors.test.js +141 -0
  112. package/dist/test/unit/bin/affected-actors.test.js.map +1 -0
  113. package/dist/test/unit/bin/build-cli.test.d.ts +2 -0
  114. package/dist/test/unit/bin/build-cli.test.d.ts.map +1 -0
  115. package/dist/test/unit/bin/build-cli.test.js +44 -0
  116. package/dist/test/unit/bin/build-cli.test.js.map +1 -0
  117. package/dist/test/unit/bin/build-from-local.test.js +65 -1
  118. package/dist/test/unit/bin/build-from-local.test.js.map +1 -1
  119. package/dist/test/unit/bin/build.test.js +223 -3
  120. package/dist/test/unit/bin/build.test.js.map +1 -1
  121. package/dist/test/unit/bin/compiled-cli.d.ts +6 -0
  122. package/dist/test/unit/bin/compiled-cli.d.ts.map +1 -0
  123. package/dist/test/unit/bin/compiled-cli.js +16 -0
  124. package/dist/test/unit/bin/compiled-cli.js.map +1 -0
  125. package/dist/test/unit/bin/diff-changes.test.js +205 -85
  126. package/dist/test/unit/bin/diff-changes.test.js.map +1 -1
  127. package/dist/test/unit/bin/diff.test.js +25 -28
  128. package/dist/test/unit/bin/diff.test.js.map +1 -1
  129. package/dist/test/unit/bin/git.test.js +69 -152
  130. package/dist/test/unit/bin/git.test.js.map +1 -1
  131. package/dist/test/unit/bin/slack.test.d.ts +2 -0
  132. package/dist/test/unit/bin/slack.test.d.ts.map +1 -0
  133. package/dist/test/unit/bin/slack.test.js +71 -0
  134. package/dist/test/unit/bin/slack.test.js.map +1 -0
  135. package/dist/test/unit/bin/stdin-input.test.d.ts +2 -0
  136. package/dist/test/unit/bin/stdin-input.test.d.ts.map +1 -0
  137. package/dist/test/unit/bin/stdin-input.test.js +50 -0
  138. package/dist/test/unit/bin/stdin-input.test.js.map +1 -0
  139. package/dist/test/unit/github-scripts/mask-config-secrets.test.d.ts +2 -0
  140. package/dist/test/unit/github-scripts/mask-config-secrets.test.d.ts.map +1 -0
  141. package/dist/test/unit/github-scripts/mask-config-secrets.test.js +50 -0
  142. package/dist/test/unit/github-scripts/mask-config-secrets.test.js.map +1 -0
  143. package/dist/test/unit/github-scripts/run-with-apify-tokens.test.d.ts +2 -0
  144. package/dist/test/unit/github-scripts/run-with-apify-tokens.test.d.ts.map +1 -0
  145. package/dist/test/unit/github-scripts/run-with-apify-tokens.test.js +102 -0
  146. package/dist/test/unit/github-scripts/run-with-apify-tokens.test.js.map +1 -0
  147. package/dist/test/unit/run-checks.test.d.ts +2 -0
  148. package/dist/test/unit/run-checks.test.d.ts.map +1 -0
  149. package/dist/test/unit/run-checks.test.js +62 -0
  150. package/dist/test/unit/run-checks.test.js.map +1 -0
  151. package/dist/test/unit/run-test-result.test.d.ts +2 -0
  152. package/dist/test/unit/run-test-result.test.d.ts.map +1 -0
  153. package/dist/test/unit/run-test-result.test.js +34 -0
  154. package/dist/test/unit/run-test-result.test.js.map +1 -0
  155. package/dist/test/unit/should-built-and-test.test.js +41 -38
  156. package/dist/test/unit/should-built-and-test.test.js.map +1 -1
  157. package/dist/tsconfig.tsbuildinfo +1 -1
  158. package/docs/cli.md +373 -0
  159. package/docs/lib.md +271 -0
  160. package/docs/workflows.md +367 -0
  161. package/lib/extend-expect.ts +48 -258
  162. package/lib/lib.ts +24 -28
  163. package/lib/run-checks.ts +101 -0
  164. package/lib/run-test-result.ts +45 -55
  165. package/package.json +15 -3
  166. package/test/bundle/cli-bundle.test.ts +235 -0
  167. package/test/e2e/cli-bundle.e2e.test.ts +207 -0
  168. package/test/e2e/git-build-release.e2e.test.ts +113 -0
  169. package/test/e2e/helpers.ts +82 -0
  170. package/test/unit/bin/affected-actors-cli.test.ts +201 -0
  171. package/test/unit/bin/affected-actors.test.ts +182 -0
  172. package/test/unit/bin/build-cli.test.ts +55 -0
  173. package/test/unit/bin/build-from-local.test.ts +71 -0
  174. package/test/unit/bin/build.test.ts +279 -3
  175. package/test/unit/bin/compiled-cli.ts +17 -0
  176. package/test/unit/bin/diff-changes.test.ts +229 -85
  177. package/test/unit/bin/diff.test.ts +25 -28
  178. package/test/unit/bin/git.test.ts +85 -176
  179. package/test/unit/bin/slack.test.ts +84 -0
  180. package/test/unit/bin/stdin-input.test.ts +61 -0
  181. package/test/unit/github-scripts/mask-config-secrets.test.ts +61 -0
  182. package/test/unit/github-scripts/run-with-apify-tokens.test.ts +115 -0
  183. package/test/unit/run-checks.test.ts +76 -0
  184. package/test/unit/run-test-result.test.ts +44 -0
  185. package/test/unit/should-built-and-test.test.ts +46 -39
  186. package/.github/scripts/check-package-version-bump.mjs +0 -74
  187. package/.github/workflows-package-version +0 -1
package/README.md CHANGED
@@ -1,8 +1,71 @@
1
1
  # Apify Test Tools
2
2
 
3
- [Contributing link](CONTRIBUTING.md)
3
+ Build, test and release Apify Actors from a Git repository or local source code. The package has three parts:
4
4
 
5
- ## Getting Started
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.0` or later (uses [annotate](https://vitest.dev/guide/test-context.html#annotate))
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 that uses `apify-test-tools` must have an `apify-test-tools.config.json` file at the root. It lists the actors in the repo, their folders, their full names on the platform, and which env var holds the token to use for each. A top-level `mode` field picks the file's layout; leave it out to use the default `"legacy"` layout.
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
- See [Config file](#config-file) for the available modes and every field.
87
+ ### 3. Set up Actor folders
24
88
 
25
- ### 3. Set up actor folders
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
- Each actor in the config must have a `.actor/actor.json` file. The `dockerContextDir` field in `actor.json` defines the build context boundary — this is what the tool uses to determine which files can affect the actor's build.
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
- │ │ ├── .actor
35
- │ │ │ └── actor.json
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
- ├── core <- Core (hourly) tests
45
- │ └── core.test.ts
46
- ├── some.test.ts <- Daily tests can be anywhere inside platform/
47
- └── some-other.test.ts
117
+ ├── web-scraper.test.ts
118
+ ├── email-sender.test.ts
119
+ └── orchestrator
120
+ └── orchestrator.test.ts
48
121
  ```
49
122
 
50
- For a single-actor repo, set `"folder": "."` in the config and place `.actor/actor.json` at the repo root.
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
- 1. **Sibling exclusion** — files inside another actor's `folder` are excluded first. This prevents an actor with broad context from being triggered by changes that belong to a sibling actor.
57
- 2. **CHANGELOG classification** — a `CHANGELOG.md` file is always `cosmetic` (only triggers a release build, not tests), for every actor, regardless of context or folder. (See [issue #106](https://github.com/apify/apify-test-tools/issues/106).)
58
- 3. **Context matching** — the file must fall within one of the actor's context paths (`dockerContextDir` from `actor.json` by default, or `overrideActorContext` from config if set). Files outside every context path are skipped.
59
- 4. **Hardcoded ignore list, context-aware** — the file path is first "hoisted" relative to the context path it matched (e.g. a standalone actor's own `.eslintrc` is checked as just `.eslintrc`, not the full repo-root-relative path), then checked against repo-level dev file patterns (`.vscode/`, `.gitignore`, `.husky/`, `.eslintrc`, `eslint.config.mjs`, `.prettierrc`, `.editorconfig`). There's no hardcoded special-casing for legacy `code/`/`shared/` layouts — repos that need those directories treated as top-level must list them explicitly in `overrideActorContext`.
60
- 5. **`.dockerignore` filtering** — if a `.dockerignore` exists at the root of the actor's `dockerContextDir`, matching files are ignored. Patterns are resolved relative to `dockerContextDir`, matching Docker's own behavior.
61
- 6. **README classification** — a `README.md` file is `cosmetic` (only triggers a release build, not tests) if it lives inside the actor's own `folder`; otherwise it's ignored entirely, since it isn't documentation for this actor.
62
- 7. **Cosmetic JSON classification** — `.json` files inside the actor's own `.actor/` directory with only cosmetic schema changes (whitespace, key ordering) only trigger a release build.
63
- 8. **Functional** — everything else triggers both build and tests.
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
- - Core (hourly) tests go in `test/platform/core`
72
- - Daily tests go anywhere in `test/platform`
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
- ### Modes
140
+ For a single-Actor repo, set `"folder": "."` in the config and place `.actor/actor.json` at the repo root.
94
141
 
95
- The file's layout is picked by the top-level `mode` field. Each mode is a different way of writing the same thing: every mode resolves to a list of actors with the fields above, and the same rules apply to all of them — no two actors may share a `folder`, and no two entries may point at the same `actorFullName`. If `mode` is left out, [`"legacy"`](#legacy-mode) is used, so existing config files keep working unchanged.
142
+ ### 4. Write tests
96
143
 
97
- ### Legacy mode
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
- The default. A flat `actors` array where every entry carries all of its settings. Good for repos with a few actors, or where every actor has different settings.
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
- `actors` must hold at least one entry. Every entry takes all the [actor fields](#actor-fields) directly, and `tokenEnvVar` is required on each one.
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
- ### Grouped mode
152
+ ## Config file
123
153
 
124
- Actors are organized into `groups`, and each group sets `tokenEnvVar` and `overrideActorContext` once for all of its actors. Good for repos where many actors share the same token or context.
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/email-sender",
137
- "actorFullName": "myteam/email-sender",
138
- "overrideActorContext": ["actors/email-sender", "packages/mailer"]
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
- `groups` is an object with at least one group. The group key (`myteam`, `partner` above) is only a label for readability; it has no effect on the result, and it does not need to match any folder or username. Each group needs a `tokenEnvVar` and at least one actor, and can optionally set `overrideActorContext`.
151
-
152
- An actor inside a group can set its own `tokenEnvVar` or `overrideActorContext`, and that value replaces the group's for that actor only. Values are replaced, not merged: in the example above, `myteam/email-sender` gets `["actors/email-sender", "packages/mailer"]`, not `packages/shared` as well.
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
- ## Github worklows
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
- The reusable workflows live in this repo, alongside the package they call. They are the
157
- `public_`-prefixed files in `.github/workflows`; everything else there is this repo's own CI.
158
- Reference them at the `@workflows-v0` major tag, never at `@master` — see
159
- [Versioning and releases](#versioning-and-releases).
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
- There should be 4 GH workflow files in `.github/workflows`, plus an optional fifth for Claude reviews.
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
- ### `platform-tests-core.yaml`
196
+ No two Actors may share a `folder`, and no two entries may point at the same `actorFullName`.
164
197
 
165
- ```yaml
166
- name: Platform tests - Core
198
+ ## GitHub workflows
167
199
 
168
- on:
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
- jobs:
175
- platformTestsCore:
176
- uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0
177
- with:
178
- subtest: core
179
- secrets: inherit
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
- ### `platform-tests-daily.yaml`
210
+ These are GitHub Actions workflows. On another CI platform, build the same flow with the [CLI](docs/cli.md).
183
211
 
184
- ```yaml
185
- name: Platform tests - Daily
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: inherit
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: inherit
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
- This workflow runs `apify-test-tools release --base-commit ${{ github.event.before }}`. See
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
- Optional. Reviews a PR against the shared guidelines when you add the trigger label, and again on
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: Claude review
265
+ name: Platform tests - Daily
240
266
 
241
267
  on:
242
- pull_request:
243
- types: [labeled, synchronize]
268
+ schedule:
269
+ # Runs at 00:00 UTC every day
270
+ - cron: '0 0 * * *'
271
+ workflow_dispatch:
244
272
 
245
273
  jobs:
246
- review:
247
- uses: apify/apify-test-tools/.github/workflows/public_review.yaml@workflows-v0
248
- secrets: inherit
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
- The review instructions live in `.github/review-prompt.md` in this repo and are fetched at run time,
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
- - name: Build
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
- Here is full example of what you can validate with `toFinishWith`
416
-
417
- ```ts
418
- await expect(runResult).toFinishWith({
419
- // These are default
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
- ```ts
490
- testActor(actorId, 'with prefilled input', async ({ expect, run }) => {
491
- const runResult = await run({
492
- prefilledInput: true,
493
- input: { maxItems: 10 }, // merged on top of the prefilled input
494
- });
495
- await expect(runResult).toFinishWith({ datasetItemCount: 10 });
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
- You can skip starting a new run and validate an existing one by passing `runId`:
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
- ```ts
506
- testActor(actorId, 'validate existing run', async ({ expect, run }) => {
507
- const runResult = await run({ runId: 'some-run-id' });
508
- await expect(runResult).toFinishWith({ datasetItemCount: 100 });
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
- ### Accessing run data
318
+ ## Writing tests
515
319
 
516
- `RunTestResult` provides methods to access the run's data:
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
- testActor(actorId, 'check dataset items', async ({ expect, run }) => {
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
- ### Testing standby actors
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
- Use `testStandbyActor` for actors that support standby mode:
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
- ```ts
550
- import { describe, testStandbyActor } from 'apify-test-tools';
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
- ## CLI (`apify-test-tools` bin)
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
- # Build from local source and capture output
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
- Since you already scoped the build to just the Actor(s) you care about, point vitest at a specific test file (or a `-t` name filter) instead of the whole `test/platform` directory — you get feedback on that one test without waiting for the full suite to run.
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.