From b40aae54b734058327645e2d366a364a5d529f6f Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Mon, 15 May 2017 15:36:48 +0300 Subject: [PATCH] fix(aio): fix PWA testing in cases where `atob`/`btoa` is necessary In some cases (unclear when), traceviewer-js, used by Lighthouse under the hood, assumes `atob`/`btoa` are defined in the global scope. This is true for browser environments, but not on node. As a result, some aggregations that required access to model-tracing failed to produce results, dropping the overall PWA score. This affected #16665 (e.g. commit 0de6eec7a). --- aio/scripts/test-pwa-score.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index 756665e6f4..d4d4005774 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -20,6 +20,10 @@ const config = require('lighthouse/lighthouse-core/config/default.json'); // Constants const FLAGS = {output: 'json'}; +// Work-around traceviewer-js bug. +global.atob = str => new Buffer(str, 'base64').toString('binary'); +global.btoa = str => new Buffer(str, 'binary').toString('base64'); + // Specify the path to Chrome on Travis if (process.env.TRAVIS) { process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN;