1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Spawn mocha from test.js (#3818)

This commit is contained in:
Manish Jethani 2021-08-14 20:03:49 +05:30 committed by GitHub
parent bb5bfed779
commit fd9888f85e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 72 deletions

View File

@ -7,7 +7,7 @@
"scripts": {
"build": "node build.js",
"lint": "eslint js/ *.js",
"test": "mocha tests"
"test": "node test.js --mocha"
},
"repository": {
"type": "git",

View File

@ -27,7 +27,9 @@
/******************************************************************************/
import { strict as assert } from 'assert';
import { spawn } from "child_process";
import { createRequire } from 'module';
import { promisify } from 'util';
import {
enableWASM,
@ -131,6 +133,10 @@ async function doHNTrie() {
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() {
try {
const result = await enableWASM();
@ -144,7 +150,9 @@ async function main() {
await doSNFE();
await doHNTrie();
process.exit();
if ( process.argv[2] === '--mocha' ) {
await spawnMocha();
}
}
main();

View File

@ -24,88 +24,18 @@
/******************************************************************************/
import { strict as assert } from 'assert';
import { createRequire } from 'module';
import {
enableWASM,
StaticNetFilteringEngine,
} from '../index.js';
let engine = null;
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 () => {
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', () => {
beforeEach(async () => {
// This is in lieu of a constructor for a non-singleton.