2022-10-24 15:30:10 +02:00
|
|
|
import child_process from "child_process";
|
|
|
|
import fs from "fs";
|
2021-07-23 18:31:43 -07:00
|
|
|
|
2022-10-24 15:30:10 +02:00
|
|
|
test("ensure custom driver with custom selector crawls JS files as pages", async () => {
|
2021-07-23 18:31:43 -07:00
|
|
|
try {
|
2023-11-09 19:11:11 -05:00
|
|
|
child_process.execSync(
|
|
|
|
"docker run -v $PWD/tests/fixtures:/tests/fixtures -v $PWD/test-crawls:/crawls webrecorder/browsertrix-crawler crawl --url https://www.iana.org/ --collection custom-driver-1 --driver /tests/fixtures/driver-1.mjs",
|
|
|
|
);
|
|
|
|
} catch (error) {
|
2021-07-23 18:31:43 -07:00
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
|
2023-11-09 19:11:11 -05:00
|
|
|
const crawledPages = fs.readFileSync(
|
|
|
|
"test-crawls/collections/custom-driver-1/pages/pages.jsonl",
|
|
|
|
"utf8",
|
|
|
|
);
|
2021-07-23 18:31:43 -07:00
|
|
|
const pages = new Set();
|
|
|
|
|
|
|
|
for (const line of crawledPages.trim().split("\n")) {
|
|
|
|
const url = JSON.parse(line).url;
|
|
|
|
if (!url) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pages.add(url);
|
|
|
|
}
|
|
|
|
|
2021-11-23 12:53:30 -08:00
|
|
|
console.log(pages);
|
|
|
|
|
2021-07-23 18:31:43 -07:00
|
|
|
const expectedPages = new Set([
|
|
|
|
"https://www.iana.org/",
|
2021-11-23 12:53:30 -08:00
|
|
|
"https://www.iana.org/_js/jquery.js",
|
2023-11-09 19:11:11 -05:00
|
|
|
"https://www.iana.org/_js/iana.js",
|
2021-07-23 18:31:43 -07:00
|
|
|
]);
|
|
|
|
|
|
|
|
expect(pages).toEqual(expectedPages);
|
|
|
|
});
|