节点打字稿项目中的玩笑覆盖率始终返回空

2023-12-22

我正在开发后端 Typescript 项目,我正在尝试获取单元测试用例的覆盖率报告。 Jest 在终端和 html 报告中返回空的覆盖率报告,没有说明任何内容。我也尝试过-- --coverage --watchAll=false但它也返回空文档。

包.json

"scripts":{
    "unit-test": "jest --config='./config/jest/jest_unit.config.js' --forceExit --detectOpenHandles",
}

jest_unit.config.js

/**
 * @file Jest Unit Test Configuration File
 */
module.exports = {
  roots: ['../../tests'],
  testRegex: '.*_unit.test.(js|ts|tsx)?$',
  globals: {
    'ts-jest': {
      tsConfig: 'tsconfig.json',
    },
  },
  moduleFileExtensions: ['ts', 'js'],
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
  },
  testEnvironment: 'node',
  reporters: [
    'default',
    [
      '../../node_modules/jest-html-reporter',
      {
        pageTitle: 'Unit Test Report',
        outputPath: 'tests/reports/unit-test-report.html',
        includeFailureMsg: true,
      },
    ],
  ],
  collectCoverage: true,
  collectCoverageFrom: [
    '../../api/**/*.ts'
  ],
  moduleFileExtensions: ["ts", "js", "json"],
  coverageDirectory: "../../coverage",
  coveragePathIgnorePatterns: [
    "<rootDir>/node_modules"
  ],
  coverageReporters: [
    "json",
    "lcov",
    "text"
  ],
  coverageThreshold: {
    "global": {
      "branches": 100,
      "functions": 100,
      "lines": 100,
      "statements": 100
    }
  },
};

文件夹结构

|-- app
    |-- controllers
    |-- schemas
|-- config
    |-- jest
        |-- jest_unit.config.js
|-- package.json
|-- tests
    |-- api
        |-- modules
            |-- m1
                |-- controllers
                    |-- m1_controller_unit.test.ts
                    |-- m1_controller_integration.test.ts
            |-- m2
                |-- models
                    |-- m1_model_unit.test.ts
                    |-- m1_model_integration.test.ts
            |-- m3
                |-- schemas
                    |-- m1_schema_unit.test.ts
                    |-- m1_schema_integration.test.ts

笑话报道htm 和终端显示没有覆盖线


我可以通过将配置文件移至根目录来解决此问题。在这个配置中一切都很好。我不知道为什么jest会有这样的行为。

更新结构

文件夹结构

|-- app
    |-- controllers
    |-- schemas
|-- jest_unit.config.js
|-- package.json
|-- tests
    |-- api
        |-- modules
            |-- m1
                |-- controllers
                    |-- m1_controller_unit.test.ts
                    |-- m1_controller_integration.test.ts
            |-- m2
                |-- models
                    |-- m1_model_unit.test.ts
                    |-- m1_model_integration.test.ts
            |-- m3
                |-- schemas
                    |-- m1_schema_unit.test.ts
                    |-- m1_schema_integration.test.ts

包.json

"scripts":{
    "unit-test": "jest --config='./jest_unit.config.js' --forceExit --detectOpenHandles",
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

节点打字稿项目中的玩笑覆盖率始终返回空 的相关文章

随机推荐