Actor Testing
Try for free
No credit card required
View all Actors
Actor Testing
pocesar/actor-testing
Try for free
No credit card required
Test your actors with varying inputs and expected outputs, duplicates, bad output fields, or unexpected log messages using Jasmine
The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more
1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with your Apify API token
4const client = new ApifyClient({
5 token: '<YOUR_API_TOKEN>',
6});
7
8// Prepare Actor input
9const input = {
10 "testSpec": ({ it, xit, moment, _, run, expect, expectAsync, input, describe }) => {
11 (input.resource ? [
12 'beta',
13 ] : [
14 'latest',
15 ]).forEach((build) => {
16 describe(`${build} version`, () => {
17 it('test something-task', async () => {
18 const runResult = await run({
19 taskId: '',
20 });
21
22 await expectAsync(runResult).toHaveStatus('SUCCEEDED');
23 await expectAsync(runResult).withLog((log) => {
24 expect(log)
25 .withContext(runResult.format('ReferenceError'))
26 .not.toContain('ReferenceError');
27 expect(log)
28 .withContext(runResult.format('TypeError'))
29 .not.toContain('TypeError');
30 });
31
32 await expectAsync(runResult).withStatistics((stats) => {
33 expect(stats.requestsRetries)
34 .withContext(runResult.format('Request retries'))
35 .toBeLessThan(3);
36
37 expect(stats.crawlerRuntimeMillis)
38 .withContext(runResult.format('Run time'))
39 .toBeWithinRange(0.1 * 60000, 10 * 60000);
40 });
41
42 await expectAsync(runResult).withDataset(({ dataset, info }) => {
43 expect(info.cleanItemCount)
44 .withContext(runResult.format('Dataset cleanItemCount'))
45 .toBeGreaterThan(0);
46
47 expect(dataset.items)
48 .withContext(runResult.format('Dataset items array'))
49 .toBeNonEmptyArray();
50 });
51 });
52 });
53 });
54 },
55 "slackChannel": "#public-actors-tests-notifications",
56 "slackPrefix": "@lead-dev @actor-owner"
57};
58
59(async () => {
60 // Run the Actor and wait for it to finish
61 const run = await client.actor("pocesar/actor-testing").call(input);
62
63 // Fetch and print Actor results from the run's dataset (if any)
64 console.log('Results from dataset');
65 console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
66 const { items } = await client.dataset(run.defaultDatasetId).listItems();
67 items.forEach((item) => {
68 console.dir(item);
69 });
70})();
71
72// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
Developer
Maintained by Community
Actor metrics
- 1 monthly user
- 9 stars
- 86.2% runs succeeded
- Created in Dec 2020
- Modified about 2 months ago
Categories