Files
cypress/npm/react/plugins/load-webpack/index.js
Dmitriy Kovalenko 9c642369fc chore(component-testing): Remove useless code & deps in @cypress/react and @cypress/vue (#15113)
* Remove useless code

* Add code-coverage to reacr devDependencies

* Remove react/support imports

* Remove some useless code from @cypress/react

* Cleanup vue

* Make it works :)

* Fix react errors

* Fix next.js react example

Co-authored-by: Lachlan Miller <lachlan.miller.1990@outlook.com>
Co-authored-by: Barthélémy Ledoux <bart@cypress.io>
2021-02-19 14:58:40 -06:00

60 lines
1.7 KiB
JavaScript

// @ts-check
const path = require('path')
const debug = require('debug')('@cypress/react')
const webpackPreprocessor = require('@cypress/webpack-preprocessor')
const findWebpack = require('find-webpack')
const { getTranspileFolders } = require('../utils/get-transpile-folders')
const { addImageRedirect } = require('../utils/add-image-redirect')
module.exports = (on, config) => {
const webpackFilename = config.env && config.env.webpackFilename
if (!webpackFilename) {
throw new Error(
'Could not find "webpackFilename" option in Cypress env variables',
)
}
debug('got webpack config filename %s', webpackFilename)
const resolved = path.resolve(webpackFilename)
debug('resolved webpack at %s', resolved)
const webpackOptions = findWebpack.tryLoadingWebpackConfig(resolved)
if (!webpackOptions) {
throw new Error(`Could not load webpack config from ${resolved}`)
}
debug('webpack options: %o', webpackOptions)
const coverageIsDisabled =
config && config.env && config.env.coverage === false
debug('coverage is disabled? %o', { coverageIsDisabled })
const opts = {
reactScripts: true,
addFolderToTranspile: getTranspileFolders(config),
coverage: !coverageIsDisabled,
// insert Babel plugin to mock named imports
looseModules: true,
}
findWebpack.cleanForCypress(opts, webpackOptions)
debug('cleaned webpack options: %o', webpackOptions)
addImageRedirect(webpackOptions)
const options = {
webpackOptions,
watchOptions: {},
}
on('file:preprocessor', webpackPreprocessor(options))
// IMPORTANT to return the config object
// with the any changed environment variables
return config
}