node.js - 未找到摩卡测试:“0 通过”
问题描述
我不知道为什么测试运行器不会检测到我的测试。
npm test
myproject@1.0.0 test C:\Users\sjsui\Desktop\git_workshop\myproject
mocha ./built/source
0 passing (4ms)
PS C:\Users\sjsui\Desktop\git_workshop\myproject>
我知道这test
是 mocha 搜索的默认文件夹,这就是我构建项目的方式。
built
\--source
\--test
\--test.js
这是我的 test.js 文件
describe("consumer tests", function()
{
it("runs bad request tests", (done) => {
let tests = new badrequesttests()
iteratebadtests(tests, done)
})
it("normal consumer tests", (done) => {
let tests = new normaltests()
iteratenormaltests(tests, done)
})
it("abnormal consumer tests", (done) => {
let tests = new unauthorizedtests()
iterateunauthorizedtests(tests, done)
})
})
package.json 中的 npm 脚本部分
"scripts": {
"test": "mocha ./built/source"
},
作为旁注,断点不会在测试中命中(visual studio代码调试任务-> mocha)
解决方案
我认为您的测试脚本未检测到 y mocha,因为默认情况下 mocha 不会扫描子目录,并且您的测试位于您在调用 mocha 时传递的路径的子目录中。有两种方法可以解决这个问题。
将测试文件夹的路径提供给 mocha,如下所示
mocha ./built/source/test
使用递归标志触发 mocha 测试。使用此标志 mocha 将扫描您提供的路径的子目录
mocha ./built/source --recursive
我认为这应该可以解决您的问题
推荐阅读
- java - 按意图传递 firebase 数据会导致 java.lang.IllegalArgumentException
- react-native - 如何清除 React-Native 中的 AsyncStorage?
- javascript - 无法在 fcm 中对通知进行分组
- sql - SQL Server如何提动态列值不应该为空
- linux - 无论使用的存储驱动程序如何,都可以获得 docker 容器的 rootfs 吗?
- c++ - 链接到 c++ 库时出现意外的符号解析
- shell - 如何在 bash 上捕获状态以获取 shell 脚本输出结果
- spring - 增加和减少按钮怎么做?
- laravel - 带有关系模型的 Laravel 策略
- maven - 具有完整 jar 名称的 Maven 复制依赖项