我一直在使用一些自定义Node.js模块的项目。我创建了一个 '助手' 模块,与装载协助一些辅助方法:Catch-22递归节点模块在使用摩卡时炸掉了
/helpers/index.js:
var mutability = require('./mutability'),
cb = require('./cb'),
build = require('./build'),
userAgent = require('./userAgent'),
is = require('./is'),
query = require('./query'),
config = require('./config'),
_ = require('underscore')
module.exports = _.extend({
cb: cb,
build: build,
userAgent: userAgent,
is: is,
query: query,
config: config
}, mutability)
为了好玩,mutability.js
是:
'use strict'
module.exports = {
setReadOnly: function(obj, key) {
// whatever
return obj
},
setWritable: function(obj, key) {
// whatever
return obj
}
}
我的模块之一,build
,需要一个类来做一些类型检查:
/helpers/build.js
'use strict'
var urljoin = require('url-join'),
config = require('./config'),
cb = require('./cb'),
Entity = require('../lib/entity'),
_ = require('underscore')
module.exports = {
url: function(options) {
return urljoin(
config.baseUrl,
options.client.orgId,
options.client.appId,
options.type, (typeof options.uuidOrName === 'string') ? options.uuidOrName : ""
)
},
GET: function(options) {
options.type = options.type || args[0] instanceof Entity ? args[0]._type : args[0]
options.query = options.query || args[0] instanceof Entity ? args[0] : undefined
return options
}
}
而且Entity
则需要helpers
:
/lib/entity.js
'use strict'
var helpers = require('../helpers'),
ok = require('objectkit'),
_ = require('underscore')
var Entity = function(object) {
var self = this
_.extend(self, object)
helpers.setReadOnly(self, ['uuid'])
return self
}
module.exports = Entity
无论出于何种原因,当我和摩卡运行此,我得到helpers
注销为{}
和摩卡抛出:
Uncaught TypeError: helpers.setReadOnly is not a function
当我运行/lib/entity.js
直接与node
,它打印适当的模块。是什么赋予了?摩卡为什么炸毁?
你没有给我们看的'/ helpers/mutability.js'模块似乎是最相关的 – Bergi
娜,我不这么认为。如果我直接需要'var mutability = require('/ helpers/mutability')'它工作得很好。我实际上倾向于这是一个摩卡错误,因为它不是*只是*缺少可变性,它是整个帮助者对象。 – brandonscript