index.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // in cypress/support/index.ts
  2. // load type definitions that come with Cypress module
  3. import path from 'path'
  4. const rootDir = path.resolve(__dirname, '..', '..', '..')
  5. import { devServer } from '@cypress/vite-dev-server'
  6. import coverage from '@cypress/code-coverage/task'
  7. import browserify from '@cypress/browserify-preprocessor'
  8. import createBundler from '@bahmutov/cypress-esbuild-preprocessor'
  9. import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor'
  10. import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild'
  11. const { default: viteConfig } = require(path.resolve(rootDir, 'vite.config.ts'))
  12. // need to use require for now as importing default throws a type error at runtime
  13. export const setupNodeEvents = async (
  14. on: Cypress.PluginEvents,
  15. config: Cypress.PluginConfigOptions
  16. ) => {
  17. const cucumberOptions = {
  18. ...browserify.defaultOptions,
  19. typescript: path.join(rootDir, 'node_modules/typescript')
  20. }
  21. coverage(on, config)
  22. // This is required for the preprocessor to be able to generate JSON reports after each run, and more,
  23. await addCucumberPreprocessorPlugin(on, { ...config, ...cucumberOptions })
  24. on(
  25. 'file:preprocessor',
  26. createBundler({
  27. plugins: [createEsbuildPlugin(config)]
  28. })
  29. )
  30. on('dev-server:start', (options: Cypress.DevServerConfig) => {
  31. return devServer({
  32. ...options,
  33. viteConfig: {
  34. ...viteConfig,
  35. // configFile: path.resolve(rootDir, 'vite.config.ts'),
  36. define: {
  37. 'process.env': process.env
  38. },
  39. optimizeDeps: {
  40. include: ['tailwind-merge'] // we need to include the tailwind-merge dependency otherwise the first run of the tests will fail
  41. }
  42. }
  43. })
  44. })
  45. return config
  46. }