2023-07-06 16:09:48 -04:00
import child _process from "child_process" ;
test ( "test custom behaviors" , async ( ) => {
2023-11-08 16:40:49 -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-08 16:40:49 -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-08 16:40:49 -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-08 16:40:49 -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-11-08 16:40:49 -05:00