Node.js 未能使用帆运行摩卡测试
我正在跟踪Sails文档并尝试运行Mocha测试。 我已经按照文档指定的方式编辑了我的Node.js 未能使用帆运行摩卡测试,node.js,unit-testing,sails.js,mocha.js,Node.js,Unit Testing,Sails.js,Mocha.js,我正在跟踪Sails文档并尝试运行Mocha测试。 我已经按照文档指定的方式编辑了我的package.json,但是由于某些原因,当我尝试运行Mocha时,我总是收到eaces,permission denied error 起初我得到: Error: EACCES, permission denied '/Library/Application Support/Apple/ParentalControls/Users' 我不明白它为什么要运行我的测试,但添加了此文件夹所需的权限 然后我得到:
package.json
,但是由于某些原因,当我尝试运行Mocha时,我总是收到eaces,permission denied error
起初我得到:
Error: EACCES, permission denied '/Library/Application Support/Apple/ParentalControls/Users'
我不明白它为什么要运行我的测试,但添加了此文件夹所需的权限
然后我得到:
Error: EACCES, permission denied '/Library/Application Support/ApplePushService'
同样,我不明白,所以更改了此文件夹的权限,这也没有帮助
我不明白为什么摩卡需要这些文件的权限,或者如何修复它
我运行命令:
mocha test/bootstrap.test.js test/unit/**/*.test.js
我的项目结构与Sails教程中的项目结构完全相同
我正在使用Mocha@2.2.5。
我的同事克隆了repo,并试图在他的机器上运行测试,但失败了,出现了完全相同的错误
我试图降级到Mocha@2.2.0这也没用
完整的错误跟踪:
events.js:85
throw er; // Unhandled 'error' event
^
Error: EACCES, permission denied '/Library/Application Support/ApplePushService'
at Error (native)
at Object.fs.readdirSync (fs.js:761:18)
at Glob._readdir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:609:20)
at Glob._process (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:393:15)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach (native)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
at Glob._afterReaddir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:635:15)
at Glob._readdir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:613:17)
at Glob._process (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:393:15)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach (native)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
at Glob._afterReaddir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:635:15)
at Glob._readdir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:613:17)
at Glob._process (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:393:15)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach (native)
at Glob.<anonymous> (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
at Glob._afterReaddir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:635:15)
at Glob._readdir (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:613:17)
at Glob._process (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:393:15)
at Glob.iterator (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:171:10)
at Array.forEach (native)
at new Glob (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:169:22)
at glob (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:57:11)
at Function.globSync (/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:76:10)
at Object.lookupFiles (/usr/local/lib/node_modules/mocha/lib/utils.js:590:20)
at /usr/local/lib/node_modules/mocha/bin/_mocha:320:30
at Array.forEach (native)
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:319:6)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
npm ERR! Test failed. See above for more details.
events.js:85
投掷者;//未处理的“错误”事件
^
错误:EACCES,权限被拒绝“/Library/Application Support/ApplePushService”
错误(本机)
在Object.fs.readdirSync(fs.js:761:18)
在Glob._readdir(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:609:20)
在全局进程中(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:393:15)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach(本机)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
在Glob.\u afterReaddir(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:635:15)
在Glob._readdir(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:613:17)
在全局进程中(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:393:15)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach(本机)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
在Glob.\u afterReaddir(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:635:15)
在Glob._readdir(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:613:17)
在全局进程中(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:393:15)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:427:14)
at Array.forEach(本机)
在环球。(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:426:9)
在Glob.\u afterReaddir(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:635:15)
在Glob._readdir(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:613:17)
在全局进程中(/usr/local/lib/node\u modules/mocha/node\u modules/Glob/Glob.js:393:15)
在Glob.iterator(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:171:10)
at Array.forEach(本机)
在新的Glob(/usr/local/lib/node_modules/mocha/node_modules/Glob/Glob.js:169:22)
在glob(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:57:11)
在Function.globSync(/usr/local/lib/node_modules/mocha/node_modules/glob/glob.js:76:10)
在Object.lookupFiles(/usr/local/lib/node_modules/mocha/lib/utils.js:590:20)
at/usr/local/lib/node_modules/mocha/bin/_mocha:320:30
at Array.forEach(本机)
反对。(/usr/local/lib/node_modules/mocha/bin/_mocha:319:6)
在模块处编译(Module.js:460:26)
在Object.Module.\u extensions..js(Module.js:478:10)
在Module.load(Module.js:355:32)
在Function.Module.\u加载(Module.js:310:12)
位于Function.Module.runMain(Module.js:501:10)
启动时(node.js:129:16)
在node.js:814:3
npm错误!测试失败。请参见上文了解更多详细信息。
看看我的。我想这可能对你有帮助
如以下代码所示,请参阅
我不确定它是否有帮助,但我遇到了一个类似的问题:我一在shell中键入mocha,它就在我的应用程序外的文件夹中失败了
/usr/local/lib/node_modules/mocha/bin/_mocha:372
throw err;
^
Error: EACCES: permission denied, scandir '/backup/mint17.3/etc/cups/ssl'
我发现bug来自文件./test/mocha.opt。我在sails.js文档中写了一条评论:
/**
* @Doc :: This file should contain mocha configuration as described here: https://mochajs.org/#mochaopts
*
* Note: The default test-case timeout in Mocha is 2 seconds. Increase
* the timeout value in mocha.opts to make sure the sails lifting completes
* before any of the test-cases can be started.
*/
--timeout 5s
ls test/unit/***.test.js
做什么?您的test/
目录中似乎有一个指向/Library/Application Support/
的符号链接。运行ls
命令返回:test/unit/controllers/UserController.test.js test/unit/models/User.test.js
,这是我的两个测试文件。我在搜索时没有看到任何符号链接。可能是您所在的特定目录有问题?请尝试再次运行npm cache clean
,然后再次运行npm install
,然后再次运行该命令,看看是否有效。如果没有,也许试着切换目录?没有帮助。还尝试将文件夹移动到另一个目录,该目录不是旧目录的父目录-也没有帮助。找到方法了吗?这个问题有点老了,我也有同样的问题。摩卡正在扫描整个磁盘,并在第一个被拒绝的文件夹上死亡,但仍然没有帮助。单独运行“mocha”命令(不考虑Sails)也会返回此权限拒绝错误。我想这和风帆无关。
/**
* @Doc :: This file should contain mocha configuration as described here: https://mochajs.org/#mochaopts
*
* Note: The default test-case timeout in Mocha is 2 seconds. Increase
* the timeout value in mocha.opts to make sure the sails lifting completes
* before any of the test-cases can be started.
*/
--timeout 5s