未能通过航行运行摩卡测试

问题描述:

我正在关注Sails文档并尝试运行摩卡测试。 我按照文档指定的方式编辑了我的package.json,但由于某种原因,当我尝试运行Mocha时,我总是得到EACESS,权限被拒绝,错误。未能通过航行运行摩卡测试

起初我:

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 

我的项目结构是完全一样的教程。

我正在使用[email protected]。 我的同事克隆回购,并试图在他的机器上运行测试,但失败的错误完全相同。

我试图降级到[email protected]这也没有帮助。

完整的错误跟踪:

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. 
+0

什么'LS测试/单位/ **/* .test.js'呢?看起来像'/ Library/Application Support /'可能在'test /'目录的某个地方存在一个符号链接。 – robertklep

+0

运行'ls'命令返回:'test/unit/controllers/UserController.test.js test/unit/models/User.test.js'这是我的两个测试文件。搜索时没有看到任何符号链接。 – OmriToptix

+0

也许这是你的特定目录的问题?尝试运行'npm cache clean'然后再次运行'npm install'并再次运行该命令并查看它是否可用。如果没有,也许尝试切换dirs? –

看看我的sails.js test example。我认为它可以帮助你。

如以下代码所示,请参阅test/bootstrap.js

var Sails = require('sails'); 
var _ = require('lodash') 
global.DOMAIN = 'http://localhost'; 
global.PORT = 1420; 
global.HOST = DOMAIN + ':' + PORT; 
before(function(callback) { 
    this.timeout(7000); 

    var configs = { 
    log: { 
     level: 'info' 
    }, 
    connections: { 
     memory: { 
     // lets use memory tests ... 
     adapter : 'sails-memory' 
     } 
    }, 
    models: { 
     connection: 'memory' 
    }, 
    port: PORT, 
    environment: 'test', 

    // @TODO needs suport to csrf token 
    csrf: false, 

    // we dont need this configs in API test 
    hooks: { 
     grunt: false, 
     socket: false, 
     pubsub: false 
    } 
    }; 

    Sails.load(configs, function(err, sails) { 
    if (err) { 
     console.error(err); 
     return callback(err); 
    } 

    console.log('rodo!') 
    // here you can load fixtures, etc. 
    callback(err, sails); 
    }); 
}); 

after(function(done) { 
    // here you can clear fixtures, etc. 
    sails.lower(done); 
}); 
+0

仍然没有帮助。无论Sails如何运行命令“mocha”,都会返回此权限被拒绝的错误。我想这与Sails无关。 – OmriToptix

我不知道,如果它可以帮助,但我有一个类似的问题:只要我在shell中键入摩卡,它是用EACCES的文件夹我的应用程序之外的失败。 :

/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