|
1 | 1 | const debug = require('debug')('cypress-react-unit-test')
|
2 |
| -const path = require('path') |
3 |
| -const findYarnWorkspaceRoot = require('find-yarn-workspace-root') |
| 2 | +const findWebpack = require('find-webpack') |
4 | 3 | const webpack = require('@cypress/webpack-preprocessor')
|
5 | 4 |
|
6 |
| -const webpackConfigPath = path.resolve( |
7 |
| - findYarnWorkspaceRoot() || process.cwd(), |
8 |
| - 'node_modules', |
9 |
| - 'react-scripts', |
10 |
| - 'config', |
11 |
| - 'webpack.config.js', |
12 |
| -) |
13 |
| - |
14 |
| -debug('path to react-scripts own webpack.config.js: %s', webpackConfigPath) |
15 |
| - |
16 |
| -// Do this as the first thing so that any code reading it knows the right env. |
17 |
| -process.env.BABEL_ENV = 'development' |
18 |
| -process.env.NODE_ENV = 'development' |
19 |
| - |
20 | 5 | // note: modifies the argument object in place
|
21 | 6 | const addCypressToEslintRules = webpackOptions => {
|
22 | 7 | if (webpackOptions.module && Array.isArray(webpackOptions.module.rules)) {
|
@@ -89,8 +74,14 @@ const addCodeCoverage = webpackOptions => {
|
89 | 74 | const getWebpackOptions = opts => {
|
90 | 75 | debug('top level opts %o', opts)
|
91 | 76 |
|
92 |
| - const webpackFactory = require(webpackConfigPath) |
93 |
| - const webpackOptions = webpackFactory('development') |
| 77 | + const webpackOptions = findWebpack.getWebpackOptions() |
| 78 | + if (!webpackOptions) { |
| 79 | + console.error('⚠️ Could not find Webpack options, using defaults') |
| 80 | + return { |
| 81 | + webpackOptions: webpack.defaultOptions, |
| 82 | + watchOptions: {}, |
| 83 | + } |
| 84 | + } |
94 | 85 | debug('webpack options: %o', webpackOptions)
|
95 | 86 |
|
96 | 87 | // remove bunch of options, we just need to bundle spec files
|
|
0 commit comments