mirror of
https://github.com/DeNNiiInc/Web-Page-Performance-Test.git
synced 2026-04-17 20:05:58 +00:00
Fix runner.js - even safer property access
This commit is contained in:
@@ -154,13 +154,13 @@ async function _executeTest(url, options) {
|
|||||||
|
|
||||||
|
|
||||||
// Safe property access
|
// Safe property access
|
||||||
const getScore = (cat) => (lhr.categories[cat] && lhr.categories[cat].score) ? lhr.categories[cat].score * 100 : 0;
|
const getScore = (cat) => (lhr.categories && lhr.categories[cat] && lhr.categories[cat].score) ? lhr.categories[cat].score * 100 : 0;
|
||||||
const getMetric = (aud) => (lhr.audits[aud] && lhr.audits[aud].numericValue) ? lhr.audits[aud].numericValue : 0;
|
const getMetric = (aud) => (lhr.audits && lhr.audits[aud] && lhr.audits[aud].numericValue) ? lhr.audits[aud].numericValue : 0;
|
||||||
|
|
||||||
const summary = {
|
const summary = {
|
||||||
id: testId,
|
id: testId,
|
||||||
url: lhr.finalUrl,
|
url: lhr.finalUrl || url,
|
||||||
timestamp: lhr.fetchTime,
|
timestamp: lhr.fetchTime || new Date().toISOString(),
|
||||||
scores: {
|
scores: {
|
||||||
performance: getScore('performance'),
|
performance: getScore('performance'),
|
||||||
accessibility: getScore('accessibility'),
|
accessibility: getScore('accessibility'),
|
||||||
@@ -225,8 +225,8 @@ async function _executeTest(url, options) {
|
|||||||
|
|
||||||
const summary = {
|
const summary = {
|
||||||
id: testId,
|
id: testId,
|
||||||
url: lhr.finalUrl,
|
url: lhr.finalUrl || url,
|
||||||
timestamp: lhr.fetchTime,
|
timestamp: lhr.fetchTime || new Date().toISOString(),
|
||||||
scores: {
|
scores: {
|
||||||
performance: getScore('performance'),
|
performance: getScore('performance'),
|
||||||
accessibility: getScore('accessibility'),
|
accessibility: getScore('accessibility'),
|
||||||
|
|||||||
Reference in New Issue
Block a user