Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter frames before timeOrigin #47

Merged
merged 1 commit into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 4, 'Frames were not filtered');
});