rgc998
rgc998

Reputation: 331

Cypress code coverage with next.js, swc-plugin-coverage-instrument and cypress/code-coverage

My application is using next.js (v 14.1.0) and SWC to compile the code. Because I am not using babel, and I'm using SWC, instrumentation has been challenging to implement with cypress, but I am trying to do so using swc-plugin-coverage-instrument. I've installed that, as well as cypress/code-coverage. Here is what I have added in my cypress.config.ts

export default defineConfig({
 viewportWidth: 1440,
 viewportHeight: 660,
 component: {
   devServer: {
     framework: 'next',
     bundler: 'webpack',
     webpackConfig: {
       ...other stuff here
     },
   },
   setupNodeEvents: (on, config) => {
     require('@cypress/code-coverage/task')(on, config)
     return config
   },
 },
})

and here is my next.config.js

const nextConfig = {
  experimental: {
  swcPlugins: [
     ['swc-plugin-coverage-instrument', {}]
   ],
  instrumentationHook: isProduction,
 },
...
}

the only issue now is that when I run cypress I am seeing that every test is failing and this is the error I am seeing for every test. ERROR in ./src/__tests__/Molecules/Button.cy.tsx Module build failed (from ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js):Error: failed to process

not sure what could be causing this error. Any help would be appreciated.

Upvotes: 0

Views: 261

Answers (0)

Related Questions