@@ -2,75 +2,6 @@ const debug = require('debug')('cypress-react-unit-test')
2
2
const findWebpack = require ( 'find-webpack' )
3
3
const webpack = require ( '@cypress/webpack-preprocessor' )
4
4
5
- // note: modifies the argument object in place
6
- const addCypressToEslintRules = webpackOptions => {
7
- if ( webpackOptions . module && Array . isArray ( webpackOptions . module . rules ) ) {
8
- const modulePre = webpackOptions . module . rules . find (
9
- rule => rule . enforce === 'pre' ,
10
- )
11
- if ( modulePre && Array . isArray ( modulePre . use ) ) {
12
- debug ( 'found Pre block %o' , modulePre )
13
-
14
- const useEslintLoader = modulePre . use . find (
15
- use => use . loader && use . loader . includes ( 'eslint-loader' ) ,
16
- )
17
- if ( useEslintLoader ) {
18
- debug ( 'found useEslintLoader %o' , useEslintLoader )
19
-
20
- if ( useEslintLoader . options ) {
21
- if ( Array . isArray ( useEslintLoader . options . globals ) ) {
22
- debug (
23
- 'adding cy to existing globals %o' ,
24
- useEslintLoader . options . globals ,
25
- )
26
- useEslintLoader . options . globals . push ( 'cy' )
27
- useEslintLoader . options . globals . push ( 'Cypress' )
28
- } else {
29
- debug ( 'setting new list of globals with cy and Cypress' )
30
- useEslintLoader . options . globals = [ 'cy' , 'Cypress' ]
31
- }
32
- }
33
- }
34
- }
35
- }
36
- }
37
-
38
- // note: modifies the argument object in place
39
- const addCodeCoverage = webpackOptions => {
40
- debug ( 'trying to add code instrumentation plugin' )
41
- if ( ! webpackOptions ) {
42
- return
43
- }
44
- if ( ! webpackOptions . module ) {
45
- return
46
- }
47
- debug ( 'webpackOptions.module %o' , webpackOptions . module )
48
- if ( ! Array . isArray ( webpackOptions . module . rules ) ) {
49
- return
50
- }
51
- const oneOfRule = webpackOptions . module . rules . find ( rule =>
52
- Array . isArray ( rule . oneOf ) ,
53
- )
54
- if ( ! oneOfRule ) {
55
- return
56
- }
57
- const babelRule = oneOfRule . oneOf . find (
58
- rule => rule . loader && rule . loader . includes ( '/babel-loader/' ) ,
59
- )
60
- if ( ! babelRule ) {
61
- return
62
- }
63
- debug ( 'babel rule %o' , babelRule )
64
- if ( ! babelRule . options ) {
65
- return
66
- }
67
- if ( ! Array . isArray ( babelRule . options . plugins ) ) {
68
- return
69
- }
70
- babelRule . options . plugins . push ( 'babel-plugin-istanbul' )
71
- debug ( 'added babel-plugin-istanbul' )
72
- }
73
-
74
5
const getWebpackOptions = opts => {
75
6
debug ( 'top level opts %o' , opts )
76
7
@@ -83,19 +14,8 @@ const getWebpackOptions = opts => {
83
14
}
84
15
}
85
16
debug ( 'webpack options: %o' , webpackOptions )
86
-
87
- // remove bunch of options, we just need to bundle spec files
88
- delete webpackOptions . optimization
89
- delete webpackOptions . plugins
90
-
91
- // ESLint loader does not know about our "cy" global so it will error
92
- // find it in the module processing rules and add global "cy" option
93
- debug ( 'module property %o' , webpackOptions . module )
94
-
95
- addCypressToEslintRules ( webpackOptions )
96
- if ( opts . coverage ) {
97
- addCodeCoverage ( webpackOptions )
98
- }
17
+ findWebpack . cleanForCypress ( opts , webpackOptions )
18
+ debug ( 'claned webpack options: %o' , webpackOptions )
99
19
100
20
const options = {
101
21
webpackOptions,
0 commit comments