cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Could not detect tests when including 'splitChunks: all' in webpack.config.js

Open paulthenightowl opened this issue 3 years ago • 3 comments

Current behavior

When Im using @cypress/webpack-preprocessor to preprosess the webpack.config.js file and include the option: splitChunks: all Cypress response with the message "Cypress could not detect tests in this file." after I run a basic test. The error only happens with splitChunks: all not splitChunks: async

image

Desired behavior

No response

Test code to reproduce

cypress/plugins/index.js

const webpackPreprocessor = require('@cypress/webpack-preprocessor')

module.exports = (on) => {
  const options = {
    webpackOptions: require('../../webpack.config'),
    watchOptions: {},
  }

  on('file:preprocessor', webpackPreprocessor(options))
}

root/webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: [/node_modules/],
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env'],
          },
        }],
      },
    ],
  },
  optimization: {
    splitChunks: {
        chunks: 'all'
    }
  },
}

cypress/integration/detail.spec.js:

/// <reference types="Cypress" />

describe("Test detail page", () => {
    before(() => {
        cy.visit("/")
    })

    it("Should open hamburger menu and select detail page", () => {
        cy.react('HamburgerMenu').should('exist');
        cy.get('.hamburgerMenu_root-3yVlk > .MuiButtonBase-root').click();
    })
})

Cypress Version

9.0.0

Other

No response

paulthenightowl avatar Nov 16 '21 10:11 paulthenightowl

Hm, I'm not able to reproduce, which doesn't mean it's not a real issue, just that here's more going on in your project than in my sample one.

Here's the project I spun up to test it out: split-chunks.zip using the exact plugins file and webpack config you provided - it recognizes the test as expected, regardless of splitChunks setting.

BlueWinds avatar Nov 17 '21 18:11 BlueWinds

Related to preprocessor + integration tests, not dev-server.

JessicaSachs avatar Mar 17 '22 23:03 JessicaSachs

I'm seeing a similar issue. When chunks: 'initial' or chunks: 'all' is set then Cypress can't find any of the custom cy commands like cy.login. It looks like cy.react in the example code above is also a custom command and this may be breaking it.

dpage-mdsol avatar Nov 22 '22 21:11 dpage-mdsol

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

cypress-app-bot avatar May 22 '23 19:05 cypress-app-bot

This issue has been closed due to inactivity.

cypress-app-bot avatar Jun 06 '23 02:06 cypress-app-bot