将Node.js模块导入Interntesting时出错
我正在尝试实习生来testing我们的Node.js模块。 我已经设置了运行一个空的testing,甚至require
节点模块,但是当我试图require
在我们的包中的模块之一,我得到的错误:
/path/to/app/node_modules/path/path.js:327 var path = (i >= 0) ? arguments[i] : process.cwd(); ^ TypeError: undefined is not a function at Object.exports.resolve (/path/to/app/node_modules/path/path.js:327:52) at Object.exports.relative (/path/to/app/node_modules/path/path.js:405:20) at getSource (/path/to/app/node_modules/intern/lib/util.js:368:21) at formatLine (/path/to/app/node_modules/intern/lib/util.js:405:40) at processChromeTrace (/path/to/app/node_modules/intern/lib/util.js:418:16) at normalizeStackTrace (/path/to/app/node_modules/intern/lib/util.js:470:38) at Object.getErrorMessage (/path/to/app/node_modules/intern/lib/util.js:597:14) at PreExecutor._handleError (/path/to/app/node_modules/intern/lib/executors/PreExecutor.js:256:24) at /path/to/app/node_modules/intern/node_modules/dojo/lang.js:78:32 at process.<anonymous> (/path/to/app/node_modules/intern/lib/executors/PreExecutor.js:302:6)
文件夹结构是:
- SRC /
- **/*。咖啡
- testing
- 单位/ ** / *。咖啡
- intern.js
- js /(coffeescript在这里编译)
- SRC /
- ** / *。JS
- testing/
- ** / *。JS
- all.js(通过在
/js/tests
下滚动其他testing的名称进行编译)
- SRC /
- node_modules
这是我的intern.js:
define({ capabilities: { 'browserstack.selenium_version': '2.45.0' }, environments: [ {browserName: 'internet explorer', version: '11', platform: 'WIN8'}, {browserName: 'internet explorer', version: '10', platform: 'WIN8'}, {browserName: 'internet explorer', version: '9', platform: 'WINDOWS'}, {browserName: 'firefox', version: '37', platform: ['WINDOWS', 'MAC']}, {browserName: 'chrome', version: '39', platform: ['WINDOWS', 'MAC']}, {browserName: 'safari', version: '8', platform: 'MAC'} ], maxConcurrency: 2, tunnel: 'BrowserStackTunnel', loaderOptions: { packages: [{name: 'app', location: 'js/src'}] }, reporters: ['Console', 'Lcov'], suites: ['js/tests/unit/all'], excludeInstrumentation: /^(?:\.npm|js\/tests|src|tests|node_modules)\// });
我的testing只是:
define (require) -> registerSuite = require('intern!object') assert = require('intern/chai!assert') SchemaBuilder = require('intern/dojo/node!app/path/to/Module') registerSuite name: 'Testing' 'test': ->
从项目根目录运行'./node_modules/.bin/intern-client config=tests/intern'
这是我的代码,configuration,环境或实习生的问题吗?
我已经尝试了Node.js v0.12.0和v0.12.7。
有趣的是,从我的应用程序依赖项( package.json
)中删除path
模块解决了(好,避免) undefined is not a function
错误,似乎回落在实习生自己的pathparsing。 我真的不知道为什么,但这似乎是一个错误。
这提出了一个新的,更容易处理的错误: Error: Cannot find module 'app/path/to/Module'
,build议require()
path是错误的。
我认为问题是intern/dojo/node
loader不支持loaderOptions: {packages: [{name: 'app', location: 'js/src'}]}
configuration,因此它正在寻找一个app
目录相对于testing模块。 如果我用../../../../js/src/
replaceapp/
然后它parsing并按预期工作。
这有点难看,但这是在节点上需要本地文件的标准方式,所以也不足为奇,我只希望Intern的loader可以使它更清洁。