用摩卡回收的sails.js

我有某些摩卡testing需要重新提升使用moduleLoaderOverride模拟某些策略的不同configuration的sails。 一般来说,这是工作,但似乎帆不降低和重新正确提升。

为testing执行sails实例所有pipe理的实用程序文件:

// util var Sails = require('sails/lib/app'), sails; module.exports = { sailsInstance: undefined, testConfigs: {}, start: function(callback) { this.sailsInstance = new Sails(); /* This config will NOT be enforced for the remaining tests, it is just a quick lift so our code can use sails config parser and extract the other configs easily. */ this.sailsInstance.lift({}, function(err, server) { sails = server; // populate this.testConfigs object here this.configureSails('defaultConfig', callback); }.bind(this)); }, end: function(callback) { this.sailsInstance.lower(callback); }, configureSails: function(configName, callback) { console.log('LIFTING WITH:', configName); var launchConfig = this.testConfigs[configName]; console.log('LOWERING'); this.sailsInstance.lower(function (err) { console.log('LOWERED'); this.sailsInstance = new Sails(); console.log('LIFTING'); this.sailsInstance.lift( launchConfig, function(err, server) { console.log('LIFTED'); global.sails = server; return callback(err); }.bind(this)); }.bind(this)); }, 

在test-bootstrap文件中:

 // test-bootstrap before(function (done){ util.start(done); }); after(function(done) { testUtils.end(done); }); 

在用户testing文件中:

 // user test describe('User permissions', function() { before(function(done){ util.configureSails('enablePolicies', done); }); }); 

所以,在bootstrap中一切都很顺利,但在用户testing文件中第二次解除时却失败了。 我得到的确切日志是这样的:

 LIFTING WITH: defaultConfig LOWERING LOWERED LIFTING LIFTED User permissions LIFTING WITH: enablePolicies LOWERING 1) "before all" hook 0 passing (3s) 1 failing 1) User permissions "before all" hook: Uncaught Error: Trying to start server on port 1337 but can't...Something else is probably running on that port! Please disable the other server, or choose a different port and try again. LOWERED LIFTING // npm error spam 

当风帆试图连续升起两次时,我已经看到了这个错误,但是由于我先降低了它,所以不应该发生。 我也怀疑范围问题,因为启动function做两个电梯没有运行的端口,但用户testing失败。 我看到的唯一区别是configureSails函数正在从用户testing文件而不是util文件调用,但我不知道如果这是问题或如何解决这个问题。

有什么想法吗? 提前致谢