tweak the code of getting last session, without splice events array

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
committed by yz-yu
parent 19acba745a
commit ae71cf106a
4 changed files with 179 additions and 152 deletions

19
test/machine.test.ts Normal file
View File

@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { getLastSession } from '../src/replay/machine';
import { sampleEvents } from './utils';
import { EventType } from '../src/types';
const events = sampleEvents.filter(
(e) => ![EventType.DomContentLoaded, EventType.Load].includes(e.type),
);
describe('get last session', () => {
it('will return all the events when there is only one session', () => {
expect(getLastSession(events)).to.deep.equal(events);
});
it('will return last session when there is more than one in the events', () => {
const multiple = events.concat(events).concat(events);
expect(getLastSession(multiple)).to.deep.equal(events);
});
});