Skip to content

Commit

Permalink
fix: filter frames before timeOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed May 1, 2017
1 parent 2daef47 commit 8122b6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function extractFramesFromTimeline(timeline, opts) {
const startTs = (opts.timeOrigin || events[0].ts) / 1000;
const endTs = events[events.length - 1].ts / 1000;

const rawScreenshots = events.filter(e => e.cat.includes(screenshotTraceCategory));
const rawScreenshots = events.filter(e => e.cat.includes(screenshotTraceCategory) && e.ts > startTs * 1000);
const frames = rawScreenshots.map(function (evt) {
const base64img = evt.args && evt.args.snapshot;
const timestamp = evt.ts / 1000;
Expand Down
6 changes: 4 additions & 2 deletions test/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ test('extract frames should support json', async t => {
const data = await frame.extractFramesFromTimeline(trace);
t.is(data.startTs, 103204916.772, 'data.startTs doesn\'t match expected value');
t.true(Array.isArray(data.frames), 'Frames is not an array');
t.is(data.frames.length, 7, 'Number of frames is incorrect');
});

test('extract frames from timeline supports options', async t => {
const data = await frame.extractFramesFromTimeline('./assets/progressive-app.json', {timeOrigin: 103205446186});
t.is(data.startTs, 103205446.186, 'data.startTs doesn\'t match supplied timeOrigin value');
const data = await frame.extractFramesFromTimeline('./assets/progressive-app.json', {timeOrigin: 103206183179});
t.is(data.startTs, 103206183.179, 'data.startTs doesn\'t match supplied timeOrigin value');
t.truthy(data.endTs, 'data.endTs doesn\'t exist');
t.true(Array.isArray(data.frames), 'Frames is not an array');
t.is(data.frames.length, 3, 'Frames were not filtered');
});

0 comments on commit 8122b6e

Please sign in to comment.