From bb5bfed7797c2e8a6dd80a9b3914c7c07960e3ff Mon Sep 17 00:00:00 2001 From: Manish Jethani Date: Sat, 14 Aug 2021 17:26:03 +0530 Subject: [PATCH] Add tests for promise-based filter loading (#3817) --- platform/nodejs/tests/snfe.js | 37 +++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/platform/nodejs/tests/snfe.js b/platform/nodejs/tests/snfe.js index d6b34dae6..13e8668a4 100644 --- a/platform/nodejs/tests/snfe.js +++ b/platform/nodejs/tests/snfe.js @@ -113,31 +113,52 @@ describe('SNFE', () => { }); it('should not reject on no lists', async () => { - await assert.doesNotReject(engine.useLists([])); + await engine.useLists([]); }); it('should not reject on one empty list', async () => { - await assert.doesNotReject(engine.useLists([ + await engine.useLists([ { name: 'easylist', raw: '' }, - ])); + ]); }); it('should not reject on one list containing one filter', async () => { - await assert.doesNotReject(engine.useLists([ + await engine.useLists([ { name: 'easylist', raw: '/foo^' }, - ])); + ]); }); it('should not reject on one list containing multiple filters', async () => { - await assert.doesNotReject(engine.useLists([ + await 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([ + await engine.useLists([ { name: 'easylist', raw: '/foo^\n||example.com^' }, { name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' }, + ]); + }); + + it('should not reject on promised-based lists', async () => { + await engine.useLists([ + Promise.resolve({ name: 'easylist', raw: '/foo^\n||example.com^' }), + Promise.resolve({ name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' }), + ]); + }); + + it('should reject on promised-based lists in which a promise is rejected', async () => { + await assert.rejects(engine.useLists([ + Promise.reject({ name: 'easylist', raw: '/foo^\n||example.com^' }), + Promise.resolve({ name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' }), + ])); + }); + + it('should reject on promised-based lists in which all promises are rejected', async () => { + await assert.rejects(engine.useLists([ + Promise.reject({ name: 'easylist', raw: '/foo^\n||example.com^' }), + Promise.reject({ name: 'easyprivacy', raw: '||example.net/bar/\n^bar.js?' }), ])); }); });