Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this package with TypeScript files? #6

Closed
krishnabrq opened this issue Aug 19, 2024 · 2 comments
Closed

How to use this package with TypeScript files? #6

krishnabrq opened this issue Aug 19, 2024 · 2 comments

Comments

@krishnabrq
Copy link

krishnabrq commented Aug 19, 2024

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
@cenfun
Copy link
Owner

cenfun commented Aug 19, 2024

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
Copy link
Author

krishnabrq commented Aug 19, 2024

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/"]
}

@cenfun cenfun closed this as completed Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants