我不知道为什么mocha.js找不到我的路径! 这是我的节点课程项目中包含的文件结构
///////Root
--package.json
--node_modules/
--playground
--server
-server.js
-db
-models
-tests
---server.test.js
每次我运行“ mocha server / ** / *。test.js”时,从命令提示符处运行测试命令后,都会从命令提示符处得到此错误:
> todo-api@1.0.0 test C:\Users\Omar Ali\Desktop\node-todo-api
> mocha server/**/*.test.js
module.js:549
throw err;
^
Error: Cannot find module '../server/server'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Omar Ali\Desktop\node-todo-api\server\tests\
server.test.js:6:9)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\mocha\lib\mocha.js:2
50:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\moc
ha\lib\mocha.js:247:14)
at Mocha.run (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\mocha\lib
\mocha.js:576:10)
at Object.<anonymous> (C:\Users\Omar Ali\Desktop\node-todo-api\node_modules\
mocha\bin\_mocha:637:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todo-api@1.0.0 test: `mocha server/**/*.test.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the todo-api@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Omar Ali\AppData\Roaming\npm-cache\_logs\2018-07-28T18_00_
44_790Z-debug.log
答案 0 :(得分:1)
由于要显示结构,因此应该为require 'vendor/autoload.php';
或../server
,因为您的服务器模块(或文件)位于测试脚本的父级中。>