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

Mocha test fails without giving proper error

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

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

我也手动尝试了 运行ning 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 ]

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

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

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