2

我正在尝试在节点中加载需要模块以使用 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
 });
4

0 回答 0