Skip to content

feat: Support running Actors under test locally - #254

Draft
janbuchar wants to merge 9 commits into
throwaway-actorsfrom
local-runs
Draft

janbuchar wants to merge 9 commits into
throwaway-actorsfrom
local-runs

Conversation

@janbuchar

@janbuchar janbuchar commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a local runtime for ad-hoc Actors: run({ runtime: 'local' }) runs the Actor the way it would on somebody's machine, with the SDK's local storage and none of the platform's ACTOR_*/APIFY_* variables. See "Running locally" in docs/lib.md.

  • contributes to local: run-local wrapper #101 — covers ad-hoc Actors (defineActor) only, not apify run on an arbitrary Actor repo
  • APIFY_LOCAL_RUNS_ON decides where a local run executes: machine (default) spawns the Actor on the machine running the tests, platform runs it on the platform inside the Actor's own image, through a launcher that hides the platform from it and copies its local storage to the run. The test doesn't change between the two
  • RunOutcome is what both a platform and a local result provide: status, getDataset, getStatistics, getLog, getRunInfo and getRecord. toFinishWith and the other matchers take it, and run({ runtime: 'local' }) is typed to return it
  • RunTestResult.getRecord(key) is new, a record of the default store decoded like apify-client does

Notes for review

  • new runtime dependency @crawlee/fs-storage-native, the library Crawlee 4 writes local storage with. It's native. The build for local runs on the platform gets it under the alias apify-test-tools-storage, so it doesn't replace the Actor's own copy
  • a Crawlee 3 store is read too, but its records appear under their filenames (OUTPUT.json)
  • local runs on the platform cost a second build per Actor and bring back only the default dataset and key-value store
  • the launcher sets CRAWLEE_DISABLE_BROWSER_SANDBOX: Chrome's sandbox can't start in a container, and the SDK only turns it off when it knows it's on the platform
  • both variants need the Actor to start with npm start and to exit when done
  • nothing is charged off the platform, so chargedEventCounts can only be asserted as 0 on a local run
  • prepare builds the package and there's an .npmignore, so that test: Restructure e2e tests apify-sdk-js#863 and refactor: Restructure e2e tests using apify-test-tools crawlee#4375 can install it from a commit. Both go away before merging
  • fix: Wait for chargedEventCounts in toFinishWith #262 adds fetchRunInfo, which RunOutcome and LocalRunResult will need once both are in

@janbuchar janbuchar added t-tooling Issues with this label are in the ownership of the tooling team. adhoc Ad-hoc unplanned task added during the sprint. labels Nov 19, 2026
@janbuchar janbuchar self-assigned this Nov 20, 2026
@janbuchar
janbuchar added this pull request to stack #273 December 3, 2026 14:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant