1

I have a react component library which is bundled using Rollup. I want to add cypress component testing so that I can unit test those components using cypress.
Cypress currently supports setting automatic configuration for React using either webpack' bundler or vite` bundler.

export default defineConfig({
  component: {
    devServer: {
      bundler: 'vite', // or it can be webpack
      framework:'react',
    }
  },

if we have anything apart from webpack or vite, we need to return custom-server instance from the devserver function as mentioned in the documentation

module.exports = defineConfig({
  component: {
    devServer(cypressConfig) {
      // return dev server instance or a promise that resolves to
      // a dev server instance here
    },
  },
})

I am not understanding how to return that devserver instance.

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73

1 Answers1

1

Function syntax:

import { devServer } from '@cypress/vite-dev-server'
import { defineConfig } from 'cypress'

export default defineConfig({
  component: {
    devServer(devServerConfig) {
      return devServer({
        ...devServerConfig,
        framework: 'react',
        viteConfig: require('./vite.config.js')
      })
    }
  }
})

https://github.com/cypress-io/cypress/tree/master/npm/vite-dev-server#readme