mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Spawn mocha from test.js (#3818)
This commit is contained in:
parent
bb5bfed779
commit
fd9888f85e
@ -7,7 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node build.js",
|
"build": "node build.js",
|
||||||
"lint": "eslint js/ *.js",
|
"lint": "eslint js/ *.js",
|
||||||
"test": "mocha tests"
|
"test": "node test.js --mocha"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -27,7 +27,9 @@
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
|
import { spawn } from "child_process";
|
||||||
import { createRequire } from 'module';
|
import { createRequire } from 'module';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
enableWASM,
|
enableWASM,
|
||||||
@ -131,6 +133,10 @@ async function doHNTrie() {
|
|||||||
console.log("anotherTrie.matches('foo.invalid')", anotherTrie.matches('foo.invalid'));
|
console.log("anotherTrie.matches('foo.invalid')", anotherTrie.matches('foo.invalid'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function spawnMocha() {
|
||||||
|
await promisify(spawn)('mocha', [ 'tests' ], { stdio: [ 'inherit', 'inherit', 'inherit' ] });
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const result = await enableWASM();
|
const result = await enableWASM();
|
||||||
@ -144,7 +150,9 @@ async function main() {
|
|||||||
await doSNFE();
|
await doSNFE();
|
||||||
await doHNTrie();
|
await doHNTrie();
|
||||||
|
|
||||||
process.exit();
|
if ( process.argv[2] === '--mocha' ) {
|
||||||
|
await spawnMocha();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -24,88 +24,18 @@
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { createRequire } from 'module';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
enableWASM,
|
|
||||||
StaticNetFilteringEngine,
|
StaticNetFilteringEngine,
|
||||||
} from '../index.js';
|
} from '../index.js';
|
||||||
|
|
||||||
let engine = null;
|
let engine = null;
|
||||||
|
|
||||||
describe('SNFE', () => {
|
describe('SNFE', () => {
|
||||||
function fetch(listName) {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const require = createRequire(import.meta.url); // jshint ignore:line
|
|
||||||
resolve(require(`../data/${listName}.json`));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSNFE(engine) {
|
|
||||||
let result = 0;
|
|
||||||
|
|
||||||
// Tests
|
|
||||||
// Not blocked
|
|
||||||
result = engine.matchRequest({
|
|
||||||
originURL: 'https://www.bloomberg.com/',
|
|
||||||
url: 'https://www.bloomberg.com/tophat/assets/v2.6.1/that.css',
|
|
||||||
type: 'stylesheet'
|
|
||||||
});
|
|
||||||
if ( result !== 0 ) {
|
|
||||||
engine.toLogData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blocked
|
|
||||||
result = engine.matchRequest({
|
|
||||||
originURL: 'https://www.bloomberg.com/',
|
|
||||||
url: 'https://securepubads.g.doubleclick.net/tag/js/gpt.js',
|
|
||||||
type: 'script'
|
|
||||||
});
|
|
||||||
if ( result !== 0 ) {
|
|
||||||
engine.toLogData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unblocked
|
|
||||||
result = engine.matchRequest({
|
|
||||||
originURL: 'https://www.bloomberg.com/',
|
|
||||||
url: 'https://sourcepointcmp.bloomberg.com/ccpa.js',
|
|
||||||
type: 'script'
|
|
||||||
});
|
|
||||||
if ( result !== 0 ) {
|
|
||||||
engine.toLogData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
engine = await StaticNetFilteringEngine.create();
|
engine = await StaticNetFilteringEngine.create();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Basic', async () => {
|
|
||||||
beforeEach(async () => {
|
|
||||||
await engine.useLists([
|
|
||||||
fetch('easylist').then(raw => ({ name: 'easylist', raw })),
|
|
||||||
fetch('easyprivacy').then(raw => ({ name: 'easyprivacy', raw })),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it ('should work', async () => {
|
|
||||||
testSNFE(engine);
|
|
||||||
|
|
||||||
const serialized = await engine.serialize();
|
|
||||||
await engine.useLists([]);
|
|
||||||
|
|
||||||
assert.notDeepEqual(await engine.serialize(), serialized);
|
|
||||||
|
|
||||||
testSNFE(engine);
|
|
||||||
|
|
||||||
await engine.deserialize(serialized);
|
|
||||||
|
|
||||||
assert.deepEqual(await engine.serialize(), serialized);
|
|
||||||
|
|
||||||
testSNFE(engine);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Filter loading', () => {
|
describe('Filter loading', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
// This is in lieu of a constructor for a non-singleton.
|
// This is in lieu of a constructor for a non-singleton.
|
||||||
|
Loading…
Reference in New Issue
Block a user