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

Cannot generate a coverage report #65

Closed
leonardparisi opened this issue Jan 8, 2022 · 4 comments
Closed

Cannot generate a coverage report #65

leonardparisi opened this issue Jan 8, 2022 · 4 comments

Comments

@leonardparisi
Copy link

I don't know if this is an issue specifically with @swc/jest, but I tried the suggestions in this StackOverflow question and they made no difference. Here is my jest.config.js:

module.exports = {
  'roots': ['<rootDir>/../src'],
  'moduleDirectories': ['node_modules', 'src'],
  'setupFilesAfterEnv': ['<rootDir>/setup-tests.js'],
  'coverageDirectory': '<rootDir>/../coverage',
  'verbose': true,
  'collectCoverage': true,
  'transform': {
    '^.+\\.(t|j)sx?$': [
      '@swc/jest',
      {
        'jsc': {
          target: 'es2021',
        },
        'sourceMaps': true,
      },
    ],
  },
  'collectCoverageFrom': [
    '<rootDir>/../src/**.{ts,js,tsx,jsx}',
    '!**/node_modules/**',
  ],
}

My file structure looks like:

.
├── coverage
├── jest
   ├── jest.config.js
   ├── setup-tests.js
├── src/
├── tsconfig.json

The output looks like this:

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------

Test Suites: 11 passed, 11 total
Tests:       25 passed, 25 total
Snapshots:   0 total
Time:        1.307 s
Ran all test suites.
@kdy1
Copy link
Member

kdy1 commented Jan 12, 2022

I think it can be a problem of a sourcemap.

@kdy1
Copy link
Member

kdy1 commented Feb 3, 2022

I think it may work if you remove sourceMaps: true. Can you try it?

@kalvin807
Copy link

kalvin807 commented Feb 8, 2022

I was having a similar problem,
I think the fix is you need a collectCoverageFrom glob like this

  collectCoverageFrom: [
    "src/**/*.{ts,js,tsx,jsx}",
    "!**/node_modules/",
  ],

yours is **.{ts...} while it should be single asterisk **/*.{ts...} < recurive each folder and each file that matches the extensions list in src folder.

Or is it due to some internal difference between swc generated file and ts-jest generated file?

@kdy1
Copy link
Member

kdy1 commented Feb 24, 2022

Closing as duplicate of swc-project/swc#3854

@kdy1 kdy1 closed this as completed Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants