cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Webpack error when used within the Rushstack ecosystem #9710

Closed alfonsoar closed 1 year ago

alfonsoar commented 3 years ago

Issue:

When using this tool within the rushstack ecosystem we observe a webpack error when trying to run the unit tests. A couple of concepts tools to keep in mind are:

Rush (Monorepo tool) Heft (Build system, running TS) Rig package (Helps manage Heft build)

Example error:

Screen Shot 2020-12-08 at 9 06 14 PM

Reproduction Steps:

I have set up a fresh repository to showcase this issue https://github.com/alfonsoar/rushstack-cypress-react-unit-integration, please follow the README steps to set-up the repo and run the unit tests.

Only the component-1 package has cypress configured.

Link to cypress.json Link to webpack config. --> rush-rig Link to cypress plugin configuration Link to spec file

LeJeanbono commented 3 years ago

Webpack need a specific loader for tsx file, like ts-loader

alfonsoar commented 3 years ago

Thank you for the reply and for looking into this issue. So the main reason we don’t use ts-loader or babel-loader in our webpack config is because of the usage with heft. Heft actually the build system (the one orchestrating TS --> JS done by tsc) so this is why there is no need for these loaders. You can read a bit more about why they take this approach here. Do you have any ideas on if this is something we could support within cypress-react-unit-test or what we would need to do to support it?

dmtrKovalenko commented 3 years ago

It looks like webpack config path that you are passing here is not correct. It should point direct location of the webpack config to use

const preprocessor = require('cypress-react-unit-test/plugins/load-webpack')
module.exports = (on, config) => {

config.env.webpackFilename = 'rush-rig/library/webpack-shared.config.js'
  preprocessor(on, config)
  // IMPORTANT to return the config object
  return config
}
cypress-app-bot commented 1 year ago

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.