Skip to content
Open
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
9 changes: 8 additions & 1 deletion core/lib/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ function extractFramesFromTimeline(timeline, opts) {
/** @type {Array<TraceEvent>} */
let events = trace.traceEvents || trace;

// Try to find navigationStart
let navigationStart = null;
const navStartEvent = events.find(e => e.name === 'navigationStart');
if (navStartEvent) {
navigationStart = navStartEvent.ts;
}

let startTs = Number.MAX_VALUE;
let endTs = -Number.MAX_VALUE;
events.forEach(e => {
Expand All @@ -122,7 +129,7 @@ function extractFramesFromTimeline(timeline, opts) {
endTs = Math.max(endTs, e.ts);
});

startTs = (opts.timeOrigin || startTs) / 1000;
startTs = (opts.timeOrigin || navigationStart || startTs) / 1000;
endTs /= 1000;

/** @type {?string} */
Expand Down
4 changes: 2 additions & 2 deletions core/test/frame.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ test('frames can set and retrieve progress', t => {

test('extract frames from timeline should return a data object with an array of frames', async t => {
const data = await frame.extractFramesFromTimeline('./test/assets/nyt.json');
t.is(data.startTs, 282644630.041, 'data.startTs doesn\'t match expected value');
t.is(Math.floor(data.startTs), 282646416, 'data.startTs doesn\'t match expected value');
t.truthy(data.endTs, 'data.endTs doesn\'t exist');
t.true(Array.isArray(data.frames), 'Frames is not an array');
});

test('extract frames should support json', async t => {
const trace = JSON.parse(fs.readFileSync('./test/assets/progressive-app.json', 'utf-8'));
const data = await frame.extractFramesFromTimeline(trace);
t.is(data.startTs, 103204916.772, 'data.startTs doesn\'t match expected value');
t.is(Math.floor(data.startTs), 103205446, 'data.startTs doesn\'t match expected value');
t.true(Array.isArray(data.frames), 'Frames is not an array');
t.is(data.frames.length, 6, 'Number of frames is incorrect');
});
Expand Down
6 changes: 3 additions & 3 deletions core/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ test('speedline return object should contain timing informations', async t => {
test('speedline return object should contain speed index', async t => {
const results = await speedline(TIMELINE_PATH);
t.is(typeof results.speedIndex, 'number');
t.is(Math.floor(results.speedIndex), 1134);
t.is(Math.floor(results.perceptualSpeedIndex), 1156);
t.is(Math.floor(results.speedIndex), 604);
t.is(Math.floor(results.perceptualSpeedIndex), 626);
});

test('speedline return object should only compute what is asked', async t => {
const results = await speedline(TIMELINE_PATH, {include: 'perceptualSpeedIndex'});
t.is(typeof results.speedIndex, 'undefined');
t.is(Math.floor(results.perceptualSpeedIndex), 1156);
t.is(Math.floor(results.perceptualSpeedIndex), 626);
});

test('speedline can takes timeOrigin option and adjusts results', async t => {
Expand Down
4 changes: 2 additions & 2 deletions core/test/speed-index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ test('speed indexes calculated for realistic trace', async t => {
speedIndex.calculateVisualProgress(data.frames);
speedIndex.calculatePerceptualProgress(data.frames);
const indexes = speedIndex.calculateSpeedIndexes(data.frames, data);
t.is(Math.floor(indexes.speedIndex), 542);
t.is(Math.floor(indexes.perceptualSpeedIndex), 578);
t.is(Math.floor(indexes.speedIndex), 537);
t.is(Math.floor(indexes.perceptualSpeedIndex), 573);
});

test('speed indexes calculated with --fast', t => {
Expand Down
Loading