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

run specific tests via command line #42

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
147 changes: 82 additions & 65 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 13 additions & 6 deletions browser/prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -68,13 +69,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 util.inspect(v)
}).join(' ')
}

process.stdout.write(msg + '\n');
if (typeof originalLog === 'function') {
return originalLog.apply(this, arguments);
Expand Down