我得到了我约曼运行真棒客户端测试。 约曼编译我的CoffeeScript,在服务器开启了测试页面,用PhantomJS参观,并通过所有测试结果的命令行。 该过程是相当哈克,测试结果经由传递alert()
消息,其创建一个临时文件,并与邮件作为JSON填充它的幻影的过程。 约曼(当然,咕噜)循环通过临时文件,解析所述测试并将它们显示在命令行。
我解释了处理的原因,我想了一些东西添加到它。 我得到了服务器端的测试以及。 他们用摩卡和supertest检查API端点和Redis的客户端,以确保数据库状态正常。 但我想合并这两个测试套件!
我不想写的服务器调用客户端模拟响应。 我不想向服务器发送模拟数据。 沿途某处,我会改变服务器或客户端和测试将不会失败。 我想做一个真正的集成测试。 所以,当在客户端的测试结束我想钩上运行服务器端的相关测试(检查数据库状态,会话状态,移动到不同的测试页)。
是否有此解决方案的任何? 或者,altenatively,我从哪里开始黑客攻击约曼/格朗特/咕噜,摩卡,使这项工作?
我想,幻影处理程序中的咕噜,摩卡是一个良好的开端:
// Handle methods passed from PhantomJS, including Mocha hooks.
var phantomHandlers = {
// Mocha hooks.
suiteStart: function(name) {
unfinished[name] = true;
currentModule = name;
},
suiteDone: function(name, failed, passed, total) {
delete unfinished[name];
},
testStart: function(name) {
currentTest = (currentModule ? currentModule + ' - ' : '') + name;
verbose.write(currentTest + '...');
},
testFail: function(name, result) {
result.testName = currentTest;
failedAssertions.push(result);
},
testDone: function(title, state) {
// Log errors if necessary, otherwise success.
if (state == 'failed') {
// list assertions
if (option('verbose')) {
log.error();
logFailedAssertions();
} else {
log.write('F'.red);
}
} else {
verbose.ok().or.write('.');
}
},
done: function(failed, passed, total, duration) {
var nDuration = parseFloat(duration) || 0;
status.failed += failed;
status.passed += passed;
status.total += total;
status.duration += Math.round(nDuration*100)/100;
// Print assertion errors here, if verbose mode is disabled.
if (!option('verbose')) {
if (failed > 0) {
log.writeln();
logFailedAssertions();
} else {
log.ok();
}
}
},
// Error handlers.
done_fail: function(url) {
verbose.write('Running PhantomJS...').or.write('...');
log.error();
grunt.warn('PhantomJS unable to load "' + url + '" URI.', 90);
},
done_timeout: function() {
log.writeln();
grunt.warn('PhantomJS timed out, possibly due to a missing Mocha run() call.', 90);
},
// console.log pass-through.
// console: console.log.bind(console),
// Debugging messages.
debug: log.debug.bind(log, 'phantomjs')
};
谢谢! 会有这个赏金。