有人能给我一些关于如何将大黄蜂与requireJs相结合的一些提示吗?BumbleBee结合了Rhino、JSpec、恩维杰和Ant,提供了一个“开箱即用”的JavaScript测试工具包。它对我们非常有用,因为它使一个简单的独立运行在ubuntu盒的终端上成为可能。
我们的整个基于需求JS模块的JS代码,如果超出了规范的要求,就不会加载所需的模块--来自envjs/大黄蜂/莱茵河的文件(可能要对此负责),这可能是由于需求JS中的异步性。
我所做的:
这些文件可能很有趣:
of /bumblebee.js(我认为它是整个测试套件的切入点):
load('dependencies/js/env.rhino.1.2.js');
window.location="examples/fixture/fixture.html";
load('dependencies/js/jspec/jspec.js');
load('dependencies/js/require-jquery.js');
var runSpec = function(spec) {
JSpec.exec(spec);
};
define(function(require) {
console.log("A1");
var dep = require('dependency');
//The value returned from the function is
//used as the module export visible to Node.
return function () {};
});
require(['dependency'], function(d){
console.log("A2");
} );
console.log("A3");
var specs = arguments;
jQuery.each(specs, function(index, spec) {
runSpec(spec);
});
JSpec
.run({ reporter: JSpec.reporters.Terminal, fixturePath: 'spec/fixtures' })
.report();只有"A3“才会被打印到控制台,基于需求的代码永远不会在这里执行。
然后,我将定义/要求部分放入规范中--示例文件中,并检测到,我也无法使用require模块,因为它们不会加载,也不会预先发送。
考虑到来自BambleBee的原始规范文件-示例:
describe('Greeter', function() {
load('examples/src/greeter.js');
it('greets people', function() {
expect(example.greeter().greet()).to(eql, 'Hello!');
});
});当我现在使用特定于requireJS的模块时,也不会加载它们:
describe('Greeter', function() {
load('examples/src/greeter.js');
require(['dependency'], function(d){
// do something with D...
console.log("This will **NEVER** be printed");
} );
console.log("This **WILL** be printed");
it('greets people', function() {
expect(example.greeter().greet()).to(eql, 'Hello!');
});
});问题
是否有一种将Envjs与requireJS相结合的方法,还是EnvJS是我们的错误测试工具?非常感谢您的提示!
发布于 2012-08-08 02:52:03
这是一个众所周知的问题。您可以参考https://github.com/envjs/env-js/issues/7来获得envjs和requirejs之间的详细讨论。我的解决方案是使用Phantomjs运行带有CI的茉莉规范,您可以在https://github.com/xiaocong/xiaocong.github.com/tree/master/examples/coffee-bbb-amd-backbone-rest-contacts上找到示例项目。
https://stackoverflow.com/questions/11207174
复制相似问题