Skip to content

Commit 5c57aa7

Browse files
authored
feat: testing fix (#8)
* feat: initial testing fix * feat: testing for standard and advanced options * fix: code cleanup * fix: linting fixes * fix: minor testing polish * fix: linting fixes
1 parent 10e6edb commit 5c57aa7

File tree

7 files changed

+719
-1581
lines changed

7 files changed

+719
-1581
lines changed

nodes/ApifyContentCrawler/__tests__/Apify.node.spec.ts

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,60 @@ describe('Apify Node', () => {
3636

3737
describe('actors', () => {
3838
describe('run-actor', () => {
39-
it('should run the run-actor workflow and wait for finish', async () => {
40-
const mockRunActor = fixtures.runActorResult();
41-
const mockBuild = fixtures.getBuildResult();
42-
const mockFinishedRun = fixtures.getSuccessRunResult();
39+
const mockRunActor = fixtures.runActorResult();
40+
const mockBuild = fixtures.getBuildResult();
41+
const mockFinishedRun = fixtures.getSuccessRunResult();
42+
const mockResultDataset = fixtures.getDatasetItems();
4343

44-
const scope = nock('https://api.apify.com')
45-
.get(`/v2/acts/${ACTOR_ID}`)
46-
.reply(200, fixtures.getActorResult())
47-
.get(`/v2/acts/${ACTOR_ID}/builds/default`)
48-
.reply(200, mockBuild)
49-
.post(`/v2/acts/${ACTOR_ID}/runs`)
50-
.query({ waitForFinish: 0, build: mockBuild.data.buildNumber, memory: 1024 })
51-
.reply(200, mockRunActor)
52-
.get('/v2/actor-runs/Icz6E0IHX0c40yEi7')
53-
.reply(200, mockFinishedRun);
44+
const tests = [
45+
{
46+
name: 'Advanced Workflow',
47+
workflowJsonName: 'run-actor-advanced.workflow.json',
48+
nodeName: 'Crawl a Website (Advanced Settings)',
49+
},
50+
{
51+
name: 'Standard Workflow',
52+
workflowJsonName: 'run-actor-standard.workflow.json',
53+
nodeName: 'Crawl a Website (Standard Settings)',
54+
},
55+
];
5456

55-
const runActorWorkflow = require('./workflows/actors/run-actor-wait-for-finish.workflow.json');
56-
const { executionData } = await executeWorkflow({
57-
credentialsHelper,
58-
workflow: runActorWorkflow,
59-
});
57+
test.each(tests)(
58+
'$name should run the WCC actor correctly',
59+
async ({ workflowJsonName, nodeName }) => {
60+
const scope = nock('https://api.apify.com')
61+
.get(`/v2/acts/${ACTOR_ID}/builds/default`)
62+
.reply(200, mockBuild)
63+
.post(`/v2/acts/${ACTOR_ID}/runs`)
64+
.query({ waitForFinish: 0 })
65+
.reply(200, mockRunActor)
66+
.get('/v2/actor-runs/5rsC83CHinQwPlsSI')
67+
.reply(200, mockFinishedRun)
68+
.get('/v2/datasets/63kMAihbWVgBvEAZ2/items')
69+
.reply(200, mockResultDataset);
6070

61-
const nodeResults = getRunTaskDataByNodeName(executionData, 'Run actor');
62-
expect(nodeResults.length).toBe(1);
63-
const [nodeResult] = nodeResults;
64-
expect(nodeResult.executionStatus).toBe('success');
71+
const workflow = require(`./workflows/actors/${workflowJsonName}`);
72+
const { executionData } = await executeWorkflow({
73+
credentialsHelper,
74+
workflow,
75+
});
6576

66-
const data = getTaskData(nodeResult);
67-
// exptect polled terminal run as result
68-
expect(data).not.toEqual(mockRunActor.data);
69-
expect(data).toEqual(mockFinishedRun.data);
77+
const nodeResults = getRunTaskDataByNodeName(executionData, nodeName);
78+
expect(nodeResults.length).toBe(1);
7079

71-
expect(scope.isDone()).toBe(true);
72-
});
80+
const [nodeResult] = nodeResults;
81+
expect(nodeResult.executionStatus).toBe('success');
82+
83+
const data = getTaskData(nodeResult);
84+
expect(typeof data).toBe('object');
85+
86+
const first = data?.['0'] as { json: any };
87+
expect(first.json).toEqual(mockResultDataset[0]);
88+
89+
console.log(`Pending mocks for ${workflowJsonName}:`, scope.pendingMocks());
90+
expect(scope.isDone()).toBe(true);
91+
},
92+
);
7393
});
7494
});
7595
});

0 commit comments

Comments
 (0)