cenfun / jest-monocart-coverage

A Jest custom reporter for monocart coverage reports
MIT License
3 stars 1 forks source link

How to use this package with TypeScript files? #6

Closed krishnabrq closed 3 weeks ago

krishnabrq commented 3 weeks ago

I am having a TypeScript project, with following jest.config.mjs:

/** @type {import('ts-jest').JestConfigWithTsJest} */

export default {
  testEnvironment: 'node',
  detectOpenHandles: true,
  verbose: true,
  cache: true,
  bail: 1,
  rootDir: '.',
  roots: ['<rootDir>/'],
  testMatch: ['<rootDir>/src/_tests/**/*.(spec|test).ts'],
  testPathIgnorePatterns: ['<rootDir>/node_modules/'],
  collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
  coverageDirectory: '<rootDir>/coverage/',
  coverageReporters: ['none'],
  reporters: [
    'default',
    [
      'jest-monocart-coverage',
      {
        reports: [['html'], ['cobertura'], ['console-details']],
        outputDir: './coverage',
      },
    ],
    [
      'jest-junit',
      {
        outputDirectory: '<rootDir>/coverage/',
        outputName: 'junit.xml',
        suiteName: 'Tests',
        classNameTemplate: '{classname}',
        ancestorSeparator: ' > ',
      },
    ],
  ],
  transform: {
    '^.+.tsx?$': ['ts-jest', {}],
  },
  transformIgnorePatterns: ['node_modules'],
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  coverageProvider: 'v8',
  passWithNoTests: true,
  forceExit: true,
};

When I am running the tests with jest --coverage, the file contents are compiled JS, not TS. How can I have them as actual TS content?

Example:

cenfun commented 3 weeks ago

It seems that it failed to load sourcemap files. try debug to show error details

[
      'jest-monocart-coverage',
      {
        reports: [['html'], ['cobertura'], ['console-details']],
        logging: "debug",
        outputDir: './coverage',
      },
    ],

Or provide a minimal reproduction repo.

krishnabrq commented 3 weeks ago

Thanks for pointing out the issue. Changing the following in tsconfig.json worked for me:

{
  "compilerOptions": {
    ...
-    "sourceMap": false,
-    "inlineSourceMap": true,
+    "sourceMap": true,
+    "inlineSourceMap": false,
    ...
  },
  "include": ["src/", "lib/"],
  "exclude": ["node_modules/", "build/"]
}