Files
rrweb/test/packer.test.ts
yz-yu dcad6ff922 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
2026-04-01 12:00:00 +08:00

44 lines
1.1 KiB
TypeScript

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,
});
});
});