Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add basic lighthouse functionality #825

Merged
merged 2 commits into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions agent/js/src/agent_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ Agent.prototype.scheduleProcessDone_ = function(ipcMsg, job) {
fs.unlinkSync(ipcMsg.traceFile);
} catch(e) {}
}
if (ipcMsg.lighthouseFile) {
try {
var buffer = fs.readFileSync(ipcMsg.lighthouseFile);
if (buffer) {
job.resultFiles.push(new wpt_client.ResultFile(
wpt_client.ResultFile.ResultType.GZIP,
'lighthouse.html.gz', 'application/x-gzip', buffer));
}
fs.unlinkSync(ipcMsg.lighthouseFile);
} catch(e) {}
}
if (ipcMsg.userTimingFile) {
try {
var buffer = fs.readFileSync(ipcMsg.userTimingFile);
Expand Down
30 changes: 26 additions & 4 deletions agent/js/src/wd_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,13 +1028,34 @@ WebDriverServer.prototype.onTracingMessage_ = function(message) {
};

/**
* Runs lighthouse with the options specified by the task and dumps data into
* Runs lighthouse with the options specified by the task and dumps data into
* a directory.
* @private
*/
WebDriverServer.prototype.runLighthouse_ = function() {
// TODO(phulce): actually run lighthouse
this.onPageLoad_(new Error('Lighthouse not yet implemented!'));
this.lighthouseFile_ = path.join(this.runTempDir_, 'lighthouse.html');
this.app_.timeout(1000, 'Waiting for Chrome to be available...');
process_utils.scheduleExec(this.app_,
'lighthouse',
[
'--disable-device-emulation',
'--disable-network-throttling',
'--save-assets',
'--port', this.browser_.devToolsPort_,
'--output', 'html',
'--output-path', this.lighthouseFile_,
this.task_.url,
], undefined, this.timeout_).then(function () {
var devtoolsLogFile = path.join(this.runTempDir_, 'lighthouse-0.devtoolslog.json');
this.devToolsMessages_ = JSON.parse(fs.readFileSync(devtoolsLogFile, 'utf8'));

this.traceFile_ = path.join(this.runTempDir_, 'lighthouse-0.trace.json');
var contents = JSON.parse(fs.readFileSync(this.traceFile_, 'utf8'));
fs.writeFileSync(this.traceFile_, JSON.stringify(contents));
this.onPageLoad_();
}.bind(this), function (err) {
this.onPageLoad_(err);
}.bind(this));
};

/**
Expand Down Expand Up @@ -1590,7 +1611,7 @@ WebDriverServer.prototype.done_ = function() {

this.scheduleNoFault_('Capture Screen Shot', function() {
if (!this.task_.lighthouse)
this.takeScreenshot_('screen', 'end of run');
return this.takeScreenshot_('screen', 'end of run');
}.bind(this));
if (this.videoFile_) {
this.scheduleNoFault_('Stop video recording',
Expand Down Expand Up @@ -1668,6 +1689,7 @@ WebDriverServer.prototype.done_ = function() {
devToolsFile: devToolsFile,
screenshots: this.screenshots_,
traceFile: this.traceFile_,
lighthouseFile: this.lighthouseFile_,
userTimingFile: this.userTimingFile_,
cpuSlicesFile: this.cpuSlicesFile_,
scriptTimingFile: this.scriptTimingFile_,
Expand Down
25 changes: 25 additions & 0 deletions www/lighthouse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
if(array_key_exists("HTTP_IF_MODIFIED_SINCE",$_SERVER) && strlen(trim($_SERVER['HTTP_IF_MODIFIED_SINCE']))) {
header("HTTP/1.0 304 Not Modified");
} else {
include 'common.inc';
$ok = false;
if (isset($testPath) && is_dir($testPath)) {
$file = "${run}_lighthouse.html.gz";
$filePath = "$testPath/$file";
if (is_file($filePath)) {
$ok = true;

// Cache for a year
header('Last-Modified: ' . gmdate('r'));
header('Cache-Control: public,max-age=31536000');
header('Content-type: text/html');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
}
}
if (!$ok) {
header("HTTP/1.0 404 Not Found");
}
}
?>
9 changes: 7 additions & 2 deletions www/result.inc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ $page_description = "Website performance test result$testLabel.";
?>
</div>
<?php
$fvMedian = $testResults->getMedianRunNumber($median_metric, false);
$rvMedian = $testResults->getMedianRunNumber($median_metric, true);

// create a friendlier (unique) name for the fi
$fileUrl = GetFileUrl($url);
if ( $test['testinfo']['lighthouse'] && $fvMedian )
{
echo "<a href=\"/lighthouse.php?test=$id&run=$fvMedian\">Lighthouse report</a><br>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for now but I'd really like to give it much more prominent treatment. The grades section in the header is a perfect place since the grades won't be calculated in the lighthouse case. If the score can be pulled out of the HTML then the UI can have a large:

Lighthouse Score: 85/100 (click for full report)

And maybe also the logo ;-)

}
if( FRIENDLY_URLS )
{
echo "<a href=\"/result/$id/{$id}_{$fileUrl}_page_data.csv\">Raw page data</a> - ";
Expand All @@ -151,8 +158,6 @@ $page_description = "Website performance test result$testLabel.";
<div class="cleared"></div>
<div id="average">
<?php
$fvMedian = $testResults->getMedianRunNumber($median_metric, false);
$rvMedian = $testResults->getMedianRunNumber($median_metric, true);
$is_test_error = $testInfo->isTestError();
if ($fvMedian)
{
Expand Down