Mocha with Grunt:找不到存在的模块

时间:2016-03-02 20:38:25

标签: json gruntjs mocha

我遇到了Mocha找到存在的模块的问题。我有一个包含我所有测试数据的数据文件夹。此文件夹存在且位于正确的目录中(使用pwd确认)。当我使用mocha test filename 运行测试时,测试通过,但是当我使用grunt test时,我收到以下错误。

Running "mochaTest:tests" (mochaTest) task
>> Mocha exploded!
>> Error: Cannot find module '/Users/user/Documents/project/project_dispatcher/tests/data'
>>     at Function.Module._resolveFilename (module.js:339:15)
>>     at Function.Module._load (module.js:290:25)
>>     at Module.require (module.js:367:17)
>>     at require (internal/module.js:16:19)
>>     at /Users/user/Documents/project/project_dispatcher/node_modules/mocha/lib/mocha.js:219:27
>>     at Array.forEach (native)
>>     at Mocha.loadFiles (/Users/user/Documents/project/project_dispatcher/node_modules/mocha/lib/mocha.js:216:14)
>>     at MochaWrapper.run (/Users/user/Documents/project/project_dispatcher/node_modules/grunt-mocha-test/tasks/lib/MochaWrapper.js:51:15)
>>     at /Users/user/Documents/project/project_dispatcher/node_modules/grunt-mocha-test/tasks/mocha-test.js:86:20
>>     at capture (/Users/user/Documents/project/project_dispatcher/node_modules/grunt-mocha-test/tasks/mocha-test.js:33:5)
Warning: Task "mochaTest:tests" failed. Use --force to continue.

我假设这是一个配置问题,但我遗失了导致它的原因。我有以下结构:

- >测试

- > testfile.js

- >数据

----> datafile.json

我使用:

包含json文件
var requestObj = require('./data/workflowRequest.json');

./不再有效,因为我正在使用位于测试文件夹上方的Grunt吗?我也很困惑,因为堆栈跟踪只包含mocha文件,而且没有我写的测试文件。

修改 Grunt代码也可能有用

mochaTest: {
    tests: {
        src:['tests/**/*'],
        options: {
            reporter: 'spec'
        }
    },
    watch: {
        src:['tests/**/*'],
        options: {
            reporter: 'nyan'
        }
    },
    tap: {
        src:['tests/**/*'],
        options: {
            reporter: 'tap'
        }
    }
},

0 个答案:

没有答案