我试图在节点中加载require模块以使用jasmine进行测试。 她是我的规范跑者
var coffee,
isVerbose,
jasmine,
key,
showColors,
sys,
i,
len,
jasmine = require('jasmine-node'),
fs = require("fs"),
sys = require('sys');
for (i = 0, len = jasmine.length; i < len; i++) {
key = jasmine[i];
global[key] = jasmine[key];
}
isVerbose = true;
showColors = true;
coffee = true;
process.argv.forEach(function(arg) {
switch (arg) {
case '--color':
return showColors = true;
case '--noColor':
return showColors = false;
case '--verbose':
return isVerbose = true;
case '--coffee':
return coffee = true;
}
});
function runSpecs(callback) {
jasmine.executeSpecsInFolder(__dirname + '/spec', (function(runner, log) {
if (runner.results().failedCount === 0) {
callback(true);
} else {
callback(false);
}
}), isVerbose, showColors);
}
exports.runSpecs = runSpecs;
我尝试加载的模块如下所示:
define(function(){
function something(){
return 'blah'
}
return {
something: something
};
});
我的规范现在看起来像这样:
var something = require('../../static/source/something.js');
我收到错误“定义未定义” 我已经尝试过使用来自require js文档的示例似乎不起作用。
var requirejs = require('requirejs');
requirejs.config({
//Pass the top-level main.js/index.js require
//function to requirejs so that node modules
//are loaded relative to the top-level JS file.
nodeRequire: require
});