Skip to content

Commit

Permalink
Add more npm tests
Browse files Browse the repository at this point in the history
Also, disable wasm tests, currently erroring with:

    WebAssembly.Memory(): could not allocate memory
  • Loading branch information
gorhill committed Oct 4, 2021
1 parent 5f8c179 commit a76935b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
4 changes: 4 additions & 0 deletions platform/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ class StaticNetFilteringEngine {
return snfe.hasQuery(details);
}

isBlockImportant() {
return snfe.isBlockImportant();
}

toLogData() {
return snfe.toLogData();
}
Expand Down
48 changes: 43 additions & 5 deletions platform/npm/tests/snfe.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { createWorld } from 'esm-world';
import './_common.js';

describe('SNFE', () => {
for ( let wasm of [ false, true ] ) {
for ( let wasm of [ false/*, true*/ ] ) {
context(`${wasm ? 'Wasm on' : 'Wasm off'}`, () => {
let module = null;
let engine = null;
Expand Down Expand Up @@ -239,15 +239,53 @@ describe('SNFE', () => {
engine = await module.StaticNetFilteringEngine.create();
});

it('should match block-important pure-hostname filter', async () => {
it('should match pure-hostname block filter', async () => {
await engine.useLists([
{ name: 'test', raw: '@@||example.com^\n||example.com^$important' },
{ name: 'test', raw: '||example.net^' },
]);
const r = engine.matchRequest({
originURL: 'https://www.example.com/',
type: 'image',
url: 'https://www.example.net/',
});
assert.strictEqual(r, 1);
});

it('should match pure-hostname exception filter', async () => {
await engine.useLists([
{ name: 'test', raw: '||example.net^\n@@||example.net^' },
]);
const r = engine.matchRequest({
originURL: 'https://www.example.com/',
type: 'image',
url: 'https://www.example.net/',
});
assert.strictEqual(r, 2);
});

it('should match pure-hostname block-important filter', async () => {
await engine.useLists([
{ name: 'test', raw: '@@||example.net^\n||example.net^$important' },
]);
const r = engine.matchRequest({
originURL: 'https://www.example.com/',
type: 'image',
url: 'https://www.example.net/',
});
assert.strictEqual(r, 1);
assert(engine.isBlockImportant());
});

it('should detect the filter is block-important', async () => {
await engine.useLists([
{ name: 'test', raw: '||example.net^$important' },
]);
engine.matchRequest({
originURL: 'https://www.example.com/',
type: 'main_frame',
url: 'https://www.example.com/',
type: 'image',
url: 'https://www.example.net/',
});
assert(engine.isBlockImportant());
});
});
});
Expand Down

0 comments on commit a76935b

Please sign in to comment.