Files
rrweb/packages/rrweb/test/machine.test.ts
Justin Halsall ad9bc3ed19 Chore: Move most types from rrweb to @rrweb/types package (#1031)
* Chore: Add move most types from rrweb to @rrweb/types package

* Split off type imports

* Split off type import to its own line

* Get vite to generate type definitions

* Apply formatting changes

* noEmit not allowed in tsconfig, moved it to build step

* Align version of @rrweb/types with main rrweb package

Based on @mark-fenng's comments https://github.com/rrweb-io/rrweb/pull/1031/files#r1002298176

* Move up keywords
2022-11-04 17:25:15 +08:00

48 lines
1.4 KiB
TypeScript

import { discardPriorSnapshots } from '../src/replay/machine';
import { sampleEvents } from './utils';
import { EventType } from '@rrweb/types';
const events = sampleEvents.filter(
(e) => ![EventType.DomContentLoaded, EventType.Load].includes(e.type),
);
const nextEvents = events.map((e) => ({
...e,
timestamp: e.timestamp + 1000,
}));
const nextNextEvents = nextEvents.map((e) => ({
...e,
timestamp: e.timestamp + 1000,
}));
describe('get last session', () => {
it('will return all the events when there is only one session', () => {
expect(discardPriorSnapshots(events, events[0].timestamp)).toEqual(events);
});
it('will return last session when there is more than one in the events', () => {
const multiple = events.concat(nextEvents).concat(nextNextEvents);
expect(
discardPriorSnapshots(
multiple,
nextNextEvents[nextNextEvents.length - 1].timestamp,
),
).toEqual(nextNextEvents);
});
it('will return last session when baseline time is future time', () => {
const multiple = events.concat(nextEvents).concat(nextNextEvents);
expect(
discardPriorSnapshots(
multiple,
nextNextEvents[nextNextEvents.length - 1].timestamp + 1000,
),
).toEqual(nextNextEvents);
});
it('will return all sessions when baseline time is prior time', () => {
expect(discardPriorSnapshots(events, events[0].timestamp - 1000)).toEqual(
events,
);
});
});