Skip to content

Commit

Permalink
some tweaks/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
okor committed Jun 26, 2017
1 parent 837ee78 commit 3ab4e9b
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ phantomjsdriver.log
config-test.json
config-block.json
config.json
TODO.txt
TODO.txt
tmp/*
report.txt
browsertime-results/*
2 changes: 1 addition & 1 deletion config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
}

]
}
}
2 changes: 1 addition & 1 deletion lib/reporters/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ module.exports = function(config, stat, verbose) {
}


}
}
6 changes: 4 additions & 2 deletions lib/util/calcStats.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var _ = require('underscore-node');
var fs = require('fs');

module.exports = function(config, stat, url) {

var result = require(stat.har) // TODO: use in memory thing instead
var file = './tmp/' + stat.har + '.har';
var result = JSON.parse(fs.readFileSync(file, 'utf8'));
var cats = ['fonts', 'css', 'js', 'images'];

_.each(result.log.entries, function(entry, index) {
Expand All @@ -27,4 +29,4 @@ module.exports = function(config, stat, url) {
});

return stat;
}
}
16 changes: 11 additions & 5 deletions lib/util/scaffoldStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ module.exports = function(config, startTime, dirname) {
_.each(site.tests, function(test) {

var url = site.protocolPrefix + site.base + test.path;
stats[test.name] = {

var parts = site.base.replace(/^(https?:\/\/)?(www\.)/,'').split('.');
parts.pop();
var newname = parts.join('-');

stats[newname + '-' + test.name] = {
key: newname + '-' + test.name,
url: url,
base: site.base,
name: test.name,
har: dirname + "/tmp/" + startTime + "-" + test.name + ".json",
timings: dirname + "/tmp/" + startTime + "-" + test.name + "-timings.json",
har: startTime + "-" + test.name + "",
timings: startTime + "-" + test.name + "-timings",
html: { count: 0, totalSize: 0, budgetDiff: 0, entries: [] },
fonts: { count: 0, totalSize: 0, budgetDiff: 0, entries: [] },
css: { count: 0, totalSize: 0, budgetDiff: 0, entries: [] },
js: { count: 0, totalSize: 0, budgetDiff: 0, entries: [] },
images: { count: 0, totalSize: 0, budgetDiff: 0, entries: [] },
matchers: _.defaults(defaultMatchers, (site.matchers||{})),
matchers: _.defaults((site.matchers||{}), defaultMatchers),
browserSize: test.browserSize||defaultBrowserSize
}

Expand All @@ -44,4 +50,4 @@ module.exports = function(config, startTime, dirname) {
});

return stats;
}
}
26 changes: 13 additions & 13 deletions lightbike.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var config = require(path.resolve(configPath));
var startTime = Date.now();
var stats = scaffoldStats(config, startTime, __dirname);


// should be part of options hash
var minWaitTime = 4000; // ms
var WAITSCRIPT = 'return (function(){ if (typeof(LIGHTSTART) === "undefined") window.LIGHTSTART = (new Date).getTime(); if (((new Date).getTime() - LIGHTSTART) > ' + minWaitTime + ') return true; })()';
Expand All @@ -48,28 +47,29 @@ var logDir = path.resolve(__dirname + '/tmp');

// the magic
_.each(stats, function(stat) {
console.log('Testing ' + stat.name);
console.log('Testing ' + stat.base + ' ' + stat.name);

var cmd = [
"browsertime -u " + stat.url + " -n 1 -w " + stat.browserSize,
" --filename " + stats[stat.name].timings,
" --harFile " + stats[stat.name].har,
" --waitScript '" + WAITSCRIPT + "'",
" --logDir " + logDir
"browsertime " + stat.url + " -n 1 -viewPort " + stat.browserSize,
" --resultDir " + logDir,
" --logDir " + logDir,
" --output " + stats[stat.key].timings,
" --har " + stats[stat.key].har,
" --waitScript '" + WAITSCRIPT + "'"
].join('');

if (stat.headers) cmd += " --headers " + "'" + stat.headers + "'";
if (stat.block) cmd += " --blacklist " + "'" + stat.block + "'";

if (verbose) {
console.log();
console.log(cmd);
console.log();
}
// if (verbose) {
// console.log();
// console.log(cmd);
// console.log();
// }

execSync(cmd, 120000);

calcStats(config, stat, stat.url);
logStats(config, stat, verbose);
console.log('');
})
})
102 changes: 102 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ab4e9b

Please sign in to comment.