https://cypress.io logo
#help
Title
# help
r

rich-lamp-44536

02/10/2022, 11:11 AM
How can I get
@cypress/code-coverage/support
to work? I tried everything now and no matter what I do, no coverage report will be created anywhere 🤔
cypress/plugins/index.ts
Copy code
ts
import codeCoverageTask from '@cypress/code-coverage/task';
import { startDevServer } from '@cypress/vite-dev-server';
import path from 'node:path';

export default (
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions,
): void | Cypress.ConfigOptions | Promise<Cypress.ConfigOptions> => {
  on('dev-server:start', async (options) => {
    return startDevServer({
      options,
      viteConfig: {
        configFile: path.resolve(__dirname, '..', '..', 'vite.config.ts'),
      },
    });
  });

  codeCoverageTask(on, config);

  return config;
};
cypress/support/index.ts
Copy code
ts
import '@cypress/code-coverage/support';
import './commands';
vite.config.ts
Copy code
ts
/// <reference types="vitest" />
import content from '@originjs/vite-plugin-content';
import { quasar, transformAssetUrls } from '@quasar/vite-plugin';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'node:path';
import type { PluginOption } from 'vite';
import { defineConfig } from 'vite';
import istanbul from 'vite-plugin-istanbul';

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const plugins: PluginOption[] = [
    vue({
      template: { transformAssetUrls },
    }),
    quasar({
      autoImportComponentCase: 'pascal',
      sassVariables: 'src/quasar-variables.scss',
    }),
    content(),
  ];

  console.log('command:', command);
  console.log('mode:', mode);
  // if (command === 'serve' && mode === 'development') {
  console.info('Adding istanbul plugin');
  plugins.push(
    istanbul({
      include: 'src/*',
      exclude: ['node_modules', 'cypress/', 'test/'],
      extension: ['.ts', '.vue'],
      cypress: true,
      forceBuildInstrument: true,
    }),
  );
  // }

  return {
    plugins,
    test: {
      environment: 'happy-dom',
      coverage: {
        reporter: ['cobertura', 'html', 'text'],
        all: true,
        include: ['src/**/*.{ts,vue}'],
        exclude: ['src/**/*.d.ts', 'src/**/*.spec.ct.ts'],
      },
      reporters: ['default', 'junit'],
      outputFile: 'junit.xml',
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src'),
      },
    },
    css: {
      postcss: {
        plugins: [
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset(atRule) {
                if (atRule.name === 'charset') {
                  atRule.remove();
                }
              },
            },
          },
        ],
      },
    },
    server: {
      port: 5173,
    },
    preview: {
      port: 4173,
    },
  };
});
@User not, sure but maybe you have some knowledge about this?
s

stocky-dream-36427

02/10/2022, 9:27 PM
Morning.
Component Testing + Code Cov is untested for Vite.
We need help fixing it.
It's one of the things that's broken/never build for the Alpha.
r

rich-lamp-44536

02/10/2022, 9:29 PM
👍
yeah, feels like it
s

stocky-dream-36427

02/10/2022, 9:29 PM
If you know how to do it, it would be amazing.
r

rich-lamp-44536

02/10/2022, 9:29 PM
okay, at least I know now whats going on
s

stocky-dream-36427

02/10/2022, 9:29 PM
I think webpack works fine (I think)
But I don't know how to add it to Vite easily
This is for a diff project -- not faker, yes?
r

rich-lamp-44536

02/10/2022, 9:30 PM
yeah it's for company work
s

stocky-dream-36427

02/10/2022, 9:30 PM
(Just double checking)
yeah
This would be really helpful for the community if you could help figure it out.
I can tell you the general structure of how the code coverage plugin works.
r

rich-lamp-44536

02/10/2022, 9:31 PM
yeah, currently I'm watching just some gh issues and focus on other stuff
s

stocky-dream-36427

02/10/2022, 9:31 PM
👍 totally.
DM if you're ever interested in picking it up.
I think we're looking at 4-6 weeks before I can look at it?
But we'll see.
If it's important to you I will try to fix it.
r

rich-lamp-44536

02/10/2022, 9:32 PM
not important at all
s

stocky-dream-36427

02/10/2022, 9:32 PM
kk
r

rich-lamp-44536

02/10/2022, 9:32 PM
totally a nice to have
prio like hell 😛
m

mysterious-area-98742

02/11/2022, 8:05 AM
If you open some publically-tracked issue (e.g. Github) let me know
I'd like to track this
r

rich-lamp-44536

02/11/2022, 8:31 AM
I did not create an issue in cypress right now, cause I'm assuming that I configured something wrongly and/or my Cypress+Vite+Vue3+TS setup is to strong
m

mysterious-area-98742

02/11/2022, 8:33 AM
Thanks 😄
Make sure to update the issue above and/or @mention me if you do something new
3 Views