diff --git a/platform/npm/package-lock.json b/platform/npm/package-lock.json index 41b2790b1..583c88d12 100644 --- a/platform/npm/package-lock.json +++ b/platform/npm/package-lock.json @@ -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": { diff --git a/platform/npm/package.json b/platform/npm/package.json index 48358011d..867f9eb96 100644 --- a/platform/npm/package.json +++ b/platform/npm/package.json @@ -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" } diff --git a/platform/npm/test.js b/platform/npm/test.js index 256b02c30..5be784b92 100644 --- a/platform/npm/test.js +++ b/platform/npm/test.js @@ -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() { diff --git a/platform/npm/tests/_common.js b/platform/npm/tests/_common.js new file mode 100644 index 000000000..a5a294b30 --- /dev/null +++ b/platform/npm/tests/_common.js @@ -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); + } +}); diff --git a/platform/npm/tests/request-data.js b/platform/npm/tests/request-data.js index f1f4bea70..d2a772982 100644 --- a/platform/npm/tests/request-data.js +++ b/platform/npm/tests/request-data.js @@ -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()); } diff --git a/platform/npm/tests/snfe.js b/platform/npm/tests/snfe.js index 38f6af544..387bd9f84 100644 --- a/platform/npm/tests/snfe.js +++ b/platform/npm/tests/snfe.js @@ -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;