@@ -3,6 +3,8 @@ import { setTimeout } from 'node:timers/promises';
33import c from 'ansi-colors' ;
44import { ActorListSortBy , ApifyClient , LoggerActorRedirect } from 'apify-client' ;
55import express from 'express' ;
6+ import type { Page } from 'puppeteer' ;
7+ import type { AddressInfo } from 'net' ;
68import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , test , vi } from 'vitest' ;
79
810import { LEVELS , Log } from '@apify/log' ;
@@ -11,23 +13,24 @@ import { stringifyWebhooksToBase64 } from '../src/utils';
1113import { Browser , DEFAULT_OPTIONS , validateRequest } from './_helper' ;
1214import { createDefaultApp , mockServer } from './mock_server/server' ;
1315import { MOCKED_ACTOR_LOGS_PROCESSED , StatusGenerator } from './mock_server/test_utils' ;
16+ import { WEBHOOK_EVENT_TYPES } from '@apify/consts' ;
1417
1518describe ( 'Actor methods' , ( ) => {
16- let baseUrl ;
19+ let baseUrl : string ;
1720 const browser = new Browser ( ) ;
1821
1922 beforeAll ( async ( ) => {
20- const server = await mockServer . start ( ) ;
23+ const server = await mockServer . start ( ) as import ( 'http' ) . Server ;
2124 await browser . start ( ) ;
22- baseUrl = `http://localhost:${ server . address ( ) . port } ` ;
25+ baseUrl = `http://localhost:${ ( server . address ( ) as AddressInfo ) . port } ` ;
2326 } ) ;
2427
2528 afterAll ( async ( ) => {
2629 await Promise . all ( [ mockServer . close ( ) , browser . cleanUpBrowser ( ) ] ) ;
2730 } ) ;
2831
29- let client ;
30- let page ;
32+ let client : ApifyClient ;
33+ let page : Page ;
3134 beforeEach ( async ( ) => {
3235 page = await browser . getInjectedPage ( baseUrl , DEFAULT_OPTIONS ) ;
3336 client = new ApifyClient ( {
@@ -37,7 +40,8 @@ describe('Actor methods', () => {
3740 } ) ;
3841 } ) ;
3942 afterEach ( async ( ) => {
40- client = null ;
43+ // purge the client instance to avoid sharing state between tests
44+ client = null as any ;
4145 page . close ( ) . catch ( ( ) => { } ) ;
4246 } ) ;
4347
@@ -90,7 +94,7 @@ describe('Actor methods', () => {
9094 const actorId = 'some-id' ;
9195
9296 const res = await client . actor ( actorId ) . get ( ) ;
93- expect ( res . id ) . toEqual ( 'get-actor' ) ;
97+ expect ( res ? .id ) . toEqual ( 'get-actor' ) ;
9498 validateRequest ( { } , { actorId } ) ;
9599
96100 const browserRes = await page . evaluate ( ( id ) => client . actor ( id ) . get ( ) , actorId ) ;
@@ -115,7 +119,7 @@ describe('Actor methods', () => {
115119
116120 const defaultBuildClient = await client . actor ( actorId ) . defaultBuild ( ) ;
117121 const res = await defaultBuildClient . get ( ) ;
118- expect ( res . id ) . toEqual ( 'get-build' ) ;
122+ expect ( res ? .id ) . toEqual ( 'get-build' ) ;
119123 validateRequest ( { } , { buildId : 'default-build-get' } ) ;
120124
121125 const browserRes = await page . evaluate ( async ( id ) => {
@@ -179,7 +183,7 @@ describe('Actor methods', () => {
179183 const actorId = 'some-id' ;
180184 const input = {
181185 foo : 'bar' ,
182- fn : async ( a , b ) => a + b ,
186+ fn : async ( a : number , b : number ) => a + b ,
183187 } ;
184188
185189 const expectedRequestProps = [
@@ -196,7 +200,7 @@ describe('Actor methods', () => {
196200 const browserRes = await page . evaluate ( ( id ) => {
197201 return client . actor ( id ) . start ( {
198202 foo : 'bar' ,
199- fn : async ( a , b ) => a + b ,
203+ fn : async ( a : number , b : number ) => a + b ,
200204 } ) ;
201205 } , actorId ) ;
202206 expect ( browserRes ) . toEqual ( res ) ;
@@ -207,11 +211,11 @@ describe('Actor methods', () => {
207211 const actorId = 'some-id' ;
208212 const webhooks = [
209213 {
210- eventTypes : [ 'ACTOR.RUN.CREATED' ] ,
214+ eventTypes : [ WEBHOOK_EVENT_TYPES . ACTOR_RUN_CREATED ] ,
211215 requestUrl : 'https://example.com/run-created' ,
212216 } ,
213217 {
214- eventTypes : [ 'ACTOR.RUN.SUCCEEDED' ] ,
218+ eventTypes : [ WEBHOOK_EVENT_TYPES . ACTOR_RUN_SUCCEEDED ] ,
215219 requestUrl : 'https://example.com/run-succeeded' ,
216220 } ,
217221 ] ;
@@ -357,7 +361,7 @@ describe('Actor methods', () => {
357361 } ) ;
358362
359363 describe ( 'lastRun()' , ( ) => {
360- test . each ( [ 'get' , 'dataset' , 'keyValueStore' , 'requestQueue' , 'log' ] ) ( '%s() works' , async ( method ) => {
364+ test . each ( [ 'get' , 'dataset' , 'keyValueStore' , 'requestQueue' , 'log' ] as const ) ( '%s() works' , async ( method ) => {
361365 const actorId = 'some-actor-id' ;
362366 const requestedStatus = 'SUCCEEDED' ;
363367
@@ -367,7 +371,7 @@ describe('Actor methods', () => {
367371 if ( method === 'log' ) {
368372 expect ( res ) . toEqual ( 'last-run-log' ) ;
369373 } else {
370- expect ( res . id ) . toEqual ( `last-run-${ method } ` ) ;
374+ expect ( res ? .id ) . toEqual ( `last-run-${ method } ` ) ;
371375 }
372376 validateRequest ( { status : requestedStatus } , { actorId } ) ;
373377
@@ -581,7 +585,7 @@ describe('Actor methods', () => {
581585 const envVarName = 'TEST_ENV_VAR' ;
582586
583587 const res = await client . actor ( actorId ) . version ( versionNumber ) . envVar ( envVarName ) . get ( ) ;
584- expect ( res . id ) . toEqual ( 'get-actor-env-var' ) ;
588+ expect ( res ? .id ) . toEqual ( 'get-actor-env-var' ) ;
585589 validateRequest ( { } , { actorId, versionNumber, envVarName } ) ;
586590
587591 const browserRes = await page . evaluate (
@@ -681,8 +685,8 @@ describe('Actor methods', () => {
681685} ) ;
682686
683687describe ( 'Run actor with redirected logs' , ( ) => {
684- let baseUrl ;
685- let client ;
688+ let baseUrl : string ;
689+ let client : ApifyClient ;
686690 const statusGenerator = new StatusGenerator ( ) ;
687691
688692 beforeAll ( async ( ) => {
@@ -698,7 +702,7 @@ describe('Run actor with redirected logs', () => {
698702 } ) ;
699703 const app = createDefaultApp ( router ) ;
700704 const server = await mockServer . start ( undefined , app ) ;
701- baseUrl = `http://localhost:${ server . address ( ) . port } ` ;
705+ baseUrl = `http://localhost:${ ( server . address ( ) as AddressInfo ) . port } ` ;
702706 } ) ;
703707
704708 afterAll ( async ( ) => {
@@ -715,7 +719,7 @@ describe('Run actor with redirected logs', () => {
715719 afterEach ( async ( ) => {
716720 // Reset the generator to so that the next test starts fresh
717721 statusGenerator . reset ( ) ;
718- client = null ;
722+ client = null as unknown as ApifyClient ;
719723 } ) ;
720724
721725 const testCases = [
@@ -727,7 +731,7 @@ describe('Run actor with redirected logs', () => {
727731 log : new Log ( { level : LEVELS . DEBUG , prefix : 'custom prefix...' , logger : new LoggerActorRedirect ( ) } ) ,
728732 } ,
729733 } ,
730- ] ;
734+ ] as const ;
731735
732736 describe ( 'actor.call - redirected logs' , ( ) => {
733737 test . each ( testCases ) ( 'logOptions:$logOptions' , async ( { expectedPrefix, logOptions } ) => {
0 commit comments