为什么 Node typescript 项目的 jasmine Karma 单元测试显示覆盖范围包括依赖项?

2024-05-04

正如题主所说,我们项目的代码覆盖率包括节点依赖。但请注意,当我们开发和发布它时,此 npm 依赖项的源代码也是项目的一部分。 这是该项目的结构:

  • root
    • main_project
      • 业力.conf.ts
      • src 和其他要测试并生成覆盖率的文件
      • test
    • side_project which is packaged and published to npm and used across multiple projects including this one
      • src etc.

So, even though my karma config is within the main_project(src and src/* in image) folder here, which I want to test and generate coverage for, karma includes the side_project(petreol-api-wrapper in the image) as well in the coverage, like this: screenshot of karma coverage

这是我的相关业力配置:

const testRecursivePath = "test/*Test.ts";
const srcOriginalRecursivePath = "src/**/*.ts";
frameworks: ["jasmine"],
reporters: [
    "progress",
    "junit",
    "coverage-istanbul"
],
files: [
    testRecursivePath,
    {
        pattern: srcOriginalRecursivePath,
        included: false,
        served: true
    }
],
preprocessors: {
    [testRecursivePath]: ["webpack", "coverage"]
},

有人可以帮我解决这个问题吗?


有一个选项可以排除文件karma.conf,例如,下面的配置将排除所有ts里面的文件node_modules文件夹。您可能需要使用我在下面的示例中提供的相对路径。您可以忽略所有使用**.*

exclude: [
        "node_modules/**/*.ts"
]

用作

const testRecursivePath = "test/*Test.ts";
const srcOriginalRecursivePath = "src/**/*.ts";
frameworks: ["jasmine"],
reporters: [
    "progress",
    "junit",
    "coverage-istanbul"
],
files: [
    testRecursivePath,
    {
        pattern: srcOriginalRecursivePath,
        included: false,
        served: true
    }
],
exclude: [
        "node_modules/**/*.ts"
]
preprocessors: {
    [testRecursivePath]: ["webpack", "coverage"]
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 Node typescript 项目的 jasmine Karma 单元测试显示覆盖范围包括依赖项? 的相关文章