From b9127e44ad6cb9f2581a7eb8ed465a500ffa234a Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 23 Jul 2013 05:40:19 +0100 Subject: [PATCH 1/3] make console.log work like normal --- browser/prelude.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/browser/prelude.js b/browser/prelude.js index fd5c626..b398a53 100644 --- a/browser/prelude.js +++ b/browser/prelude.js @@ -68,13 +68,19 @@ var originalLog = console.log; console.log = function (msg) { - var args = arguments; - for (var i = 1; i < args.length; i++) { - msg = msg.replace(/(^|[^%])%[sd]/, function (_, s) { - return s + args[i]; - }); + if('string' === typeof msg) { + var args = arguments; + for (var i = 1; i < args.length; i++) { + msg = msg.replace(/(^|[^%])%[sd]/, function (_, s) { + return s + args[i]; + }); + } + } else { + msg = [].map.call(arguments, function (v) { + return JSON.stringify(v, null, 2) + }) } - + process.stdout.write(msg + '\n'); if (typeof originalLog === 'function') { return originalLog.apply(this, arguments); From 86dba522d80f11e9329d2602fee0feff047fda70 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 23 Jul 2013 05:45:00 +0100 Subject: [PATCH 2/3] use util.inspect instead --- browser/prelude.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/browser/prelude.js b/browser/prelude.js index b398a53..8330fc1 100644 --- a/browser/prelude.js +++ b/browser/prelude.js @@ -2,6 +2,7 @@ var xws = require('xhr-write-stream'); var Stream = require('stream'); var json = typeof JSON === 'object' ? JSON : require('jsonify'); + var util = require('util') process.on = function () {}; var ws = xws('/sock'); @@ -77,8 +78,8 @@ } } else { msg = [].map.call(arguments, function (v) { - return JSON.stringify(v, null, 2) - }) + return util.inspect(v) + }).join(' ') } process.stdout.write(msg + '\n'); From 73d0f68d039f30306a90c6fcdca9e8e5655c7010 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Tue, 23 Jul 2013 06:18:24 +0100 Subject: [PATCH 3/3] accept files to run from command line --- bin/cmd.js | 147 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 65 deletions(-) diff --git a/bin/cmd.js b/bin/cmd.js index 1aca3d9..3c72b96 100755 --- a/bin/cmd.js +++ b/bin/cmd.js @@ -27,74 +27,91 @@ var ecstatic = require('ecstatic')(dir); var resolve = require('resolve').sync; if ((process.stdin.isTTY || argv._.length) && argv._[0] !== '-') { - try { - var pkg = require(path.join(dir, 'package.json')); - } - catch (err) { - if (err.code === 'MODULE_NOT_FOUND') { - console.error( - 'No package.json in ' + dir + ' found.\n' - + 'Consult the quick start guide for how to create one:\n' - + 'https://ci.testling.com/guide/quick_start' - ); - } - else { - console.error(err.message); - } - return; - } - - if (!pkg.testling) { - console.error( - 'The "testling" field isn\'t present ' - + 'in ' + path.join(dir, 'package.json') + '.\n' - + 'This field is required by testling. Please consult:\n' - + 'https://ci.testling.com/guide/quick_start' - ); - return; - } - var bundleId = Math.floor(Math.pow(16,8)*Math.random()).toString(16); - - if (pkg.testling.preprocess) { - // todo - } - else if (!pkg.testling.html) { - unglob(dir, pkg.testling, function (err, expanded) { - if (err) return console.error(err); - process.env.PATH = path.resolve(dir, 'node_modules/.bin') - + ':' + process.env.PATH - ; - scripts = expanded.script; - - if (expanded.file.length) { - var args = expanded.file.concat('--debug'); - var ps = spawn('browserify', args, { cwd: dir }); - ps.stdout.pipe(concat(function (src) { - bundle = src; - htmlQueue.forEach(function (f) { getHTML(f) }); - })); - ps.stderr.pipe(process.stderr); - ps.on('exit', function (code) { - if (code !== 0) { - console.error('FAILURE: non-zero exit code'); - } - else ready(); - }); - } - else if (expanded.script.length) { - ready(); - } - else { - console.error( - 'No test files, no scripts, and no html parameter found' - + 'after expanding the globs. At least one file or a custom' - + 'html field is needed.' - ); - process.exit(1); + var files = argv._ + if(files.length && files.every(function (f) { return /\.js$/.test(f) })) { + var args = files.concat('--debug'); + var ps = spawn('browserify', args); + pkg = {testling: {}} + ps.stdout.pipe(concat(function (src) { + bundle = src; + })); + ps.stderr.pipe(process.stderr); + ps.on('exit', function (code) { + if (code !== 0) { + console.error('FAILURE: non-zero exit code'); } + else ready(); }); - } + } else { + + try { + var pkg = require(path.join(dir, 'package.json')); + } + catch (err) { + if (err.code === 'MODULE_NOT_FOUND') { + console.error( + 'No package.json in ' + dir + ' found.\n' + + 'Consult the quick start guide for how to create one:\n' + + 'https://ci.testling.com/guide/quick_start' + ); + } + else { + console.error(err.message); + } + return; + } + + if (!pkg.testling) { + console.error( + 'The "testling" field isn\'t present ' + + 'in ' + path.join(dir, 'package.json') + '.\n' + + 'This field is required by testling. Please consult:\n' + + 'https://ci.testling.com/guide/quick_start' + ); + return; + } + var bundleId = Math.floor(Math.pow(16,8)*Math.random()).toString(16); + if (pkg.testling.preprocess) { + // todo + } + else if (!pkg.testling.html) { + unglob(dir, pkg.testling, function (err, expanded) { + if (err) return console.error(err); + process.env.PATH = path.resolve(dir, 'node_modules/.bin') + + ':' + process.env.PATH + ; + scripts = expanded.script; + + if (expanded.file.length) { + var args = expanded.file.concat('--debug'); + var ps = spawn('browserify', args, { cwd: dir }); + ps.stdout.pipe(concat(function (src) { + bundle = src; + htmlQueue.forEach(function (f) { getHTML(f) }); + })); + ps.stderr.pipe(process.stderr); + ps.on('exit', function (code) { + if (code !== 0) { + console.error('FAILURE: non-zero exit code'); + } + else ready(); + }); + } + else if (expanded.script.length) { + ready(); + } + else { + console.error( + 'No test files, no scripts, and no html parameter found' + + 'after expanding the globs. At least one file or a custom' + + 'html field is needed.' + ); + process.exit(1); + } + }); + } + } } else { process.stdin.pipe(concat(function (src) {