diff --git a/.gitignore b/.gitignore index 7a59f1b..44a7efb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ phantomjsdriver.log config-test.json config-block.json config.json -TODO.txt \ No newline at end of file +TODO.txt +tmp/* +report.txt +browsertime-results/* diff --git a/config-example.json b/config-example.json index 36c3bff..d00a65b 100644 --- a/config-example.json +++ b/config-example.json @@ -31,4 +31,4 @@ } ] -} \ No newline at end of file +} diff --git a/lib/reporters/console.js b/lib/reporters/console.js index d8b2f98..125f2f2 100644 --- a/lib/reporters/console.js +++ b/lib/reporters/console.js @@ -52,4 +52,4 @@ module.exports = function(config, stat, verbose) { } -} \ No newline at end of file +} diff --git a/lib/util/calcStats.js b/lib/util/calcStats.js index cb23c1a..3baca80 100644 --- a/lib/util/calcStats.js +++ b/lib/util/calcStats.js @@ -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) { @@ -27,4 +29,4 @@ module.exports = function(config, stat, url) { }); return stat; -} \ No newline at end of file +} diff --git a/lib/util/scaffoldStats.js b/lib/util/scaffoldStats.js index f5e3e13..90953cf 100644 --- a/lib/util/scaffoldStats.js +++ b/lib/util/scaffoldStats.js @@ -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 } @@ -44,4 +50,4 @@ module.exports = function(config, startTime, dirname) { }); return stats; -} \ No newline at end of file +} diff --git a/lightbike.js b/lightbike.js index 0e06ada..479f0e7 100755 --- a/lightbike.js +++ b/lightbike.js @@ -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; })()'; @@ -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(''); -}) \ No newline at end of file +}) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..df14696 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,102 @@ +{ + "name": "lightbike", + "version": "1.0.0", + "lockfileVersion": 1, + "dependencies": { + "ascii-table": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/ascii-table/-/ascii-table-0.0.8.tgz", + "integrity": "sha1-Q2LhTSMfxwwMj5dJ8w30qn9e2KY=" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "fs-extra": { + "version": "0.26.7", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.26.7.tgz", + "integrity": "sha1-muH92UiXeY7at20JGM9C0MMYT6k=" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==" + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=" + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "jsonfile": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=" + }, + "klaw": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", + "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=" + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "rimraf": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz", + "integrity": "sha1-wjOOxkPfeht/5cVPqG9XQopV8z0=" + }, + "sync-exec": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/sync-exec/-/sync-exec-0.6.2.tgz", + "integrity": "sha1-cX0izFPwzh3vVZQ2LzqJouu5EQU=" + }, + "underscore-node": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/underscore-node/-/underscore-node-0.1.2.tgz", + "integrity": "sha1-DOjHpXN8ptyOcTFdxNokaUnUgng=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } +}