This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
file-preprocessor.js
64 lines (53 loc) · 1.95 KB
/
file-preprocessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// @ts-check
const debug = require('debug')('cypress-react-unit-test')
const findWebpack = require('find-webpack')
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
const { addImageRedirect } = require('../utils/add-image-redirect')
const getWebpackPreprocessorOptions = opts => {
debug('top level opts %o', opts)
const webpackOptions = findWebpack.getWebpackOptions()
if (!webpackOptions) {
console.error('⚠️ Could not find Webpack options, using defaults')
return webpackPreprocessor.defaultOptions
}
debug('webpack options: %o', webpackOptions)
findWebpack.cleanForCypress(opts, webpackOptions)
debug('cleaned webpack options: %o', webpackOptions)
addImageRedirect(webpackOptions)
const options = {
webpackOptions,
watchOptions: {},
}
return options
}
module.exports = config => {
debug('env object %o', config.env)
const coverageIsDisabled =
config && config.env && config.env.coverage === false
debug('coverage is disabled? %o', { coverageIsDisabled })
debug('component test folder: %s', config.componentFolder)
debug('fixtures folder', config.fixturesFolder)
debug('integration test folder: %s', config.integrationFolder)
const additionalFolders = []
// user can disable folders, so check first
if (config.componentFolder) {
additionalFolders.push(config.componentFolder)
}
if (config.fixturesFolder) {
additionalFolders.push(config.fixturesFolder)
}
if (config.integrationFolder) {
additionalFolders.push(config.integrationFolder)
}
debug('additional folders: %o', additionalFolders)
const opts = {
reactScripts: true,
addFolderToTranspile: additionalFolders,
coverage: !coverageIsDisabled,
// insert Babel plugin to mock named imports
looseModules: true,
}
const preprocessorOptions = getWebpackPreprocessorOptions(opts)
debug('final webpack options %o', preprocessorOptions.webpackOptions)
return webpackPreprocessor(preprocessorOptions)
}