Skip to content

Commit

Permalink
Add tests for SNFE deserialization (gorhill#3827)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjethani authored Aug 15, 2021
1 parent 8bb4424 commit e009d69
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions platform/npm/tests/snfe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit e009d69

Please sign in to comment.