From ef0075acc1e3e2eccf1f4e940ef281d111da355f Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Sat, 14 Aug 2021 01:51:36 +0530 Subject: [PATCH] Add tests for filter loading (#3816) --- platform/nodejs/tests/snfe.js | 52 ++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/platform/nodejs/tests/snfe.js b/platform/nodejs/tests/snfe.js index dba745a39..d6b34dae6 100644 --- a/platform/nodejs/tests/snfe.js +++ b/platform/nodejs/tests/snfe.js @@ -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?' }, + ])); + }); + }); });