Skip to content

Instantly share code, notes, and snippets.

@Hounddog
Created July 30, 2012 08:02
Show Gist options
  • Save Hounddog/3205607 to your computer and use it in GitHub Desktop.
Save Hounddog/3205607 to your computer and use it in GitHub Desktop.
Ci implementation for dojo doh
define(["doh/runner", "dojo/_base/xhr", "dojo/_base/connect","dojo/json", "dojo/io-query"], function(doh, xhr, connect, json, ioQuery) {
var uri = window.location.search;
var query = uri.substring(uri.indexOf("?") + 1, uri.length);
var queryObject = ioQuery.queryToObject(query);
var data = json.stringify({'doh': 'start', "browser": queryObject.browser});
xhr.post({
url: "/receiver.php",
sync:true,
content:{
'COMMAND': data
}
});
connect.connect(doh, "debug", function(){
var data = json.stringify({'message':Array.prototype.join.call(arguments, " "), "browser": queryObject.browser })
xhr.post({
url: "/receiver.php",
sync:true,
content:{
'DATA': data
},
load:function(data) {
window.close();
}
})
});
connect.connect(doh, "_report", function(){
var data = json.stringify({'doh':'result', 'failureCount': doh._failureCount, 'errorCount': doh._errorCount})
xhr.post({
url: "/receiver.php",
sync:true,
content:{
'COMMAND': data
},
load:function(data) {
}
})
});
});
/**
* Module dependencies.
*/
var program = require('commander');
/**
* Cli options
*/
program
.version('0.0.1')
.option('-u, --url [type]', 'Add the url to connect to [required]')
.option('-B, --base-path [type]', 'Specify Dojo BasePath')
.option('-m, --module [type]', 'Specify Module for testing')
.option('-M, --module-path [type]', 'Specify Module Paths')
.option('-s, --server [type]', 'Specify server url for nodeJs runner. If not set will deault to url [-url]')
.option('-p, --port <n>', 'Specify the port [8000]', parseInt, 8000)
.option('-a, --no-auto', 'Auto Start browser')
.option('-b, --browser [type]', 'Specify Browser for testing [firefox]. Required if autostart is enabled')
.parse(process.argv)
if (process.argv.length == 2) {
process.stdout.write(program.helpInformation());
program.emit('--help');
process.exit(0);
}
/**
* Process CLI
*/
if(!program.url) {
var message = [
'',
' Please Specify Url',
''
].join('\n');
process.stdout.write(message);
process.stdout.write(program.helpInformation());
program.emit('--help');
process.exit(0);
}
if(!program.server) {
program.server = program.url;
}
if(!program.module) {
var message = [
'',
' Please Specify module for testing',
''
].join('\n');
process.stdout.write(message);
process.stdout.write(program.helpInformation());
program.emit('--help');
process.exit(0);
}
if(program.auto) {
if(!program.browser) {
var message = [
'',
' Auto is enabled. Please Specify Browser',
''
].join('\n');
process.stdout.write(message);
process.stdout.write(program.helpInformation());
program.emit('--help');
process.exit(0);
}
}
/**
* spawn listener
*/
var io = require('socket.io').listen(program.port);
io.set('log level', 1);
url = createUrl();
/**
* Spawn browser
*/
if(program.auto) {
var spawn = require('child_process').spawn;
browser = spawn(program.browser, [url]);
}
browser.stderr.setEncoding('utf8');
browser.stderr.on('data', function (data) {
if (/^execvp\(\)/.test(data)) {
console.log('Failed to start browser.');
}
});
startOutput = [
'',
' Server started',
'',
' Listening on Port: \t' + program.port,
' Testing Module: \t' + program.module,
' Running Browser: \t' + program.browser,
' Dojo basePath: \t' + program.basePath,
' Test url: \t\t' + url,
' Server url: \t\t' + program.server,
'',
' Waiting for Connection',
''
].join('\n');
process.stdout.write(startOutput);
io.sockets.on('connection', function (socket) {
var message = [
'',
' Connection established',
'',
''
].join('\n');
process.stdout.write(message);
socket.on('debug', function (message) {
console.log(message.message)
});
socket.on('result', function (message) {
var success = true;
if (message.errorCount >0 || message.failureCount > 0) {
success = false;
}
console.log("------------------------------------------------------------");
console.log("TESTS FOR " + program.browser + " " + (success? "PASSED": "FAILED"));
console.log("------------------------------------------------------------");
browser.kill('SIGHUP');
if(success) {
process.exit(0);
} else {
process.exit(1);
}
});
});
function createUrl () {
var runner = program.basePath + '/util/doh/runner.html';
var url= program.url + runner + '?testModule=' + program.module;
if(program.modulePath) {
url += '&registerModulePath=' + program.modulePath;
}
url += '&dohPlugins=widget/doh/node&port=' + program.port + '&server=' + program.server + '&browser=' + program.browser;
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment