Express 当有多个套件时,不要显示测试

Express 当有多个套件时,不要显示测试,express,testing,jestjs,command-line-interface,tdd,Express,Testing,Jestjs,Command Line Interface,Tdd,我正在测试我的应用程序。 当我运行“npm测试”时,我希望在终端中看到所有测试。 我有一个名为auth.test.js的文件和所有测试 所以我运行npm测试时的输出是: > jest --forceExit PASS src/test/auth.test.js /LOGIN testing ✓ Should not login a unexistent username. (22ms) ✓ Should not login with incorrect crede

我正在测试我的应用程序。 当我运行“npm测试”时,我希望在终端中看到所有测试。 我有一个名为auth.test.js的文件和所有测试

所以我运行npm测试时的输出是:

> jest --forceExit

 PASS  src/test/auth.test.js
  /LOGIN testing
    ✓ Should not login a unexistent username. (22ms)
    ✓ Should not login with incorrect credentials. (63ms)
    ✓ Should not login with empty fields. (2ms)
    ✓ Should login a moked user. (67ms)
  /SIGNUP testing
    ✓ Should not sign up a new user with invalid password. (3ms)
    ✓ Should not sign up a new user with invalid username. (2ms)
    ✓ Should sign up a new user. (72ms)
    ✓ Should not sign up a existing user. (4ms)
    ✓ Should not sign up with empty fields. (3ms)

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total
Snapshots:   0 total
Time:        1.114s, estimated 2s
Ran all test suites.
那很好。我可以看到所有测试的细节

现在,我想添加一个包含测试的新文件,名为api.tests.js

然后,当我运行“npm测试”时,我看到以下输出:

> jest --forceExit

 PASS  src/test/api.test.js
 PASS  src/test/auth.test.js

Test Suites: 2 passed, 2 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        1.589s, estimated 2s
Ran all test suites.
在阅读jest文档(cli文章)之后,我找不到如何查看详细信息,就像我在测试一个文件时看到的一样,但是在测试多个文件时看到的一样


可能吗?如何操作?

您需要在
jest.config.js
文件中修改的配置

Jest用来检测测试文件的glob模式。默认情况下,它会在tests文件夹中查找.js、.jsx、.ts和.tsx文件,以及后缀为.test或.spec的任何文件(例如Component.test.js或Component.spec.js)。它还会找到名为test.js或spec.js的文件

您的新测试文件名为
api.tests.js
,因此需要添加一个glob模式

”***/?(*)+(规范测试)。[jt]s?(x)
进入
testMatch
配置

例如,
jest.config.js

module.exports={
预设:“ts笑话”,
测试环境:“酶”,
setupFilesAfterEnv:['jest-Ezyme'],
测试环境选项:{
酶适配器:“反应16”
},
coverageReporters:['json','text','lcov','clover'],
testMatch:['**/\\\\\\\\\\\/*.[jt]s?(x)'**/?(*)+(规范测试)。[jt]s?(x)'**/?(*)+(规范测试)。[jt]s?(x)]
};
单元测试结果:

☁  笑话代码实验室[大师]⚡  净现值
>开玩笑-codelab@1.0.0test/Users/ldu020/workspace/github.com/mrdulin/jest-codelab
>开玩笑——侦探本汉德斯
通过src/stackoverflow/58663681/api.tests.js
✓ t1(4ms)
测试套件:1个通过,共1个
测试:1项通过,共1项
快照:共0个
时间:3.883s
运行所有测试套件。

?不,这是另一种信息,但不是我粘贴的测试细节。在这种情况下,OP可能在测试文件的名称中有输入错误。但在我的例子中,我有一个文件夹tests,其中有两个文件,routes.test.js和api.test.js。正如OP所说的,如果我只运行其中一个文件,通过删除另一个文件,我将获得该文件中每个测试的状态。但是,如果我有这两个测试,我只会在文件名之前获得一个大字母的通过状态,但每个测试的状态都不会显示。--verbose为我工作