fix the skip event calculation (#242)

This commit is contained in:
yz-yu
2020-07-11 17:06:56 +08:00
committed by GitHub
parent 3e2b596664
commit e2cc42e393
5 changed files with 67 additions and 20 deletions

View File

@@ -6,14 +6,43 @@ import { EventType } from '../src/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(getLastSession(events)).to.deep.equal(events);
expect(getLastSession(events, events[0].timestamp)).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);
const multiple = events.concat(nextEvents).concat(nextNextEvents);
expect(
getLastSession(
multiple,
nextNextEvents[nextNextEvents.length - 1].timestamp,
),
).to.deep.equal(nextNextEvents);
});
it('will return last session when baseline time is future time', () => {
const multiple = events.concat(nextEvents).concat(nextNextEvents);
expect(
getLastSession(
multiple,
nextNextEvents[nextNextEvents.length - 1].timestamp + 1000,
),
).to.deep.equal(nextNextEvents);
});
it('will return first session when baseline time is previous time', () => {
expect(getLastSession(events, events[0].timestamp - 1000)).to.deep.equal(
events,
);
});
});

View File

@@ -6,6 +6,7 @@ import * as puppeteer from 'puppeteer';
import { expect } from 'chai';
import { Suite } from 'mocha';
import { launchPuppeteer, sampleEvents as events } from './utils';
import { EventType } from '../src/types';
interface ISuite extends Suite {
code: string;
@@ -59,7 +60,11 @@ describe('replayer', function (this: ISuite) {
replayer.play();
replayer['timer']['actions'].length;
`);
expect(actionLength).to.equal(events.length);
expect(actionLength).to.equal(
events.filter(
(e) => ![EventType.DomContentLoaded, EventType.Load].includes(e.type),
).length,
);
});
it('will clean actions when pause', async () => {