web icon indicating copy to clipboard operation
web copied to clipboard

Exclude Files in Coverage Config

Open mjaworski-eab opened this issue 3 years ago • 4 comments

There seems to be some issue with coverageConfig.exclude. It is part of the finalConfig which is passed out of parseConfig.js, but does not seem to exclude files from the coverage report (reporter: json).

If I provide this configuration, I still get files in __wds-outside-root__ in my coverage report.

export default ({
  nodeResolve: true,
  coverageConfig: {
    report: true,
    reportDir: 'coverage',
    exclude: ['**/node_modules/**/*', '**/web_modules/**/*', '**/__wds-outside-root__/**/*'],
    reporters: ['text-summary', 'json-summary']
  }
});

We have many components and want to collect coverage on each independently.

mjaworski-eab avatar Apr 18 '21 23:04 mjaworski-eab

I did some debugging and I see that __wds-outside-root__ is properly excluded. Do you have some reproduction we could look at?

LarsDenBakker avatar Apr 23 '21 12:04 LarsDenBakker

I'm having the same issue. How do you exclude node_modules from the coverage output?

Ive tried multiple variants of excluding node_modules from the config. The below is a kitchen sink approach that also doesn't work...

export default {
  rootDir: '.',
  nodeResolve: true,
  files: [
    'src/**/*.test.ts',
    '!node_modules/**/*',
    '!**/node_modules/**/*'
  ],
  coverage: true,
  coverageConfig: {
    report: true,
    reportDir: 'coverage',
    exclude: [
      'node_modules/**/*',
      '**/node_modules/**/*',
      'web_modules/**/*',
      '**/web_modules/**/*',
      '**/__wds-outside-root__/**/*'
    ],
  }
}

Pickra avatar Sep 16 '22 16:09 Pickra

I use '**/node_modules/**',...

Westbrook avatar Sep 16 '22 23:09 Westbrook

Thanks @Westbrook . Tried that too, i must have something else wrong.

Pickra avatar Sep 17 '22 00:09 Pickra

I had the same problem and randomly found a solution:

coverageConfig: {
  include: ['**']
}

dominikfryc avatar Apr 18 '23 22:04 dominikfryc

Any luck from this?

My web-test-runner.config.js is:

const { esbuildPlugin } = require('@web/dev-server-esbuild');

module.exports = {
  files: [
    './src/**/*.test.ts',
    '!**/node_modules/**/*',
  ],
  nodeResolve: true,
  coverage: true,
  coverageConfig: {
    exclude: [
      'node_modules/**',
      '**/node_modules/**',
    ],
  },
  plugins: [
    esbuildPlugin({ ts: true }),
  ],
};

I still see node_modules/.pnpm/@open-wc+testing at coverage/lcov-report/index.html.


Already resolved,

I modified my config to include @dominikfryc suggestion, as follow:

const { esbuildPlugin } = require('@web/dev-server-esbuild');

module.exports = {
  files: [
    './src/**/*.test.ts',
  ],
  nodeResolve: true,
  coverage: true,
  coverageConfig: {
    include: ['**'],
    exclude: ['**/node_modules/**'],
  },
  plugins: [
    esbuildPlugin({ ts: true }),
  ],
};

And it works, now I only see my src files.

reekoheek avatar May 11 '23 10:05 reekoheek