Skip to content

Commit

Permalink
core: replace WebInspector traceparser with native JSON.parse (#6099)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Sep 24, 2018
1 parent 265d956 commit 14d6450
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 208 deletions.
23 changes: 6 additions & 17 deletions lighthouse-core/lib/asset-saver.js
Expand Up @@ -12,7 +12,6 @@ const stream = require('stream');
const Simulator = require('./dependency-graph/simulator/simulator');
const lanternTraceSaver = require('./lantern-trace-saver');
const Metrics = require('./traces/pwmetrics-events');
const TraceParser = require('./traces/trace-parser');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');

Expand Down Expand Up @@ -94,30 +93,20 @@ async function loadArtifacts(basePath) {

// load devtoolsLogs
artifacts.devtoolsLogs = {};
filenames.filter(f => f.endsWith(devtoolsLogSuffix)).map(filename => {
filenames.filter(f => f.endsWith(devtoolsLogSuffix)).forEach(filename => {
const passName = filename.replace(devtoolsLogSuffix, '');
const devtoolsLog = JSON.parse(fs.readFileSync(path.join(basePath, filename), 'utf8'));
artifacts.devtoolsLogs[passName] = devtoolsLog;
});

// load traces
artifacts.traces = {};
const promises = filenames.filter(f => f.endsWith(traceSuffix)).map(filename => {
return new Promise(resolve => {
const passName = filename.replace(traceSuffix, '');
const readStream = fs.createReadStream(path.join(basePath, filename), {
encoding: 'utf-8',
highWaterMark: 4 * 1024 * 1024, // TODO benchmark to find the best buffer size here
});
const parser = new TraceParser();
readStream.on('data', chunk => parser.parseChunk(chunk));
readStream.on('end', _ => {
artifacts.traces[passName] = parser.getTrace();
resolve();
});
});
filenames.filter(f => f.endsWith(traceSuffix)).forEach(filename => {
const file = fs.readFileSync(path.join(basePath, filename), {encoding: 'utf-8'});
const trace = JSON.parse(file);
const passName = filename.replace(traceSuffix, '');
artifacts.traces[passName] = Array.isArray(trace) ? {traceEvents: trace} : trace;
});
await Promise.all(promises);

return artifacts;
}
Expand Down
74 changes: 0 additions & 74 deletions lighthouse-core/lib/traces/trace-parser.js

This file was deleted.

21 changes: 0 additions & 21 deletions lighthouse-core/lib/web-inspector.js
Expand Up @@ -21,10 +21,6 @@ module.exports = (function() {
global.self = global;
}

if (typeof global.window === 'undefined') {
global.window = global;
}

global.Node = {
ELEMENT_NODE: 1,
TEXT_NODE: 3,
Expand All @@ -45,28 +41,11 @@ module.exports = (function() {
// See https://github.com/GoogleChrome/lighthouse/issues/73
const _setImmediate = global.setImmediate;

global.Protocol = {
Agents() {},
};

global.WebInspector = {};
const WebInspector = global.WebInspector;

// Shared Dependencies
require('chrome-devtools-frontend/front_end/common/Object.js');
require('chrome-devtools-frontend/front_end/common/UIString.js');
require('chrome-devtools-frontend/front_end/platform/utilities.js');
require('chrome-devtools-frontend/front_end/sdk/Target.js');
require('chrome-devtools-frontend/front_end/sdk/TargetManager.js');

// Dependencies for timeline-model
WebInspector.console = {
error() {},
};

// used for streaming json parsing
require('chrome-devtools-frontend/front_end/common/TextUtils.js');
require('chrome-devtools-frontend/front_end/timeline/TimelineLoader.js');

// Dependencies for effective CSS rule calculation.
require('chrome-devtools-frontend/front_end/common/TextRange.js');
Expand Down
11 changes: 11 additions & 0 deletions lighthouse-core/test/lib/asset-saver-test.js
Expand Up @@ -170,4 +170,15 @@ describe('asset-saver helper', () => {
});
}, 40 * 1000);
});

describe('loadArtifacts', () => {
it('loads artifacts from disk', async () => {
const artifactsPath = __dirname + '/../fixtures/artifacts/perflog/';
const artifacts = await assetSaver.loadArtifacts(artifactsPath);
assert.strictEqual(artifacts.LighthouseRunWarnings.length, 2);
assert.strictEqual(artifacts.URL.requestedUrl, 'https://www.reddit.com/r/nba');
assert.strictEqual(artifacts.devtoolsLogs.defaultPass.length, 555);
assert.strictEqual(artifacts.traces.defaultPass.traceEvents.length, 12);
});
});
});
93 changes: 0 additions & 93 deletions lighthouse-core/test/lib/traces/trace-parser-test.js

This file was deleted.

4 changes: 2 additions & 2 deletions lighthouse-extension/app/src/lighthouse-ext-background.js
Expand Up @@ -231,8 +231,8 @@ function isRunning() {
return lighthouseIsRunning;
}

// Run when in extension context, but not in devtools.
if ('chrome' in window && chrome.runtime) {
// Run when in extension context, but not in devtools or unit tests.
if (typeof window !== 'undefined' && 'chrome' in window && chrome.runtime) {
chrome.runtime.onInstalled.addListener(details => {
if (details.previousVersion) {
// eslint-disable-next-line no-console
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
"chrome-debug": "./lighthouse-core/scripts/manual-chrome-launcher.js"
},
"engines": {
"node": ">=8.9"
"node": ">=8.10"
},
"scripts": {
"install-all": "npm-run-posix-or-windows install-all:task",
Expand Down

0 comments on commit 14d6450

Please sign in to comment.