Skip to content

How to use this package with TypeScript files? #6

@krishnabrq

Description

@krishnabrq

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:

  • using coverageReporters: ['html']:
    Screenshot 2024-08-19 at 5 16 13 PM
  • using this package:
    Screenshot 2024-08-19 at 5 15 53 PM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions