1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-02 23:57:10 +02:00

Use createWorld() in request data tests (#3832)

This commit is contained in:
Manish Jethani 2021-08-17 16:50:13 +05:30 committed by GitHub
parent 75c386b4d9
commit f020e5334c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 50 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@gorhill/ubo-core",
"version": "0.1.8",
"version": "0.1.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -526,8 +526,9 @@
"dev": true
},
"esm-world": {
"version": "github:mjethani/esm-world#0e5a77a5c0cb22de28616bba9ed7247dee218fb3",
"from": "github:mjethani/esm-world#0e5a77a5c0cb22de28616bba9ed7247dee218fb3",
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/esm-world/-/esm-world-0.1.1.tgz",
"integrity": "sha512-BrUju/zoltW1L3MXWM3WZFpZddekSLnl0st7L//luZs3fbJ/o/3knWByewSic3RsMWCp3lGIh0GfA9WOEU8QxQ==",
"dev": true
},
"espree": {

View File

@ -32,7 +32,7 @@
"devDependencies": {
"c8": "^7.8.0",
"eslint": "^7.32.0",
"esm-world": "github:mjethani/esm-world#0e5a77a5c0cb22de28616bba9ed7247dee218fb3",
"esm-world": "0.1.1",
"mocha": "^9.0.3",
"scaling-palm-tree": "github:mjethani/scaling-palm-tree#15cf1ab37e038771e1ff8005edc46d95f176739f"
}

View File

@ -32,7 +32,12 @@ import { promisify } from 'util';
/******************************************************************************/
async function spawnMocha() {
await promisify(spawn)('mocha', [ '--experimental-vm-modules', '--no-warnings', 'tests', '--reporter', 'progress' ], { stdio: [ 'inherit', 'inherit', 'inherit' ] });
const files = [
'tests/snfe.js',
'tests/request-data.js',
];
await promisify(spawn)('mocha', [ '--experimental-vm-modules', '--no-warnings', ...files, '--reporter', 'progress' ], { stdio: [ 'inherit', 'inherit', 'inherit' ] });
}
async function main() {

View File

@ -0,0 +1,34 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-present Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/
'use strict';
/******************************************************************************/
import process from 'process';
process.on('warning', warning => {
// Ignore warnings about experimental features like
// --experimental-vm-modules
if ( warning.name !== 'ExperimentalWarning' ) {
console.warn(warning.stack);
}
});

View File

@ -29,6 +29,10 @@ import { createRequire } from 'module';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import { createWorld } from 'esm-world';
import './_common.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
@ -59,46 +63,40 @@ describe('Request data', () => {
texttrack: 'other',
};
let enableWASM = null;
let engine = null;
before(async () => {
const module = await import('../index.js');
enableWASM = module.enableWASM;
engine = await module.StaticNetFilteringEngine.create();
await engine.useLists([
read('./data/assets/ublock/badware.txt')
.then(raw => ({ name: 'badware', raw })),
read('./data/assets/ublock/filters.txt')
.then(raw => ({ name: 'filters', raw })),
read('./data/assets/ublock/filters-2020.txt')
.then(raw => ({ name: 'filters-2020', raw })),
read('./data/assets/ublock/filters-2021.txt')
.then(raw => ({ name: 'filters-2021', raw })),
read('./data/assets/ublock/privacy.txt')
.then(raw => ({ name: 'privacy', raw })),
read('./data/assets/ublock/resource-abuse.txt')
.then(raw => ({ name: 'resource-abuse', raw })),
read('./data/assets/ublock/unbreak.txt')
.then(raw => ({ name: 'unbreak.txt', raw })),
read('./data/assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt')
.then(raw => ({ name: 'easylist', raw })),
read('./data/assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt')
.then(raw => ({ name: 'easyprivacy', raw })),
read('./data/assets/thirdparties/pgl.yoyo.org/as/serverlist')
.then(raw => ({ name: 'PGL', raw })),
read('./data/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt')
.then(raw => ({ name: 'urlhaus', raw })),
]);
});
// False must go first:
// https://github.com/gorhill/uBlock/pull/3828#issuecomment-899470383
for ( let wasm of [ false, true ] ) {
context(`${wasm ? 'Wasm on' : 'Wasm off'}`, () => {
let engine = null;
before(async () => {
const { StaticNetFilteringEngine, enableWASM } = await createWorld('./index.js', { globals: global });
engine = await StaticNetFilteringEngine.create();
await engine.useLists([
read('./data/assets/ublock/badware.txt')
.then(raw => ({ name: 'badware', raw })),
read('./data/assets/ublock/filters.txt')
.then(raw => ({ name: 'filters', raw })),
read('./data/assets/ublock/filters-2020.txt')
.then(raw => ({ name: 'filters-2020', raw })),
read('./data/assets/ublock/filters-2021.txt')
.then(raw => ({ name: 'filters-2021', raw })),
read('./data/assets/ublock/privacy.txt')
.then(raw => ({ name: 'privacy', raw })),
read('./data/assets/ublock/resource-abuse.txt')
.then(raw => ({ name: 'resource-abuse', raw })),
read('./data/assets/ublock/unbreak.txt')
.then(raw => ({ name: 'unbreak.txt', raw })),
read('./data/assets/thirdparties/easylist-downloads.adblockplus.org/easylist.txt')
.then(raw => ({ name: 'easylist', raw })),
read('./data/assets/thirdparties/easylist-downloads.adblockplus.org/easyprivacy.txt')
.then(raw => ({ name: 'easyprivacy', raw })),
read('./data/assets/thirdparties/pgl.yoyo.org/as/serverlist')
.then(raw => ({ name: 'PGL', raw })),
read('./data/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt')
.then(raw => ({ name: 'urlhaus', raw })),
]);
if ( wasm ) {
assert(await enableWASM());
}

View File

@ -24,17 +24,10 @@
/******************************************************************************/
import { strict as assert } from 'assert';
import process from 'process';
import { createWorld } from 'esm-world';
process.on('warning', warning => {
// Ignore warnings about experimental features like
// --experimental-vm-modules
if ( warning.name !== 'ExperimentalWarning' ) {
console.warn(warning.stack);
}
});
import './_common.js';
let engine = null;