Skip to content

Commit

Permalink
restore comment
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Jul 24, 2024
1 parent 7153855 commit 06a6344
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tests/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,25 @@ ${metricsToLogString}
customMetrics.forEach(metricName => {
let wptCustomMetric = firstViewData[`_${metricName}`];
try {
// Some, but not all, custom metrics wrap their return values in JSON.stringify()
// Some just return the objects. And some have strings which are not JSON!
// Gotta love the consistency!!!
//
// IMHO wrapping the return in JSON.stringify() is best practice, since WebPageTest
// will do that to save to database and you can run into weird edge cases where it
// doesn't return data when doing that, so explicitly doing that avoids that when
// testing in the console* , but we live in an inconsistent world!
// (* see https://github.com/HTTPArchive/custom-metrics/pull/113#issuecomment-2043937823)
//
// Anyway, if it's a string, see if we can parse it back to a JS object to pretty
// print it, but be prepared for that to fail for non-JSON strings so wrap in try/catch
// See pipeline: https://github.com/HTTPArchive/data-pipeline/blob/main/modules/import_all.py#L115
if (typeof wptCustomMetric === 'string') {
wptCustomMetric = JSON.parse(wptCustomMetric);
}
} catch (e) { }
} catch (e) {
// If it fails, that's OK as we'll just stick with the exact string output anyway
}
wptCustomMetrics[`_${metricName}`] = wptCustomMetric;
});

Expand Down

0 comments on commit 06a6344

Please sign in to comment.