Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Apr 2, 2024
1 parent efb53c9 commit f636e80
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion src/converters/abp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default async function convert(filters) {
throw new Error("Unknown problem");
}
} catch (e) {
console.error(e);
errors.push(`Error: "${e.message}" in rule: "${filter}"`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/converters/adguard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const createFilter = (
);
};

export default async function convert(rules, { resourcesPath }) {
export default async function convert(rules, { resourcesPath } = {}) {
const filter = createFilter(rules.map(normalizeFilter));
const conversionResult = await converter.convertStaticRuleSet(filter, { resourcesPath });
const declarativeRules = await conversionResult.ruleSet.getDeclarativeRules();
Expand Down
6 changes: 4 additions & 2 deletions test/unit/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ function normalize(rule) {
}

export async function testRule(rule) {
const { rules: adguardRules } = await convertWithAdguard([rule]);
const { rules: abpRules } = await convertWithAbp([rule]);
try {
const { rules: adguardRules } = await convertWithAdguard([rule]);
const { rules: abpRules } = await convertWithAbp([rule]);

expect(adguardRules[0]).not.toBe(undefined);
expect(normalize(adguardRules[0])).toEqual(normalize(abpRules[0]));
} catch (e) {
e.message += `
Expand Down
13 changes: 10 additions & 3 deletions test/unit/trackerdb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test } from "bun:test";
import { readFileSync } from "node:fs";
import path from "node:path";
import loadTrackerDB from "@ghostery/trackerdb";
import { detectFilterType } from "@cliqz/adblocker";

import { ROOT_PATH } from "../../scripts/helpers/paths.js";
import { testRule } from "./helpers.js";
Expand All @@ -20,14 +21,20 @@ const engine = readFileSync(
const trackerDB = await loadTrackerDB(engine);

const UNSUPPORTED_FILTERS = [
'/baynote(-observer)?([0-9]+)\\.js/',
'/facebook\\.com\\/(v2\\.0\\/)?(plugins|widgets)\\/.*\\.php/'
"/baynote(-observer)?([0-9]+)\\.js/",
"/facebook\\.com\\/(v2\\.0\\/)?(plugins|widgets)\\/.*\\.php/",
];

test("TrackerDB filters", async () => {
for (const pattern of trackerDB.engine.metadata.getPatterns()) {
for (const filter of pattern.filters) {
if (UNSUPPORTED_FILTERS.includes(filter)) {
if (
UNSUPPORTED_FILTERS.includes(filter) ||
// not supported - https://gitlab.com/eyeo/adblockplus/abc/webext-ad-filtering-solution/-/issues/572
filter.includes(".*") ||
// ignore cosmetic filters
detectFilterType(filter) === 2
) {
continue;
}
await testRule(filter);
Expand Down

0 comments on commit f636e80

Please sign in to comment.