browsertrix-crawler/tests/custom-behavior-flow.test.js
Ilya Kreymer c796996664
Support for behaviors from 'recorder flow' JSON created in devtools (#818)
New Feature:
- support 'flow behavior' from JSON specification
- detect .json files via --customBehaviors
- log behavior progress while running
- logging tweaks (via browsertrix-behaviors 0.8.4) to limit logging for
custom behaviors
- differentiate logging for iframes, move more behavior messages to
debug
- move initCrawlState() to happen earlier to ensure Redis logging can happen in case of fatal errors
- docs to be added in separate follow-up PR
2025-04-09 12:24:29 +02:00

49 lines
1.4 KiB
JavaScript

import child_process from "child_process";
import Redis from "ioredis";
async function sleep(time) {
await new Promise((resolve) => setTimeout(resolve, time));
}
test("test pushing behavior logs to redis", async () => {
const child = child_process.exec("docker run -p 36398:6379 -v $PWD/test-crawls:/crawls -v $PWD/tests/custom-behaviors/:/custom-behaviors/ -e CRAWL_ID=behavior-logs-flow-test --rm webrecorder/browsertrix-crawler crawl --debugAccessRedis --url https://webrecorder.net/ --customBehaviors /custom-behaviors/custom-flow.json --scopeType page --logBehaviorsToRedis --pageExtraDelay 20");
let crawlFinished = false;
child.on("exit", function () {
crawlFinished = true;
});
const redis = new Redis("redis://127.0.0.1:36398/0", { lazyConnect: true, retryStrategy: () => null });
await sleep(3000);
await redis.connect({ maxRetriesPerRequest: 50 });
let customLogLineCount = 0;
let done = false;
while (!crawlFinished) {
let res = null;
try {
res = await redis.rpop("behavior-logs-flow-test:b");
} catch (e) {
break;
}
if (!res) {
await sleep(500);
continue;
}
const json = JSON.parse(res);
if (json.context === "behaviorScriptCustom") {
customLogLineCount++;
}
if (json.message === "All Steps Done!") {
done = true;
}
}
expect(customLogLineCount).toEqual(4);
expect(done).toBe(true);
});