sveltejs / svelte-loader

Webpack loader for svelte components.
MIT License
594 stars 73 forks source link

istanbul get wrong coverage for svelte file #210

Closed cheapCoder closed 1 year ago

cheapCoder commented 1 year ago

I am trying to get e2e test using playwright, and hope to get coverage using istanbul. The coverage report show the wrong coverage,and it not change when running extra test file.

window.__coverage__ in the console seems to show that the report is from code compiled from the svelte component.

image

I am wondering

// babel config
module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-typescript'],
  plugins: [
    [
      '@babel/plugin-transform-runtime',
      {
        corejs: 3,
        useESModules: true,
        version: '^7.18.3'
      }
    ]
  ],
  env: {
    development: {
      plugins: [
        [
          'istanbul',
          {
            exclude: ['**/tests/*.spec.ts', '**/src/components/index.ts'],
            // include: ['**/src/**/*.(ts|svelte)'],
            extension: ['.ts', '.svelte'],
            useInlineSourceMaps: false
          }
        ]
      ]
    }
  }
};
cheapCoder commented 1 year ago

By using @jsdevtools/coverage-istanbul-loader, I get the coverage for the js part of svelte component