-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver: make driver optional, default to just calling loadPage()
tests: convert previous driver test to custom selector test with --selectLinks, also test invalid selector (no links extracted) tests: add new driver test to create PDF instead of using custom selector (no longer customizable via driver params)
- Loading branch information
Showing
6 changed files
with
101 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,15 @@ | ||
import child_process from "child_process"; | ||
import fs from "fs"; | ||
|
||
test("ensure custom driver with custom selector crawls JS files as pages", async () => { | ||
test("ensure custom driver creates PDF", async () => { | ||
try { | ||
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", | ||
"docker run -v $PWD/tests/fixtures:/tests/fixtures -v $PWD/test-crawls:/crawls webrecorder/browsertrix-crawler crawl --url https://old.webrecorder.net/ --collection custom-driver-1 --driver /tests/fixtures/driver-1.mjs --limit 1", | ||
); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
const crawledPages = fs.readFileSync( | ||
"test-crawls/collections/custom-driver-1/pages/pages.jsonl", | ||
"utf8", | ||
); | ||
const pages = new Set(); | ||
|
||
for (const line of crawledPages.trim().split("\n")) { | ||
const url = JSON.parse(line).url; | ||
if (!url) { | ||
continue; | ||
} | ||
pages.add(url); | ||
} | ||
|
||
const crawledExtraPages = fs.readFileSync( | ||
"test-crawls/collections/custom-driver-1/pages/extraPages.jsonl", | ||
"utf8", | ||
); | ||
const extraPages = new Set(); | ||
|
||
for (const line of crawledExtraPages.trim().split("\n")) { | ||
const url = JSON.parse(line).url; | ||
if (!url) { | ||
continue; | ||
} | ||
extraPages.add(url); | ||
} | ||
|
||
const expectedPages = new Set([ | ||
"https://www.iana.org/", | ||
]); | ||
|
||
const expectedExtraPages = new Set([ | ||
"https://www.iana.org/_js/jquery.js", | ||
"https://www.iana.org/_js/iana.js", | ||
]); | ||
|
||
expect(pages).toEqual(expectedPages); | ||
expect(extraPages).toEqual(expectedExtraPages); | ||
const pdfs = fs.readdirSync("test-crawls/collections/custom-driver-1").filter(x => x.endsWith(".pdf")); | ||
expect(pdfs.length).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import child_process from "child_process"; | ||
import fs from "fs"; | ||
|
||
test("test custom selector crawls JS files as pages", async () => { | ||
try { | ||
child_process.execSync( | ||
"docker run -v $PWD/test-crawls:/crawls webrecorder/browsertrix-crawler crawl --url https://www.iana.org/ --collection custom-sel-1 --selectLinks \"script[src]->src\"", | ||
); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
const crawledPages = fs.readFileSync( | ||
"test-crawls/collections/custom-sel-1/pages/pages.jsonl", | ||
"utf8", | ||
); | ||
const pages = new Set(); | ||
|
||
for (const line of crawledPages.trim().split("\n")) { | ||
const url = JSON.parse(line).url; | ||
if (!url) { | ||
continue; | ||
} | ||
pages.add(url); | ||
} | ||
|
||
const crawledExtraPages = fs.readFileSync( | ||
"test-crawls/collections/custom-sel-1/pages/extraPages.jsonl", | ||
"utf8", | ||
); | ||
const extraPages = new Set(); | ||
|
||
for (const line of crawledExtraPages.trim().split("\n")) { | ||
const url = JSON.parse(line).url; | ||
if (!url) { | ||
continue; | ||
} | ||
extraPages.add(url); | ||
} | ||
|
||
const expectedPages = new Set([ | ||
"https://www.iana.org/", | ||
]); | ||
|
||
const expectedExtraPages = new Set([ | ||
"https://www.iana.org/_js/jquery.js", | ||
"https://www.iana.org/_js/iana.js", | ||
]); | ||
|
||
expect(pages).toEqual(expectedPages); | ||
expect(extraPages).toEqual(expectedExtraPages); | ||
}); | ||
|
||
|
||
test("test invalid selector, no pages extracted", async () => { | ||
try { | ||
child_process.execSync( | ||
"docker run -v $PWD/test-crawls:/crawls webrecorder/browsertrix-crawler crawl --url https://www.iana.org/ --collection custom-sel-invalid --selectLinks \"script[\"", | ||
); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
const crawledExtraPages = fs.readFileSync( | ||
"test-crawls/collections/custom-sel-invalid/pages/extraPages.jsonl", | ||
"utf8", | ||
); | ||
expect(crawledExtraPages.trim().split("\n").length).toBe(1); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default async ({ data, page, crawler }) => { | ||
await crawler.loadPage(page, data, [ | ||
{ selector: "script[src]", extract: "src", isAttribute: false }, | ||
]); | ||
await crawler.loadPage(page, data); | ||
|
||
await page.pdf({"path": `${crawler.collDir}/${data.pageid}.pdf`}); | ||
}; |