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

core: replace remaining rawValue with numericValue #8421

Merged
merged 2 commits into from
Apr 25, 2019
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 docs/recipes/custom-audit/searchable-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LoadAudit extends Audit {
const belowThreshold = loadMetrics.searchableTime <= MAX_SEARCHABLE_TIME;

return {
rawValue: loadMetrics.searchableTime,
numericValue: loadMetrics.searchableTime,
// Cast true/false to 1/0
score: Number(belowThreshold),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PreloadAsAudit extends Audit {
const passed = noAsLinks.length === 0;

return {
rawValue: passed,
score: passed ? 1 : 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+passed? idk how hacky you'll allow js to be :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did something like Number(passed) for real audits, but since this is a recipe I thought I'd be more explicit. Not sure if this is actually more self explanatory, though :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the explicitness of this for the recipe :)

displayValue: `Found ${noAsLinks.length} preload requests with missing \`as\` attributes`,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class Audit {

score,
scoreDisplayMode,
numericValue: product.rawValue,
numericValue: product.numericValue,

displayValue: product.displayValue,
explanation: product.explanation,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/bootup-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class BootupTime extends Audit {

return {
score,
rawValue: totalBootupTime,
numericValue: totalBootupTime,
displayValue: totalBootupTime > 0 ?
str_(i18n.UIStrings.seconds, {timeInMs: totalBootupTime}) : '',
details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class UnusedBytes extends Audit {
explanation: result.explanation,
warnings: result.warnings,
displayValue,
rawValue: wastedMs,
numericValue: wastedMs,
score: UnusedBytes.scoreForWastedMs(wastedMs),
extendedInfo: {
value: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class RenderBlockingResources extends Audit {
return {
displayValue,
score: ByteEfficiencyAudit.scoreForWastedMs(wastedMs),
rawValue: wastedMs,
numericValue: wastedMs,
details,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class TotalByteWeight extends ByteEfficiencyAudit {

return {
score,
rawValue: totalBytes,
numericValue: totalBytes,
displayValue: str_(UIStrings.displayValue, {totalBytes}),
extendedInfo: {
value: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class CacheHeaders extends Audit {

return {
score,
rawValue: totalWastedBytes,
numericValue: totalWastedBytes,
displayValue: str_(UIStrings.displayValue, {itemCount: results.length}),
extendedInfo: {
value: {
Expand Down
1 change: 0 additions & 1 deletion lighthouse-core/audits/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Diagnostics extends Audit {

return {
score: 1,
rawValue: 1,
details: {
type: 'debugdata',
// TODO: Consider not nesting diagnostics under `items`.
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/dom-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class DOMSize extends Audit {

return {
score,
rawValue: stats.totalBodyElements,
numericValue: stats.totalBodyElements,
displayValue: str_(UIStrings.displayValue, {itemCount: stats.totalBodyElements}),
extendedInfo: {
value: items,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/errors-in-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ErrorLogs extends Audit {

return {
score: Number(numErrors === 0),
rawValue: numErrors,
numericValue: numErrors,
details,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/load-fast-enough-for-pwa.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LoadFastEnough4Pwa extends Audit {
score,
displayValue,
explanation,
rawValue: tti.timing,
numericValue: tti.timing,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/main-thread-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MainThreadTasks extends Audit {

return {
score: 1,
rawValue: results.length,
numericValue: results.length,
details: tableDetails,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/mainthread-work-breakdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MainThreadWorkBreakdown extends Audit {

return {
score,
rawValue: totalExecutionTime,
numericValue: totalExecutionTime,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: totalExecutionTime}),
details: tableDetails,
};
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Metrics extends Audit {

return {
score: 1,
rawValue: (interactive && interactive.timing) || 0,
numericValue: (interactive && interactive.timing) || 0,
details,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class EstimatedInputLatency extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class FirstContentfulPaint3G extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: `${metricResult.timing}\xa0ms`,
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-contentful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FirstContentfulPaint extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-cpu-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FirstCPUIdle extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FirstMeaningfulPaint extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class InteractiveMetric extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: timeInMs,
numericValue: timeInMs,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs}),
extendedInfo: {
value: extendedInfo,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/max-potential-fid.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MaxPotentialFID extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: metricResult.timing}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/metrics/speed-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SpeedIndex extends Audit {
context.options.scorePODR,
context.options.scoreMedian
),
rawValue: metricResult.timing,
numericValue: metricResult.timing,
displayValue: str_(i18n.UIStrings.seconds, {timeInMs: metricResult.timing}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/network-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NetworkRequests extends Audit {

return {
score: 1,
rawValue: results.length,
numericValue: results.length,
details: tableDetails,
};
});
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/network-rtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NetworkRTT extends Audit {

return {
score: 1,
rawValue: maxRtt,
numericValue: maxRtt,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: maxRtt}),
details: tableDetails,
};
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/network-server-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class NetworkServerLatency extends Audit {

return {
score: Math.max(1 - (maxLatency / 500), 0),
rawValue: maxLatency,
numericValue: maxLatency,
displayValue: str_(i18n.UIStrings.ms, {timeInMs: maxLatency}),
details: tableDetails,
};
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/predictive-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class PredictivePerf extends Audit {

return {
score,
rawValue: values.roughEstimateOfTTI,
numericValue: values.roughEstimateOfTTI,
displayValue: Util.formatMilliseconds(values.roughEstimateOfTTI),
details: {
type: 'debugdata',
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Redirects extends Audit {
return {
// We award a passing grade if you only have 1 redirect
score: redirectRequests.length <= 2 ? 1 : UnusedBytes.scoreForWastedMs(totalWastedMs),
rawValue: totalWastedMs,
numericValue: totalWastedMs,
displayValue: totalWastedMs ?
str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: totalWastedMs}) :
'',
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/time-to-first-byte.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TTFBMetric extends Audit {
};

return {
rawValue: ttfb,
numericValue: ttfb,
score: Number(passed),
displayValue,
details,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/uses-rel-preconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class UsesRelPreconnectAudit extends Audit {

return {
score: UnusedBytes.scoreForWastedMs(maxWasted),
rawValue: maxWasted,
numericValue: maxWasted,
displayValue: maxWasted ?
str_(i18n.UIStrings.displayValueMsSavings, {wastedMs: maxWasted}) :
'',
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/uses-rel-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class UsesRelPreloadAudit extends Audit {

return {
score: UnusedBytes.scoreForWastedMs(wastedMs),
rawValue: wastedMs,
numericValue: wastedMs,
displayValue: wastedMs ?
str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) :
'',
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/test/audits/bootup-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Performance: bootup-time audit', () => {
assert.deepEqual(roundedValueOf(output, 'https://www.google-analytics.com/analytics.js'), {scripting: 40.6, scriptParseCompile: 9.6, total: 53.4});
assert.deepEqual(roundedValueOf(output, 'Other'), {scripting: 11.7, scriptParseCompile: 0, total: 1123.8}); // eslint-disable-line max-len

assert.equal(Math.round(output.rawValue), 225);
assert.equal(Math.round(output.numericValue), 225);
assert.equal(output.details.items.length, 5);
assert.equal(output.score, 1);
});
Expand All @@ -58,7 +58,7 @@ describe('Performance: bootup-time audit', () => {

assert.equal(output.details.items.length, 8);
assert.equal(output.score, 0.98);
assert.equal(Math.round(output.rawValue), 720);
assert.equal(Math.round(output.numericValue), 720);
});

it('should get no data when no events are present', () => {
Expand All @@ -72,7 +72,7 @@ describe('Performance: bootup-time audit', () => {
.then(output => {
assert.equal(output.details.items.length, 0);
assert.equal(output.score, 1);
assert.equal(Math.round(output.rawValue), 0);
assert.equal(Math.round(output.numericValue), 0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Byte efficiency base audit', () => {
assert.deepEqual(result.details.items, []);
});

it('should set the rawValue', () => {
it('should set the numericValue', () => {
const result = ByteEfficiencyAudit.createAuditProduct(
{
headings: baseHeadings,
Expand All @@ -101,7 +101,7 @@ describe('Byte efficiency base audit', () => {
);

// 900ms savings comes from the graph calculation
assert.equal(result.rawValue, 900);
assert.equal(result.numericValue, 900);
});

it('should score the wastedMs', () => {
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Byte efficiency base audit', () => {
simulator
);

assert.equal(result.rawValue, 300);
assert.equal(result.numericValue, 300);
});

it('should create load simulator with the specified settings', async () => {
Expand All @@ -224,14 +224,14 @@ describe('Byte efficiency base audit', () => {
let settings = {throttlingMethod: 'simulate', throttling: modestThrottling};
let result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect modest savings
expect(result.rawValue).toBeLessThan(5000);
expect(result.rawValue).toMatchSnapshot();
expect(result.numericValue).toBeLessThan(5000);
expect(result.numericValue).toMatchSnapshot();

settings = {throttlingMethod: 'simulate', throttling: ultraSlowThrottling};
result = await MockAudit.audit(artifacts, {settings, computedCache});
// expect lots of savings
expect(result.rawValue).not.toBeLessThan(5000);
expect(result.rawValue).toMatchSnapshot();
expect(result.numericValue).not.toBeLessThan(5000);
expect(result.numericValue).toMatchSnapshot();
});

it('should allow overriding of computeWasteWithTTIGraph', async () => {
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('Byte efficiency base audit', () => {
const result = await MockAudit.audit(artifacts, {settings, computedCache});
const resultTti = await MockJustTTIAudit.audit(artifacts, {settings, computedCache});
// expect less savings with just TTI
expect(resultTti.rawValue).toBeLessThan(result.rawValue);
expect({default: result.rawValue, justTTI: resultTti.rawValue}).toMatchSnapshot();
expect(resultTti.numericValue).toBeLessThan(result.numericValue);
expect({default: result.numericValue, justTTI: resultTti.numericValue}).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Render blocking resources audit', () => {
const computedCache = new Map();
const result = await RenderBlockingResourcesAudit.audit(artifacts, {settings, computedCache});
assert.equal(result.score, 1);
assert.equal(result.rawValue, 0);
assert.equal(result.numericValue, 0);
});

describe('#estimateSavingsWithGraphs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Total byte weight audit', () => {
]);

return TotalByteWeight.audit(artifacts, {options, computedCache: new Map()}).then(result => {
assert.strictEqual(result.rawValue, 150 * 1024);
assert.strictEqual(result.numericValue, 150 * 1024);
assert.strictEqual(result.score, 1);
const results = result.details.items;
assert.strictEqual(results.length, 3);
Expand All @@ -73,7 +73,7 @@ describe('Total byte weight audit', () => {

return TotalByteWeight.audit(artifacts, {options, computedCache: new Map()}).then(result => {
assert.ok(0.40 < result.score && result.score < 0.6, 'score is around 0.5');
assert.strictEqual(result.rawValue, 4180 * 1024);
assert.strictEqual(result.numericValue, 4180 * 1024);
const results = result.details.items;
assert.strictEqual(results.length, 10, 'results are clipped at top 10');
assert.strictEqual(result.extendedInfo.value.totalCompletedRequests, 11);
Expand All @@ -88,7 +88,7 @@ describe('Total byte weight audit', () => {
]);

return TotalByteWeight.audit(artifacts, {options, computedCache: new Map()}).then(result => {
assert.strictEqual(result.rawValue, 15000 * 1024);
assert.strictEqual(result.numericValue, 15000 * 1024);
assert.strictEqual(result.score, 0);
});
});
Expand Down
Loading