Skip to content

Commit

Permalink
fixed some coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
weiwei-lin committed Jan 16, 2017
1 parent addb3b0 commit 3127aab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
43 changes: 31 additions & 12 deletions lighthouse-cli/performance-experiment/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ function requestHandler(request, response) {
function reportRequestHandler(request, response) {
try {
const id = request.parsedUrl.query.id || 0;
const [params, results] = database.getData(id);
const results = database.getResults(id);

results.relatedReports = database.timeStamps.map((generatedTime, index) => {
return {reportUrl:`/?id=${index}`, url: database.url, generatedTime};
return {reportUrl: `/?id=${index}`, url: database.url, generatedTime};
});

const reportGenerator = new ReportGenerator();
Expand All @@ -103,7 +103,7 @@ function reportRequestHandler(request, response) {

function rerunRequestHandler(request, response) {
try {
const [flags, results] = database.getData(request.parsedUrl.query.id || 0);
const flags = database.getFlags(request.parsedUrl.query.id || 0).flags;
let message = '';
request.on('data', data => message += data);

Expand All @@ -119,11 +119,19 @@ function rerunRequestHandler(request, response) {
});
});
} catch (err) {
response.writeHead(404);
response.end('404: Resource Not Found');
if (err.code === 'MODULE_NOT_FOUND') {
response.writeHead(404);
response.end('404: Resource Not Found');
} else {
throw err;
}
}
}

/**
* Store all the experiment data (flags and results) on hard disk.
* Call this.clear() to delete all the temp files.
*/
class ExperimentDatabase {
constructor(url, config) {
this._url = url;
Expand All @@ -133,9 +141,17 @@ class ExperimentDatabase {
this._timeStamps = [];
}

get url() {return this._url;}
get config() {return this._config;}
get timeStamps() {return this._timeStamps;}
get url() {
return this._url;
}

get config() {
return this._config;
}

get timeStamps() {
return this._timeStamps;
}

saveData(lhFlags, lhResults) {
const id = this._timeStamps.length;
Expand All @@ -145,13 +161,16 @@ class ExperimentDatabase {
return id;
}

getData(id) {
const flags = require(`${this._root}/flags-${id}.json`);
const results = require(`${this._root}/results-${id}.json`);
return [flags, results];
getFlags(id) {
return require(`${this._root}/flags-${id}.json`);
}

getResults(id) {
return require(`${this._root}/results-${id}.json`);
}

clear() {
this._timeStamps = [];
fs.readdirSync(this._root).forEach(filename => fs.unlinkSync(`${this._root}/${filename}`));
fs.rmdirSync(this._root);
}
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/report/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class ReportGenerator {
// value < value2?
Handlebars.registerHelper('if_less_than', function(lhs, rhs, opts) {
if (lhs < rhs) {
// eslint-disable-next-line no-invalid-this
return opts.fn(this);
} else {
// eslint-disable-next-line no-invalid-this
return opts.inverse(this);
}
});
Expand Down Expand Up @@ -153,7 +155,6 @@ class ReportGenerator {
return new Handlebars.SafeString(str);
});


// format time
Handlebars.registerHelper('format_time', function(date) {
const options = {
Expand Down

0 comments on commit 3127aab

Please sign in to comment.