* introduce pako and add general packer interface

* add tests for packer

* use function API instead of class API for better tree shaking support

* refcatoring the rollup bundle config
This commit is contained in:
yz-yu
2020-04-07 18:03:47 +08:00
committed by GitHub
parent 18129bab70
commit 4f36d0e57d
23 changed files with 316 additions and 218 deletions

43
test/packer.test.ts Normal file
View File

@@ -0,0 +1,43 @@
import { expect } from 'chai';
import { matchSnapshot } from './utils';
import { pack, unpack } from '../src/packer';
import { eventWithTime, EventType } from '../src/types';
import { MARK } from '../src/packer/base';
const event: eventWithTime = {
type: EventType.DomContentLoaded,
data: {},
timestamp: new Date('2020-01-01').getTime(),
};
describe('pack', () => {
it('can pack event', () => {
const packedData = pack(event);
matchSnapshot(packedData, __filename, 'pack');
});
});
describe('unpack', () => {
it('is compatible with unpacked data 1', () => {
const result = unpack((event as unknown) as string);
expect(result).to.deep.equal(event);
});
it('is compatible with unpacked data 2', () => {
const result = unpack(JSON.stringify(event));
expect(result).to.deep.equal(event);
});
it('stop on unknown data format', () => {
expect(() => unpack('[""]')).to.throw('');
});
it('can unpack packed data', () => {
const packedData = pack(event);
const result = unpack(packedData);
expect(result).to.deep.equal({
...event,
v: MARK,
});
});
});