-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Halliday
committed
May 16, 2012
1 parent
cdf7efb
commit 7b81b93
Showing
4 changed files
with
148 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,42 @@ | ||
#!/usr/bin/env node | ||
var http = require('http'); | ||
var request = require('request'); | ||
var archy = require('archy'); | ||
var argv = require('optimist').argv; | ||
|
||
var testling = require('testling'); // sets up the test output | ||
|
||
var runner = require('../lib/run'); | ||
var testFiles = require('../lib/test_files'); | ||
var streamFiles = require('../lib/stream_files'); | ||
var withConfig = require('../lib/account/with_config'); | ||
|
||
var parse = require('optimist') | ||
.usage('Usage: testling [test files] {OPTIONS}') | ||
.option('browsers', { | ||
alias : 'b', | ||
desc : 'Run your tests remotely in real browsers on testling.com.' | ||
}) | ||
.option('output', { | ||
alias : 'o', | ||
desc : 'The output format to use in remote mode.\r\n' | ||
+ ' http://testling.com/docs/#output-parameter\r\n' | ||
}) | ||
.option('noinstrument', { | ||
desc : 'Turn off instrumentation for particular files in remote mode.\r\n' | ||
+ ' http://testling.com/docs/#noinstrument\r\n' | ||
}) | ||
.option('main', { | ||
desc : 'Use a filename besides "test.js" to start multifile bundles.\r\n' | ||
+ ' http://testling.com/docs/#main\r\n' | ||
}) | ||
.option('browserlist', { | ||
alias : 'l', | ||
desc : 'Show the available browsers on testling.com.' | ||
}) | ||
.option('config', { | ||
default : process.env.HOME + '/.config/testling.json', | ||
desc : 'Read configuration information from this file.' | ||
}) | ||
; | ||
var argv = parse.argv; | ||
|
||
if (argv.browserlist) { | ||
if (argv['list-browsers']) { | ||
var opts = { | ||
host : 'testling.com', | ||
path : '/browsers.json' | ||
uri : 'http://testling.com/browsers.json', | ||
json : true, | ||
}; | ||
http.get(opts, function (res) { | ||
var body = ''; | ||
res.on('data', function (buf) { | ||
body += buf.toString(); | ||
}); | ||
request(opts, function (err, res, browsers) { | ||
var remotes = browsers.reduce(function (acc, name) { | ||
var s = name.split('/'); | ||
var b = s[0], v = s[1]; | ||
|
||
if (!acc[b]) acc[b] = []; | ||
acc[b].push(v); | ||
|
||
return acc; | ||
}, {}); | ||
|
||
res.on('end', function () { | ||
if (res.statusCode !== 200) console.error(err) | ||
else { | ||
var xs = JSON.parse(body); | ||
var browsers = xs.reduce(function (acc, x) { | ||
var s = x.split('/'); | ||
var b = s[0], v = s[1]; | ||
acc[b] = (acc[b] || []).concat(v); | ||
return acc; | ||
}, {}); | ||
|
||
Object.keys(browsers).forEach(function (name) { | ||
console.log(name); | ||
var vs = browsers[name].sort(); | ||
console.log(' [ ' + vs.join(', ') + ' ]'); | ||
}); | ||
} | ||
var remoteNodes = Object.keys(remotes).map(function (key) { | ||
var bs = remotes[key].sort(function (a,b) { | ||
if (isNaN(Number(a))) return 1; | ||
if (isNaN(Number(b))) return -1; | ||
return Number(a) - Number(b); | ||
}); | ||
return { label : key, nodes : bs }; | ||
}); | ||
}); | ||
} | ||
else if (argv.browsers) { | ||
withConfig(argv.config, function (err, config) { | ||
if (err) { | ||
console.error('\r\nError: ' + err); | ||
return; | ||
} | ||
|
||
var auth = 'basic ' + new Buffer( | ||
[ config.email, config.password ].join(':') | ||
).toString('base64'); | ||
|
||
var params = [ 'output', 'browsers', 'noinstrument', 'main' ] | ||
.reduce(function (acc, key) { | ||
if (typeof argv[key] === 'string') { | ||
acc[key] = argv[key]; | ||
} | ||
return acc; | ||
}, {}) | ||
; | ||
console.log(archy({ | ||
label : 'remote browsers', | ||
nodes : remoteNodes | ||
})); | ||
|
||
var query = Object.keys(params).map(function (key) { | ||
return escape(key) + '=' + escape(params[key]); | ||
}).join('&'); | ||
var localNodes = []; | ||
|
||
var opts = { | ||
method : 'PUT', | ||
host : 'testling.com', | ||
port : 80, | ||
path : '/?' + query, | ||
headers : { authorization : auth }, | ||
}; | ||
var req = http.request(opts, function (res) { | ||
res.pipe(process.stdout); | ||
}); | ||
streamFiles(testFiles(argv._)).pipe(req); | ||
console.log(archy({ | ||
label : 'local browsers', | ||
nodes : localNodes | ||
})); | ||
}); | ||
} | ||
else if (argv._.length) { | ||
runner(testFiles(argv._)); | ||
} | ||
else { | ||
parse.showHelp(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/usr/bin/env node | ||
var http = require('http'); | ||
|
||
var testling = require('testling'); // sets up the test output | ||
|
||
var runner = require('../lib/run'); | ||
var testFiles = require('../lib/test_files'); | ||
var streamFiles = require('../lib/stream_files'); | ||
var withConfig = require('../lib/account/with_config'); | ||
|
||
var parse = require('optimist') | ||
.usage('Usage: testling [test files] {OPTIONS}') | ||
.option('browsers', { | ||
alias : 'b', | ||
desc : 'Run your tests remotely in real browsers on testling.com.' | ||
}) | ||
.option('output', { | ||
alias : 'o', | ||
desc : 'The output format to use in remote mode.\r\n' | ||
+ ' http://testling.com/docs/#output-parameter\r\n' | ||
}) | ||
.option('noinstrument', { | ||
desc : 'Turn off instrumentation for particular files in remote mode.\r\n' | ||
+ ' http://testling.com/docs/#noinstrument\r\n' | ||
}) | ||
.option('main', { | ||
desc : 'Use a filename besides "test.js" to start multifile bundles.\r\n' | ||
+ ' http://testling.com/docs/#main\r\n' | ||
}) | ||
.option('browserlist', { | ||
alias : 'l', | ||
desc : 'Show the available browsers on testling.com.' | ||
}) | ||
.option('config', { | ||
default : process.env.HOME + '/.config/testling.json', | ||
desc : 'Read configuration information from this file.' | ||
}) | ||
; | ||
var argv = parse.argv; | ||
|
||
if (argv.browserlist) { | ||
var opts = { | ||
host : 'testling.com', | ||
path : '/browsers.json' | ||
}; | ||
http.get(opts, function (res) { | ||
var body = ''; | ||
res.on('data', function (buf) { | ||
body += buf.toString(); | ||
}); | ||
|
||
res.on('end', function () { | ||
if (res.statusCode !== 200) console.error(err) | ||
else { | ||
var xs = JSON.parse(body); | ||
var browsers = xs.reduce(function (acc, x) { | ||
var s = x.split('/'); | ||
var b = s[0], v = s[1]; | ||
acc[b] = (acc[b] || []).concat(v); | ||
return acc; | ||
}, {}); | ||
|
||
Object.keys(browsers).forEach(function (name) { | ||
console.log(name); | ||
var vs = browsers[name].sort(); | ||
console.log(' [ ' + vs.join(', ') + ' ]'); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
else if (argv.browsers) { | ||
withConfig(argv.config, function (err, config) { | ||
if (err) { | ||
console.error('\r\nError: ' + err); | ||
return; | ||
} | ||
|
||
var auth = 'basic ' + new Buffer( | ||
[ config.email, config.password ].join(':') | ||
).toString('base64'); | ||
|
||
var params = [ 'output', 'browsers', 'noinstrument', 'main' ] | ||
.reduce(function (acc, key) { | ||
if (typeof argv[key] === 'string') { | ||
acc[key] = argv[key]; | ||
} | ||
return acc; | ||
}, {}) | ||
; | ||
|
||
var query = Object.keys(params).map(function (key) { | ||
return escape(key) + '=' + escape(params[key]); | ||
}).join('&'); | ||
|
||
var opts = { | ||
method : 'PUT', | ||
host : 'testling.com', | ||
port : 80, | ||
path : '/?' + query, | ||
headers : { authorization : auth }, | ||
}; | ||
var req = http.request(opts, function (res) { | ||
res.pipe(process.stdout); | ||
}); | ||
streamFiles(testFiles(argv._)).pipe(req); | ||
}); | ||
} | ||
else if (argv._.length) { | ||
runner(testFiles(argv._)); | ||
} | ||
else { | ||
parse.showHelp(); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters