Packer (#172)
* 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:
43
test/packer.test.ts
Normal file
43
test/packer.test.ts
Normal 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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user