Skip to content

Commit

Permalink
refactor: move heavy calls to before
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto committed Jan 14, 2025
1 parent c8da3bb commit 533110e
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/adblocker/test/engine/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,22 @@ $csp=baz,domain=bar.com
});
}

const requests = [
'https://foo.com?utm',
'https://foo.com?utm=',
'https://foo.com?utm=a',
'https://foo.com?utm=a&utm_source=organic',
'https://foo.com?utm_source=organic&utm=a',
].map(urlToDocumentRequest);
let requests: Request[];
before(() => {
requests = [
'https://foo.com?utm',
'https://foo.com?utm=',
'https://foo.com?utm=a',
'https://foo.com?utm=a&utm_source=organic',
'https://foo.com?utm_source=organic&utm=a',
].map(urlToDocumentRequest);
});

describe('removes all parameters', () => {
const engine = createEngine('||foo.com$removeparam');
let engine: FilterEngine;
before(() => {
engine = createEngine('||foo.com$removeparam');
});
for (const { match, redirect, request } of requests.map((request) => ({
...engine.match(request),
request,
Expand All @@ -635,7 +641,10 @@ $csp=baz,domain=bar.com
});

describe('removes specific parameter', () => {
const engine = createEngine('||foo.com$removeparam=utm');
let engine: FilterEngine;
before(() => {
engine = createEngine('||foo.com$removeparam=utm');
});
for (const { match, redirect, request } of requests.map((request) => ({
...engine.match(request),
request,
Expand All @@ -652,7 +661,10 @@ $csp=baz,domain=bar.com
});

describe('removes specific parameter regardless of ordering', () => {
const engine = createEngine('||foo.com$removeparam=utm');
let engine: FilterEngine;
before(() => {
engine = createEngine('||foo.com$removeparam=utm');
});
for (const { match, redirect, request } of [
// First
'https://foo.com?utm=a&utm_source=organic&utm_event=b',
Expand All @@ -676,10 +688,10 @@ $csp=baz,domain=bar.com

it('removes parameter sequentially', () => {
const params = ['utm', 'utm_source', 'utm_event'];
let request = urlToDocumentRequest('https://foo.com?utm_source=organic&utm_event=b&utm=a');
const engine = createEngine(
params.map((param) => `||foo.com$removeparam=${param}`).join('\n'),
);
let request = urlToDocumentRequest('https://foo.com?utm_source=organic&utm_event=b&utm=a');
for (let i = 0; i < params.length; i++) {
const { redirect } = engine.match(request);
expect(redirect).not.to.be.undefined;
Expand Down

0 comments on commit 533110e

Please sign in to comment.