Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit b5fcf70

Browse files
committed
move webpack clean up to find-webpack
1 parent 62ff7c5 commit b5fcf70

File tree

3 files changed

+11
-93
lines changed

3 files changed

+11
-93
lines changed

package-lock.json

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"@cypress/webpack-preprocessor": "4.1.3",
101101
"babel-plugin-istanbul": "6.0.0",
102102
"debug": "4.1.1",
103-
"find-webpack": "1.1.0"
103+
"find-webpack": "1.2.0"
104104
},
105105
"release": {
106106
"branches": [

plugins/cra-v3/file-preprocessor.js

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,6 @@ const debug = require('debug')('cypress-react-unit-test')
22
const findWebpack = require('find-webpack')
33
const webpack = require('@cypress/webpack-preprocessor')
44

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-
745
const getWebpackOptions = opts => {
756
debug('top level opts %o', opts)
767

@@ -83,19 +14,8 @@ const getWebpackOptions = opts => {
8314
}
8415
}
8516
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)
9919

10020
const options = {
10121
webpackOptions,

0 commit comments

Comments
 (0)