spectacular
Version:
Advanced BDD framework for CoffeeScript and JavaScript
117 lines (108 loc) • 3.33 kB
JavaScript
// Generated by CoffeeScript 1.6.3
var PORT, URL, page, specsReady, system, waitFor;
page = require('webpage').create();
system = require('system');
PORT = system.args[1] || 5000;
URL = "http://localhost:" + PORT;
page.onConsoleMessage = function(msg, line, source) {
return console.log(msg);
};
page.open(URL).then(function(status) {
var done, runnerAvailable;
if (status !== 'success') {
console.log(JSON.stringify({
error: "Unable to access Spectacular specs at " + URL
}));
page.close();
return slimer.exit();
} else {
runnerAvailable = page.evaluate(function() {
return window.spectacular;
});
if (runnerAvailable) {
page.evaluate(function() {
var reporter, styles;
styles = {
bold: ['\x1B[1m', '\x1B[22m'],
italic: ['\x1B[3m', '\x1B[23m'],
underline: ['\x1B[4m', '\x1B[24m'],
inverse: ['\x1B[7m', '\x1B[27m'],
strikethrough: ['\x1B[9m', '\x1B[29m'],
white: ['\x1B[37m', '\x1B[39m'],
grey: ['\x1B[90m', '\x1B[39m'],
black: ['\x1B[30m', '\x1B[39m'],
blue: ['\x1B[34m', '\x1B[39m'],
cyan: ['\x1B[36m', '\x1B[39m'],
green: ['\x1B[32m', '\x1B[39m'],
magenta: ['\x1B[35m', '\x1B[39m'],
red: ['\x1B[31m', '\x1B[39m'],
yellow: ['\x1B[33m', '\x1B[39m']
};
window.spectacular.utils.colorize = function(str, color, colors) {
if (colors) {
return styles[color][0] + str + styles[color][1];
} else {
return str;
}
};
reporter = window.spectacular.ConsoleReporter.getDefault(spectacular.options);
window.env.runner.on('result', reporter.onResult);
window.env.runner.on('end', reporter.onEnd);
reporter.on('report', function(msg) {
return window.consoleResults = msg.target;
});
return reporter.on('message', function(msg) {
window.consoleProgress || (window.consoleProgress = '');
return window.consoleProgress += msg.target;
});
});
done = function() {
var result;
result = page.evaluate(function() {
return window.result;
});
console.log(page.evaluate(function() {
return window.consoleProgress;
}));
console.log(page.evaluate(function() {
return window.consoleResults;
}));
if (result) {
return slimer.exit();
} else {
return slimer.exit();
}
};
return waitFor(specsReady, done);
} else {
return slimer.exit();
}
}
});
specsReady = function() {
return page.evaluate(function() {
return window.consoleResults != null;
});
};
waitFor = function(test, ready, timeout) {
var condition, interval, start, wait;
if (timeout == null) {
timeout = 60000;
}
start = new Date().getTime();
condition = false;
wait = function() {
if ((new Date().getTime() - start < timeout) && !condition) {
return condition = test();
} else {
if (condition) {
clearInterval(interval);
return ready();
} else {
console.log('error with timeout');
return slimer.exit();
}
}
};
return interval = setInterval(wait, 250);
};