import { expect } from 'chai' ; import 'mocha' ; import { StaticDataView } from '../src/data-view' ; import CosmeticFilter from '../src/filters/cosmetic' ; import IFilter from '../src/filters/interface' ; import NetworkFilter from '../src/filters/network' ; import { parseFilters } from '../src/lists' ; import { allLists } from './utils' ; describe ( 'Make sure size estimate is accurate' , ( ) => { const { cosmeticFilters , networkFilters } = parseFilters ( allLists , { debug : true } ) ; function testSizeEstimate < T extends IFilter > ( filters , compression ) { const buffer = StaticDataView . allocate ( 1000000 , { enableCompression : compression } ) ; for ( let i = 0 ; i < filters . length ; i += 1 ) { const filter = filters [ i ] ; const estimate = filter . getSerializedSize ( compression ) ; buffer . seekZero ( ) ; filter . serialize ( buffer ) ; const realSize = buffer . pos ; if ( estimate !== realSize ) { expect ( estimate , filter . toString ( ) ) . to . equal ( realSize ) ; } } } it ( 'network' , ( ) => { testSizeEstimate < NetworkFilter > ( networkFilters , false ) ; } ) ; it ( 'network (compression)' , ( ) => { testSizeEstimate < NetworkFilter > ( networkFilters , true ) ; } ) ; it ( 'cosmetic' , ( ) => { testSizeEstimate < CosmeticFilter > ( cosmeticFilters , false ) ; } ) ; it ( 'cosmetic (compression)' , ( ) => { testSizeEstimate < CosmeticFilter > ( cosmeticFilters , true ) ; } ) ; } ) ;