笑话报道找不到文件

问题描述 投票:0回答:0

我在玩笑报道记者时遇到了一些问题。我有一个包含 2 个项目、应用程序和测试项目的 .NET 解决方案。我的 src 打字稿文件在应用程序项目中,我的测试打字稿文件在测试项目中。设置项目时,它不会收集 src 文件的代码覆盖率,也根本找不到文件。

错误

PASS  TestScripts/ConfigHelper.test.ts
ConfigHelper
  √ Initialise returns a ConfigHelper (11 ms)
  √ Get Config returns correct config (2 ms)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 | 
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        13.262 s
Ran all test suites.

项目结构

Project/
├─ Content/
│  ├─ Src/
│  │  ├─ Scripts/
│  │  │  ├─ Helpers/
│  │  │  │  ├─ ConfigHelper.ts
├─ package.json
TestProject/
├─ TestScripts/
│  ├─ ConfigHelper.test.ts
├─ package.json

jest.config.ts

export default {
  roots: [
      "../TestProject/TestScripts",
      "../Project/Content/Src/Scripts/",
  ],
  testMatch: [
      "**/__tests__/**/*.+(ts|tsx|js)",
      "**/?(*.)+(spec|test).+(ts|tsx|js)",
  ],
  transform: {
      "^.+\\.(ts|tsx)$": "ts-jest",
  },
  collectCoverage: true,
  collectCoverageFrom: ["./../Project/Content/Src/Scripts/**/*.ts"],
  clearMocks: true,
  coverageDirectory: "coverage",
  coverageProvider: "babel",
  preset: "ts-jest",
  testEnvironment: "node",
};

Package.json

{
  "name": "project",
  "version": "1.0.0",
  "description": "project",
  "scripts": {
      "lint": "eslint . --ext .ts",
      "format": "prettier --write .",
      "test": "jest --config ./jest.config.ts --coverage --colors"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
      "@jest/globals": "^29.5.0",
      "@types/jest": "^29.4.0",
      "@typescript-eslint/eslint-plugin": "^5.53.0",
      "@typescript-eslint/parser": "^5.53.0",
      "eslint": "^8.34.0",
      "eslint-config-prettier": "^8.6.0",
      "jest": "^29.4.2",
      "jest-editor-support": "^31.0.1",
      "jest-fetch-mock": "^3.0.3",
      "prettier": "^2.8.4",
      "ts-jest": "^29.0.5",
      "ts-node": "^10.9.1",
      "typescript": "^4.9.5"
  }
}
javascript typescript jestjs ts-jest babel-jest
© www.soinside.com 2019 - 2024. All rights reserved.