aelbore / esbuild-jest

A Jest transformer using esbuild
519 stars 51 forks source link

istanbul ignore file is not working #76

Open Hideman85 opened 2 years ago

Hideman85 commented 2 years ago

I just switched from ts-jest to esbuild-jest and I have some files that should not be included in the coverage but are :thinking: My files have a /* istanbul ignore file */ first line comment and should be ignored. May I know if I miss a config somehow?

// jest.config.cjs
module.exports = {
  transform: {
    '^.+\\.ts$': [
      'esbuild-jest',
      {
        sourcemap: 'external'
      }
    ]
  },
  testEnvironment: 'node',
  collectCoverageFrom: [
    'src/**/*.{js,ts}',
    '!src/**/*.d.ts', //  Ignore types file
  ],
  coverageReporters: ['json', 'text', 'text-summary'],
  coverageThreshold: {
    global: {
      lines: 89,
      statements: 89,
    },
  },
};

EDIT: The reason is esbuild remove all comments https://github.com/evanw/esbuild/issues/516

gwsbhqt commented 1 year ago

@Hideman85 I have a similar problem, have you found a solution?

gwsbhqt commented 1 year ago

I solved this problem because the translation of esbuild removes redundant comments, causing the ignored comments to be deleted. There is such a solution in esbuild to force the retention of comments. E.g:

https://esbuild.github.io/api/#legal-comments

before: / istanbul ignore file /

after: / istanbul ignore file -- @preserve /