“没有这样的模块"尝试让Mocha观看我的项目时出现错误 [英] "No such module" error when trying to get Mocha to watch my project

查看:63
本文介绍了“没有这样的模块"尝试让Mocha观看我的项目时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Mocha观看我的项目进行测试并不断运行测试,但是当我使用-w标志时,我得到了一个错误.

I'm trying to get Mocha to watch my project for test and constantly run the tests but when I use the -w flag I get an error.

这里测试执行正常:

C:\Foo>mocha

  .

  ? 1 tests complete (3ms)

,这里是-w

C:\Foo>mocha -w


node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: No such module
    at EventEmitter.<anonymous> (node.js:392:27)
    at Object.<anonymous> (C:\Users\Greg\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:203:11)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

我已在全球(npm install -g mocha)上安装了Mocha,并且应该在项目的本地安装.

I have Mocha installed globally (npm install -g mocha) and should installed locally to the project.

我在64位Windows 7家庭高级版上使用节点v0.6015,摩卡1.0.1和应该0.6.1.

I'm using node v0.6015, Mocha 1.0.1 and Should 0.6.1 on 64bit Windows 7 home premium.

推荐答案

我能够通过更改几个Mocha源代码文件使它在Windows上运行. 在npm之后安装了mocha(在我的情况下,我只是为我的项目安装了它,而不是为全局安装):

I was able to make it work on windows by changing a couple of mocha source code files. After npm install mocha (in my case I installed it just for my project, not globally):

1)首先转到 node_modules \ mocha \ lib \ utils.js 查找并修复 watch 函数,如下所示:

1) First go to node_modules\mocha\lib\utils.js find and fix watch function as follows:

exports.watch = function(files, fn) {
    var options = { interval: 100 };
    files.forEach(function(file) {
        debug('file %s', file);
        fs.watch(file, options, function(curr, prev) {
            fn(file);
        });
    });
};

我用fs.watch替换了fs.watchFile(请参阅 https://github. com/fgnass/node-dev/issues/26 了解详情),因为第一个似乎无法在Windows上运行.

I replaced fs.watchFile with fs.watch (see https://github.com/fgnass/node-dev/issues/26 for details) because the first one doesn't seem to work on windows.

2)现在打开 node_modules \ mocha \ bin \ _mocha 并应用以下修复程序:

2) Now open node_modules\mocha\bin\_mocha and apply following fixes:

a)查找并注释掉或删除以下代码:

a) Find and comment out or remove following code:

process.on('SIGINT', function(){
  showCursor();
  console.log('\n');
  process.exit();
});

由于上面的POSIX信号没有等效的需要删除(理想地由正确的实现代替,请参见

Since there's no equivalent of POSIX signals lines above have to be removed (ideally replaced by proper implementation, see What is the Windows equivalent of process.on('SIGINT') in node.js? for more details)

b)查找以下代码 utils.watch(watchFiles,function(){... ,并将其替换为

b) Find following code utils.watch(watchFiles, function(){... and replace it with

  var lastRun = new Date();
  utils.watch(watchFiles, function(){
    if (new Date() - lastRun > 300)
    {
        purge();
        stop()
        mocha.suite = mocha.suite.clone();
        ui = interfaces[program.ui](mocha.suite);
        loadAndRun();
        lastRun = new Date();
    }
  });

它抑制了来自fs.watch的过多呼叫.

It throttles excessive callacks from fs.watch.

c)最后一项更改是删除或注释掉此行:

c) Last change is removing or commenting out this line:

  process.stdout.write('\r' + str);

功能播放(arr,interval)中.它只是消除噪音.

in function play(arr, interval). It just removes noise.

这篇关于“没有这样的模块"尝试让Mocha观看我的项目时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆