Apify Test Tools
Build, test and release Apify Actors from a Git repository or local source code. The package has three parts:
-
A vitest library for writing platform tests that run your Actors on Apify and check the results:
testActor('myteam/web-scraper', 'scrapes the start URL', async ({ expect, run }) => {
const runResult = await run({ input: { startUrls: [{ url: 'https://apify.com' }] } });
await expect(runResult).toFinishWith({ datasetItemCount: { min: 1, max: 10 } });
});
-
A CLI that finds the Actors a change affects, builds them, and reports the results. It runs anywhere, so you
can build your own pipeline on it in any CI:
npx apify-test-tools get-affected-actors --base origin/master \
| jq '{ actors: (.functionallyChangedActors + .testChangedActors) }' \
| npx apify-test-tools build --version-number 0.99
-
Ready-made GitHub Actions workflows built on the CLI and the library, so a GitHub repo needs only a few lines
per workflow:
jobs:
buildDevelAndTest:
uses: apify/apify-test-tools/.github/workflows/public_pr-build-test.yaml@workflows-v0
secrets:
# One entry per secret apify-test-tools.config.json names: each `tokenEnvVar` and `testTokenEnvVar`
CONFIG_SECRETS: |
{ "APIFY_TOKEN_MYTEAM": "${{ secrets.APIFY_TOKEN_MYTEAM }}" }
Most repos only need the library and the workflows: the workflows call the CLI for you. Use the CLI directly only to
build your own pipeline, e.g. on a CI platform other than GitHub, or to build and test locally.
Only what changed is retested
Builds and platform tests cost time and money, so the tool skips everything a change can't affect:
- Only affected Actors. A changed file counts for Actors whose context contains it, subject to ignore rules,
or whose
actor.json links it. A shared file linked from actor.json affects every Actor that uses it.
- Cosmetic changes skip tests. Linked README/changelog edits and cosmetic schema changes don't trigger tests on a PR;
they're only rebuilt when released.
- Only new changes on a PR. Each push to a PR retests only the Actors that changed since its last green run, not
the whole PR again.
- Only their tests. Only the tests of the Actors that were built run.
See Change detection for the exact rules.
This README covers what you need to get a repo running. The full reference lives in docs/:
- Vitest library API —
testActor, testServerInterfaceActor, RunTestResult, matchers, running tests locally
- CLI API — every command, change detection, releasing, building locally
- Workflow API — every GitHub workflow, its inputs and secrets, versioning
Contributing
Getting started
Your Actors can be written in any programming language, e.g. Python: anything the platform builds from a Dockerfile
works. Only the tests and this tooling run on Node.js, so all a repo needs is a package.json at the root with
apify-test-tools and vitest in its devDependencies, and tests written in TypeScript or JavaScript. If you use the
PR workflow, also define the build-check, lint and test scripts
its static checks run, e.g. with your language's own linter and unit tests.
1. Install the package
npm i -D apify-test-tools
- Requires
vitest version 3.2.4 or later (uses annotate)
- Make sure
target and module in your tsconfig.json's compilerOptions are set to ES2022
- Every Actor must already have at least one build under its default build tag (usually
latest), built
from a Git repository version whose URL points to this repository. Build it once manually on the
platform before CI takes over. See Repository check.
2. Create the config file
Every repo must have an apify-test-tools.config.json file at the root that lists its Actors. See
Config file below.
3. Set up Actor folders
Each Actor in the config must have a .actor/actor.json file. The dockerContextDir field in actor.json defines
the build context boundary. Resolved documentation, schema, and Dockerfile links in actor.json also count as
dependencies even outside that context (see
Change detection).
This example has two Actors that share the code at the repo root, and one standalone Actor with its own code: