Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Dec 10, 2018
1 parent a69895f commit 4386d40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
4 changes: 0 additions & 4 deletions lighthouse-core/computed/metrics/lantern-max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const LanternFirstContentfulPaint = require('./lantern-first-contentful-paint.js
/** @typedef {BaseNode.Node} Node */

class LanternMaxPotentialFID extends LanternMetricArtifact {
get name() {
return 'LanternMaxPotentialFID';
}

/**
* @return {LH.Gatherer.Simulation.MetricCoefficients}
*/
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/computed/metrics/max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MaxPotentialFID extends MetricArtifact {
* @param {LH.Artifacts.MetricComputationData} data
* @return {Promise<LH.Artifacts.Metric>}
*/
computeObservedMetric(data) {
static computeObservedMetric(data) {
const {firstContentfulPaint} = data.traceOfTab.timings;
if (!firstContentfulPaint) {
throw new LHError(LHError.errors.NO_FCP);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Metrics: Max Potential FID should compute a simulated value 1`] = `
Object {
"optimistic": 396,
"pessimistic": 396,
"timing": 396,
}
`;
36 changes: 36 additions & 0 deletions lighthouse-core/test/computed/metrics/max-potential-fid-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
'use strict';

const assert = require('assert');

const MaxPotentialFID = require('../../../computed/metrics/max-potential-fid.js');
const trace = require('../../fixtures/traces/progressive-app-m60.json');
const devtoolsLog = require('../../fixtures/traces/progressive-app-m60.devtools.log.json');

/* eslint-env jest */

describe('Metrics: Max Potential FID', () => {
it('should compute a simulated value', async () => {
const settings = {throttlingMethod: 'simulate'};
const context = {settings, computedCache: new Map()};
const result = await MaxPotentialFID.request({trace, devtoolsLog, settings}, context);

expect({
timing: Math.round(result.timing),
optimistic: Math.round(result.optimisticEstimate.timeInMs),
pessimistic: Math.round(result.pessimisticEstimate.timeInMs),
}).toMatchSnapshot();
});

it('should compute an observed value', async () => {
const settings = {throttlingMethod: 'provided'};
const context = {settings, computedCache: new Map()};
const result = await MaxPotentialFID.request({trace, devtoolsLog, settings}, context);

assert.equal(Math.round(result.timing), 198);
});
});

0 comments on commit 4386d40

Please sign in to comment.