diff --git a/README.md b/README.md index 84ceeb9..f3f4c4b 100644 --- a/README.md +++ b/README.md @@ -439,14 +439,13 @@ Since you already scoped the build to just the Actor(s) you care about, point vi #### 5. Run tests against the builds -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). +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. If you want to run only certain tests, change the `test/platform` to be more specific. ```bash ACTOR_BUILDS='' \ TESTER_APIFY_TOKEN= \ -RUN_PLATFORM_TESTS=1 \ npx vitest --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 test/platform ``` @@ -463,7 +462,6 @@ BUILDS=$(APIFY_TOKEN_JOHN_DOE=apify_api_xxx \ # Run tests with the builds ACTOR_BUILDS="$BUILDS" \ TESTER_APIFY_TOKEN=apify_api_yyy \ -RUN_PLATFORM_TESTS=1 \ npx vitest --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 test/platform ``` diff --git a/lib/lib.ts b/lib/lib.ts index 5c83f31..7756bde 100644 --- a/lib/lib.ts +++ b/lib/lib.ts @@ -31,7 +31,7 @@ const config = actorBuilds.reduce>((map, cfg) => { export { ExpectStatic }; -const { TESTER_APIFY_TOKEN, RUN_PLATFORM_TESTS, RUN_ALL_PLATFORM_TESTS } = process.env; +const { TESTER_APIFY_TOKEN, RUN_ALL_PLATFORM_TESTS } = process.env; const apifyClient = new ApifyClient({ token: TESTER_APIFY_TOKEN }); const DEFAULT_TEST_OPTIONS: ActorTestOptions = { @@ -41,8 +41,14 @@ const DEFAULT_TEST_OPTIONS: ActorTestOptions = { timeout: DEFAULT_TEST_RUN_DURATION_MS, }; +/** + * Platform tests need `TESTER_APIFY_TOKEN` to talk to the platform, so without it we skip them altogether. + * + * `RUN_ALL_PLATFORM_TESTS` enables them too because locally we can test against a hardcoded `runId`, + * which doesn't need the tester token. + */ export const describe = (name: string, fn?: SuiteFactory, options: ActorTestOptions = DEFAULT_TEST_OPTIONS) => { - vitestDescribe.runIf(!!RUN_PLATFORM_TESTS || !!RUN_ALL_PLATFORM_TESTS)(name, options, fn); + vitestDescribe.runIf(!!TESTER_APIFY_TOKEN || !!RUN_ALL_PLATFORM_TESTS)(name, options, fn); }; const DEFAULT_TEST_ACTOR_OPTIONS: ActorTestOptions = { @@ -65,6 +71,8 @@ export const testActor = ( ...testOptions, }; const name = `${actorId}: ${testName}`; + // `RUN_ALL_PLATFORM_TESTS` is needed for the scheduled tests, which have no `ACTOR_BUILDS` to match the + // tests against - without it, every test would be filtered out as an actor we didn't build. const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorId); vitestTest.runIf(shouldRun)(name, options, async (context: TYPE) => { const { expect, ...rest } = context; @@ -97,6 +105,8 @@ export const testStandbyActor = ( ...testOptions, }; const name = `${actorId}: ${testName}`; + // `RUN_ALL_PLATFORM_TESTS` is needed for the scheduled tests, which have no `ACTOR_BUILDS` to match the + // tests against - without it, every test would be filtered out as an actor we didn't build. const shouldRun = !!RUN_ALL_PLATFORM_TESTS || config.has(actorId); vitestTest.runIf(shouldRun)(name, options, async (context: T) => {