2023-07-06 16:09:48 -04:00
import child _process from "child_process" ;
test ( "test custom behaviors" , async ( ) => {
2023-11-09 19:11:11 -05:00
const res = child _process . execSync (
"docker run -v $PWD/test-crawls:/crawls -v $PWD/tests/custom-behaviors/:/custom-behaviors/ webrecorder/browsertrix-crawler crawl --url https://example.com/ --url https://example.org/ --url https://webrecorder.net/ --customBehaviors /custom-behaviors/ --scopeType page" ,
) ;
2023-07-06 16:09:48 -04:00
const log = res . toString ( ) ;
// custom behavior ran for example.com
2023-11-09 19:11:11 -05:00
expect (
log . indexOf (
'{"state":{},"msg":"test-stat","page":"https://example.com/","workerid":0}}' ,
) > 0 ,
) . toBe ( true ) ;
2023-07-06 16:09:48 -04:00
// but not for example.org
2023-11-09 19:11:11 -05:00
expect (
log . indexOf (
'{"state":{},"msg":"test-stat","page":"https://example.org/","workerid":0}}' ,
) > 0 ,
) . toBe ( false ) ;
expect (
log . indexOf (
'{"state":{"segments":1},"msg":"Skipping autoscroll, page seems to not be responsive to scrolling events","page":"https://example.org/","workerid":0}}' ,
) > 0 ,
) . toBe ( true ) ;
2023-07-06 16:09:48 -04:00
// another custom behavior ran for webrecorder.net
2023-11-09 19:11:11 -05:00
expect (
log . indexOf (
'{"state":{},"msg":"test-stat-2","page":"https://webrecorder.net/","workerid":0}}' ,
) > 0 ,
) . toBe ( true ) ;
2023-07-06 16:09:48 -04:00
} ) ;
2023-12-13 12:14:53 -08:00
test ( "test invalid behavior exit" , async ( ) => {
let status = 0 ;
try {
child _process . execSync (
"docker run -v $PWD/test-crawls:/crawls -v $PWD/tests/invalid-behaviors/:/custom-behaviors/ webrecorder/browsertrix-crawler crawl --url https://example.com/ --url https://example.org/ --url https://webrecorder.net/ --customBehaviors /custom-behaviors/invalid-export.js --scopeType page" ,
) ;
} catch ( e ) {
status = e . status ;
}
// logger fatal exit code
expect ( status ) . toBe ( 17 ) ;
} ) ;