-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathadblockrules.test.js
57 lines (46 loc) · 1.46 KB
/
adblockrules.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import child_process from "child_process";
import fs from "fs";
import yaml from "js-yaml";
function runCrawl(name, config, commandExtra = "") {
config.generateCDX = true;
config.depth = 0;
config.collection = name;
const configYaml = yaml.dump(config);
try {
const proc = child_process.execSync(
`docker run -i -v $PWD/test-crawls:/crawls webrecorder/browsertrix-crawler crawl --config stdin ${commandExtra}`,
{ input: configYaml, stdin: "inherit", encoding: "utf8" },
);
//console.log(proc);
} catch (error) {
console.log(error);
}
}
function doesCDXContain(coll, value) {
const data = fs.readFileSync(
`test-crawls/collections/${coll}/indexes/index.cdxj`,
);
return data.indexOf(value) >= 0;
}
// Test Disabled for Brave -- should always be blocked, but seeing inconsistent ci behavior
/*
test("test crawl without ad block for specific URL", () => {
const config = {
"url": "https://www.mozilla.org/en-US/firefox/",
"pageExtraDelay": 10
};
runCrawl("adblock-no-block", config);
// without ad blocking, URL with googletagmanager is included
expect(doesCDXContain("adblock-no-block", "www.googletagmanager.com")).toBe(true);
});
*/
test("testcrawl with ad block for specific URL", () => {
const config = {
url: "https://www.mozilla.org/en-US/firefox/",
blockAds: true,
};
runCrawl("adblock-block", config);
expect(doesCDXContain("adblock-block", "www.googletagmanager.com")).toBe(
false,
);
});