Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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='<JSON output from build command>' \
TESTER_APIFY_TOKEN=<token> \
RUN_PLATFORM_TESTS=1 \
npx vitest --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 test/platform
```

Expand All @@ -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
```

Expand Down
14 changes: 12 additions & 2 deletions lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const config = actorBuilds.reduce<Map<string, ActorBuild>>((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 = {
Expand All @@ -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<object>, 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 = {
Expand All @@ -65,6 +71,8 @@ export const testActor = <T>(
...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 <TYPE extends TestContext>(context: TYPE) => {
const { expect, ...rest } = context;
Expand Down Expand Up @@ -97,6 +105,8 @@ export const testStandbyActor = <I = any, O = any>(
...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 <T extends TestContext>(context: T) => {
Expand Down
Loading