Skip to content

Commit ffde8e7

Browse files
authored
Show the test progress (#517)
Extension now reveals the progress, as does CLI
1 parent 5d97d38 commit ffde8e7

File tree

8 files changed

+82
-13
lines changed

8 files changed

+82
-13
lines changed

lighthouse-core/driver/index.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
'use strict';
1818

19+
const log = require('../lib/log.js');
20+
1921
class Driver {
2022

2123
static loadPage(driver, options) {
@@ -32,6 +34,7 @@ class Driver {
3234
}
3335

3436
static setupDriver(driver, gatherers, options) {
37+
log.log('status', 'Initializing…');
3538
return new Promise((resolve, reject) => {
3639
// Enable emulation.
3740
if (options.flags.mobile) {
@@ -82,10 +85,17 @@ class Driver {
8285
const driver = options.driver;
8386
const config = options.config;
8487
const gatherers = config.gatherers;
88+
const gatherernames = gatherers.map(g => g.name).join(', ');
8589
let pass = Promise.resolve();
8690

8791
if (config.loadPage) {
88-
pass = pass.then(_ => this.loadPage(driver, options));
92+
pass = pass.then(_ => {
93+
const status = 'Loading page & waiting for onload';
94+
log.log('status', status, gatherernames);
95+
return this.loadPage(driver, options).then(_ => {
96+
log.log('statusEnd', status);
97+
});
98+
});
8999
}
90100

91101
return gatherers.reduce((chain, gatherer) => {
@@ -101,20 +111,36 @@ class Driver {
101111
let pass = Promise.resolve();
102112

103113
if (config.trace) {
104-
pass = pass.then(_ => driver.endTrace().then(traceContents => {
105-
loadData.traceContents = traceContents;
106-
}));
114+
pass = pass.then(_ => {
115+
log.log('status', 'Gathering: trace');
116+
driver.endTrace().then(traceContents => {
117+
loadData.traceContents = traceContents;
118+
log.log('statusEnd', 'Gathering: trace');
119+
});
120+
});
107121
}
108122

109123
if (config.network) {
110-
pass = pass.then(_ => driver.endNetworkCollect().then(networkRecords => {
111-
loadData.networkRecords = networkRecords;
112-
}));
124+
pass = pass.then(_ => {
125+
const status = 'Gathering: network records';
126+
log.log('status', status);
127+
return driver.endNetworkCollect().then(networkRecords => {
128+
loadData.networkRecords = networkRecords;
129+
log.log('statusEnd', status);
130+
});
131+
});
113132
}
114133

115134
return gatherers
116135
.reduce((chain, gatherer) => {
117-
return chain.then(_ => gatherer.afterPass(options, loadData));
136+
return chain.then(_ => {
137+
const status = `Gathering: ${gatherer.name}`;
138+
log.log('status', status);
139+
return Promise.resolve(gatherer.afterPass(options, loadData)).then(ret => {
140+
log.log('statusEnd', status);
141+
return ret;
142+
});
143+
});
118144
}, pass)
119145
.then(_ => loadData);
120146
}
@@ -171,7 +197,13 @@ class Driver {
171197
})
172198

173199
// Reload the page to remove any side-effects of Lighthouse (like disabling JavaScript).
174-
.then(_ => this.loadPage(driver, options))
200+
.then(_ => {
201+
const status = 'Reloading page to reset state';
202+
log.log('status', status);
203+
return this.loadPage(driver, options).then(_ => {
204+
log.log('statusEnd', status);
205+
});
206+
})
175207

176208
// Finish and teardown.
177209
.then(_ => driver.disconnect())

lighthouse-core/lib/log.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'use strict';
1818

1919
const debug = require('debug');
20+
const EventEmitter = require('events').EventEmitter;
2021

2122
function setLevel(level) {
2223
if (level === 'verbose') {
@@ -37,17 +38,31 @@ function _log(title, logargs) {
3738
return loggers[title](...args);
3839
}
3940

41+
class Emitter extends EventEmitter { }
42+
const events = new Emitter();
43+
4044
module.exports = {
4145
setLevel,
42-
log(title) {
46+
events,
47+
log(title, msg) {
48+
if (title === 'status') {
49+
console.time(msg);
50+
events.emit('status', arguments);
51+
}
52+
if (title === 'statusEnd') {
53+
console.timeEnd(msg);
54+
}
4355
return _log(title, arguments);
4456
},
57+
4558
warn(title) {
4659
return _log(`${title}:warn`, arguments);
4760
},
61+
4862
error(title) {
4963
return _log(`${title}:error`, arguments);
5064
},
65+
5166
verbose(title) {
5267
return _log(`${title}:verbose`, arguments);
5368
}

lighthouse-core/runner.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const Driver = require('./driver');
2020
const Aggregator = require('./aggregator');
2121
const assetSaver = require('./lib/asset-saver');
22+
const log = require('./lib/log');
2223
const fs = require('fs');
2324
const path = require('path');
2425

@@ -64,7 +65,12 @@ class Runner {
6465

6566
// Now run the audits.
6667
run = run.then(artifacts => Promise.all(config.audits.map(audit => {
67-
return audit.audit(artifacts);
68+
const status = `Evaluating: ${audit.meta.description}`;
69+
log.log('status', status);
70+
return Promise.resolve(audit.audit(artifacts)).then(ret => {
71+
log.log('statusEnd', status);
72+
return ret;
73+
});
6874
})));
6975
} else if (config.auditResults) {
7076
// If there are existing audit results, surface those here.

lighthouse-extension/app/popup.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ <h2 class="header-titles__url">...</h2>
4343

4444
<aside class="status">
4545
<div class="status__spinner"></div>
46-
<div class="status__msg">Auditing page...</div>
46+
<div class="status__msg">Starting...</div>
47+
<div><small class="status__detailsmsg"></small></div>
4748
</aside>
4849

4950
<script src="scripts/popup.js"></script>

lighthouse-extension/app/src/lighthouse-background.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ window.runAudits = function(options) {
5353
});
5454
};
5555

56+
window.listenForStatus = function(callback) {
57+
log.events.addListener('status', callback);
58+
};
59+
5660
chrome.runtime.onInstalled.addListener(details => {
5761
if (details.previousVersion) {
5862
console.log('previousVersion', details.previousVersion);

lighthouse-extension/app/src/popup.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ document.addEventListener('DOMContentLoaded', _ => {
2121
const generateReportEl = document.body.querySelector('.generate-report');
2222

2323
const statusEl = document.body.querySelector('.status');
24+
const statusMessageEl = document.body.querySelector('.status__msg');
25+
const statusDetailsMessageEl = document.body.querySelector('.status__detailsmsg');
2426
const spinnerEl = document.body.querySelector('.status__spinner');
2527
const feedbackEl = document.body.querySelector('.feedback');
2628
let spinnerAnimation;
@@ -41,6 +43,13 @@ document.addEventListener('DOMContentLoaded', _ => {
4143
statusEl.classList.remove('status--visible');
4244
};
4345

46+
const logstatus = ([, message, details]) => {
47+
statusMessageEl.textContent = message;
48+
statusDetailsMessageEl.textContent = details;
49+
};
50+
51+
background.listenForStatus(logstatus);
52+
4453
generateReportEl.addEventListener('click', () => {
4554
startSpinner();
4655
feedbackEl.textContent = '';
@@ -61,6 +70,7 @@ document.addEventListener('DOMContentLoaded', _ => {
6170
}
6271
feedbackEl.textContent = message;
6372
stopSpinner();
73+
background.console.error(err);
6474
});
6575
});
6676

lighthouse-extension/app/styles/lighthouse.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ body {
141141
opacity: 0;
142142
will-change: opacity;
143143
transition: opacity 0.150s cubic-bezier(0,0,0.41,1);
144+
text-align: center;
144145
}
145146

146147
.status--visible {

lighthouse-extension/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ gulp.task('watch', ['lint', 'browserify', 'html', 'copyReportScripts'], () => {
154154
gulp.watch([
155155
'*.js',
156156
'app/src/**/*.js',
157-
'node_modules/lighthouse-core/**/*.js'
157+
'../lighthouse-core/**/*.js'
158158
], ['browserify', 'lint']);
159159
});
160160

0 commit comments

Comments
 (0)