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

Add tests for filter loading (#3816)

This commit is contained in:
Manish Jethani 2021-08-14 01:51:36 +05:30 committed by GitHub
parent 806fe5dbe1
commit ef0075acc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,21 +76,23 @@ describe('SNFE', () => {
}
}
beforeEach(async () => {
before(async () => {
engine = await StaticNetFilteringEngine.create();
await engine.useLists([
fetch('easylist').then(raw => ({ name: 'easylist', raw })),
fetch('easyprivacy').then(raw => ({ name: 'easyprivacy', raw })),
]);
});
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();
engine.useLists([]);
await engine.useLists([]);
assert.notDeepEqual(await engine.serialize(), serialized);
@ -103,4 +105,40 @@ describe('SNFE', () => {
testSNFE(engine);
});
});
describe('Filter loading', () => {
beforeEach(async () => {
// This is in lieu of a constructor for a non-singleton.
await engine.useLists([]);
});
it('should not reject on no lists', async () => {
await assert.doesNotReject(engine.useLists([]));
});
it('should not reject on one empty list', async () => {
await assert.doesNotReject(engine.useLists([
{ name: 'easylist', raw: '' },
]));
});
it('should not reject on one list containing one filter', async () => {
await assert.doesNotReject(engine.useLists([
{ name: 'easylist', raw: '/foo^' },
]));
});
it('should not reject on one list containing multiple filters', async () => {
await assert.doesNotReject(engine.useLists([
{ name: 'easylist', raw: '/foo^\n||example.com^' },
]));
});
it('should not reject on multiple lists containing multiple filters', async () => {
await assert.doesNotReject(engine.useLists([
{ name: 'easylist', raw: '/foo^\n||example.com^' },
{ name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' },
]));
});
});
});