This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow loading webpack config by filename
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @ts-check | ||
const path = require('path') | ||
const debug = require('debug')('cypress-react-unit-test') | ||
const webpack = require('@cypress/webpack-preprocessor') | ||
const findWebpack = require('find-webpack') | ||
|
||
module.exports = (on, config) => { | ||
require('@cypress/code-coverage/task')(on, config) | ||
|
||
const webpackFilename = config.env && config.env.webpackFilename | ||
if (!webpackFilename) { | ||
throw new Error( | ||
'Could not find "webpackFilename" option in Cypress env variables %o', | ||
config.env, | ||
) | ||
} | ||
debug('got webpack config filename %s', webpackFilename) | ||
const resolved = path.resolve(webpackFilename) | ||
debug('resolved webpack at %s', webpackFilename) | ||
const webpackOptions = require(resolved) | ||
|
||
debug('webpack options: %o', webpackOptions) | ||
|
||
const coverageIsDisabled = | ||
config && config.env && config.env.coverage === false | ||
debug('coverage is disabled? %o', { coverageIsDisabled }) | ||
|
||
const opts = { | ||
coverage: !coverageIsDisabled, | ||
} | ||
|
||
findWebpack.cleanForCypress(opts, webpackOptions) | ||
debug('claned webpack options: %o', webpackOptions) | ||
|
||
const options = { | ||
webpackOptions, | ||
watchOptions: {}, | ||
} | ||
|
||
on('file:preprocessor', webpack(options)) | ||
|
||
// IMPORTANT to return the config object | ||
// with the any changed environment variables | ||
return config | ||
} |