|
| 1 | +const { startDevServer } = require("@cypress/webpack-dev-server"); |
| 2 | +const findReactScriptsWebpackConfig = require("@cypress/react/plugins/react-scripts/findReactScriptsWebpackConfig"); |
1 | 3 | const { |
2 | 4 | addVisualRegressionTrackerPlugin, |
3 | 5 | } = require("@visual-regression-tracker/agent-cypress/dist/plugin"); |
4 | | -const injectReactScriptsDevServer = require("@cypress/react/plugins/react-scripts"); |
5 | 6 |
|
6 | | -module.exports = async (on, config) => { |
7 | | - injectReactScriptsDevServer(on, config); |
| 7 | +/** |
| 8 | + * @type {Cypress.PluginConfig} |
| 9 | + */ |
| 10 | +module.exports = (on, config) => { |
| 11 | + const webpackConfig = findReactScriptsWebpackConfig(config); |
| 12 | + |
| 13 | + webpackConfig.resolve.fallback = { |
| 14 | + fs: false, |
| 15 | + }; |
| 16 | + |
| 17 | + // react component tests |
| 18 | + on("dev-server:start", async (options) => { |
| 19 | + return startDevServer({ |
| 20 | + options, |
| 21 | + webpackConfig, |
| 22 | + }); |
| 23 | + }); |
| 24 | + config.env.reactDevtools = true; |
| 25 | + |
| 26 | + // visual testing |
8 | 27 | addVisualRegressionTrackerPlugin(on, config); |
| 28 | + on("before:browser:launch", (browser, launchOptions) => { |
| 29 | + if (browser.name === "chrome" && browser.isHeadless) { |
| 30 | + launchOptions.args.push( |
| 31 | + `--window-size=${config.viewportWidth},${config.viewportHeight}` |
| 32 | + ); |
| 33 | + return launchOptions; |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + // IMPORTANT to return the config object |
| 38 | + // with the any changed environment variables |
9 | 39 | return config; |
10 | 40 | }; |
0 commit comments