From e009d69f86c5ba3bf6cb1077ecfb66623ab509ec Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Mon, 16 Aug 2021 02:58:16 +0530 Subject: [PATCH] Add tests for SNFE deserialization (#3827) --- platform/npm/tests/snfe.js | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/platform/npm/tests/snfe.js b/platform/npm/tests/snfe.js index 8f052bb34..38f6af544 100644 --- a/platform/npm/tests/snfe.js +++ b/platform/npm/tests/snfe.js @@ -177,4 +177,58 @@ describe('SNFE', () => { await engine.serialize(); }); }); + + describe('Deserialization', () => { + beforeEach(async () => { + const globals = { URL, setTimeout, clearTimeout }; + + const { StaticNetFilteringEngine } = await createWorld('./index.js', { globals }); + + engine = await StaticNetFilteringEngine.create(); + }); + + it('should not reject with no lists', async () => { + await engine.useLists([]); + + const serialized = await engine.serialize(); + await engine.deserialize(serialized); + }); + + it('should not reject with one empty list', async () => { + await engine.useLists([ + { name: 'easylist', raw: '' }, + ]); + + const serialized = await engine.serialize(); + await engine.deserialize(serialized); + }); + + it('should not reject with one list containing one filter', async () => { + await engine.useLists([ + { name: 'easylist', raw: '/foo^' }, + ]); + + const serialized = await engine.serialize(); + await engine.deserialize(serialized); + }); + + it('should not reject with one list containing multiple filters', async () => { + await engine.useLists([ + { name: 'easylist', raw: '/foo^\n||example.com^' }, + ]); + + const serialized = await engine.serialize(); + await engine.deserialize(serialized); + }); + + it('should not reject with multiple lists containing multiple filters', async () => { + await engine.useLists([ + { name: 'easylist', raw: '/foo^\n||example.com^' }, + { name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' }, + ]); + + const serialized = await engine.serialize(); + await engine.deserialize(serialized); + }); + }); });