1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-19 19:52:51 +02:00

Run SNFE tests with Wasm off and on (#3833)

This commit is contained in:
Manish Jethani 2021-08-17 17:54:07 +05:30 committed by GitHub
parent 9ceef65f9a
commit 0bf19cc683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 193 additions and 195 deletions

View File

@ -70,6 +70,10 @@ describe('Request data', () => {
before(async () => { before(async () => {
const { StaticNetFilteringEngine, enableWASM } = await createWorld('./index.js', { globals: global }); const { StaticNetFilteringEngine, enableWASM } = await createWorld('./index.js', { globals: global });
if ( wasm ) {
assert(await enableWASM());
}
engine = await StaticNetFilteringEngine.create(); engine = await StaticNetFilteringEngine.create();
await engine.useLists([ await engine.useLists([
@ -96,10 +100,6 @@ describe('Request data', () => {
read('./data/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt') read('./data/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt')
.then(raw => ({ name: 'urlhaus', raw })), .then(raw => ({ name: 'urlhaus', raw })),
]); ]);
if ( wasm ) {
assert(await enableWASM());
}
}); });
for ( let i = 0; i < requests.length; i++ ) { for ( let i = 0; i < requests.length; i++ ) {

View File

@ -29,46 +29,50 @@ import { createWorld } from 'esm-world';
import './_common.js'; import './_common.js';
let engine = null;
describe('SNFE', () => { describe('SNFE', () => {
describe('Initialization', () => { for ( let wasm of [ false, true ] ) {
let StaticNetFilteringEngine = null; context(`${wasm ? 'Wasm on' : 'Wasm off'}`, () => {
let module = null;
let engine = null;
beforeEach(async () => { beforeEach(async () => {
const module = await createWorld('./index.js', { globals: { URL } }); module = await createWorld('./index.js', { globals: global });
StaticNetFilteringEngine = module.StaticNetFilteringEngine; if ( wasm ) {
assert(await module.enableWASM());
}
}); });
afterEach(() => {
engine = null;
module = null;
});
describe('Initialization', () => {
it('should not reject on first attempt', async () => { it('should not reject on first attempt', async () => {
await StaticNetFilteringEngine.create(); await module.StaticNetFilteringEngine.create();
}); });
it('should reject on second attempt', async () => { it('should reject on second attempt', async () => {
await StaticNetFilteringEngine.create(); await module.StaticNetFilteringEngine.create();
await assert.rejects(StaticNetFilteringEngine.create()); await assert.rejects(module.StaticNetFilteringEngine.create());
}); });
it('should reject on third attempt', async () => { it('should reject on third attempt', async () => {
await StaticNetFilteringEngine.create(); await module.StaticNetFilteringEngine.create();
try { try {
await StaticNetFilteringEngine.create(); await module.StaticNetFilteringEngine.create();
} catch (error) { } catch (error) {
} }
await assert.rejects(StaticNetFilteringEngine.create()); await assert.rejects(module.StaticNetFilteringEngine.create());
}); });
}); });
describe('Filter loading', () => { describe('Filter loading', () => {
beforeEach(async () => { beforeEach(async () => {
const globals = { URL, setTimeout, clearTimeout }; engine = await module.StaticNetFilteringEngine.create();
const { StaticNetFilteringEngine } = await createWorld('./index.js', { globals });
engine = await StaticNetFilteringEngine.create();
}); });
it('should not reject on no lists', async () => { it('should not reject on no lists', async () => {
@ -124,11 +128,7 @@ describe('SNFE', () => {
describe('Serialization', () => { describe('Serialization', () => {
beforeEach(async () => { beforeEach(async () => {
const globals = { URL, setTimeout, clearTimeout }; engine = await module.StaticNetFilteringEngine.create();
const { StaticNetFilteringEngine } = await createWorld('./index.js', { globals });
engine = await StaticNetFilteringEngine.create();
}); });
it('should not reject with no lists', async () => { it('should not reject with no lists', async () => {
@ -173,11 +173,7 @@ describe('SNFE', () => {
describe('Deserialization', () => { describe('Deserialization', () => {
beforeEach(async () => { beforeEach(async () => {
const globals = { URL, setTimeout, clearTimeout }; engine = await module.StaticNetFilteringEngine.create();
const { StaticNetFilteringEngine } = await createWorld('./index.js', { globals });
engine = await StaticNetFilteringEngine.create();
}); });
it('should not reject with no lists', async () => { it('should not reject with no lists', async () => {
@ -224,4 +220,6 @@ describe('SNFE', () => {
await engine.deserialize(serialized); await engine.deserialize(serialized);
}); });
}); });
});
}
}); });