摩卡测试失败而没有给出正确的错误

如何解决摩卡测试失败而没有给出正确的错误

我已经设置了 mocha 来在我的 express 应用程序上运行测试。但是,每次我运行 npm test 时,mocha 测试都会失败而没有给出任何错误,请参阅屏幕

enter image description here

这是我的 package.json 的片段,我的文件夹结构和代码

enter image description here

enter image description here

enter image description here

我也尝试手动运行 mocha,但它不打印任何内容。它只是退出进程。最后我尝试在调试模式下运行它,这是调试模式的日志

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',1 verbose cli   'run',1 verbose cli   'test'
1 verbose cli ]
2 info using npm@6.14.10
3 info using node@v14.15.4
4 verbose run-script [ 'pretest','test','posttest' ]
5 info lifecycle data-central@1.0.0~pretest: data-central@1.0.0
6 info lifecycle data-central@1.0.0~test: data-central@1.0.0
7 verbose lifecycle data-central@1.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle data-central@1.0.0~test: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;E:\The expert Institute\data-central-backend\node_modules\.bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Admin\bin;C:\Program Files\python39\Scripts;C:\Program Files\python39;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk-11.0.9\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Amazon\AWSCLIV2;C:\Users\Admin\AppData\Local\Microsoft\WindowsApps;C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Admin\AppData\Roaming\npm;C:\Program Files (x86)\terraform;C:\Users\Admin\AppData\Roaming\Python\python39\Scripts
9 verbose lifecycle data-central@1.0.0~test: CWD: E:\The expert Institute\data-central-backend
10 silly lifecycle data-central@1.0.0~test: Args: [ '/d /s /c',"mocha './tests/*.test.js'" ]
11 silly lifecycle data-central@1.0.0~test: Returned: code: 1  signal: null
12 info lifecycle data-central@1.0.0~test: Failed to exec test script
13 verbose stack Error: data-central@1.0.0 test: `mocha './tests/*.test.js'`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1048:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
14 verbose pkgid data-central@1.0.0
15 verbose cwd E:\The expert Institute\data-central-backend
16 verbose Windows_NT 10.0.19042
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
18 verbose node v14.15.4
19 verbose npm  v6.14.10
20 error code ELIFECYCLE
21 error errno 1
22 error data-central@1.0.0 test: `mocha './tests/*.test.js'`
22 error Exit status 1
23 error Failed at the data-central@1.0.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1,true ]

操作系统 - Windows 10 节点版本 - 14 LTS NPM 版本 - 6.14.10

解决方法

这个问题的答案非常简单。我的节点服务器已经在端口 3000 上运行。现在当我运行 npm test 时,chai-http 再次启动节点服务器看到这一行enter image description here

没有两个服务器可以在同一个端口上运行,所以我的节点进程在端口冲突时退出,它没有给我任何错误,为什么我的测试不起作用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?