Cypress component testing with razzle #1633
Replies: 4 comments 1 reply
-
// webpack.config.js
const webpack = require('webpack');
const createConfig = require('razzle/config/createConfigAsync');
const loadRazzleConfig = require('razzle/config/loadRazzleConfig');
const setPorts = require('razzle-dev-utils/setPorts');
const configPromise = new Promise(function (resolve, reject) {
loadRazzleConfig(webpack)
.then(
async ({ razzle, razzleOptions, webpackObject, plugins, paths }) => {
verbose = razzleOptions.verbose;
if (!verbose) {
process.removeAllListeners('warning');
}
const clientOnly = true;
process.env.BUILD_TYPE = razzleOptions.buildType;
setPorts(clientOnly).then(async () => {
resolve(await createConfig(
'web',
'dev',
razzle,
webpackObject,
clientOnly,
paths,
plugins,
razzleOptions
));
})
})
});
module.exports = configPromise // usage
const webpack = require('@cypress/webpack-preprocessor')
const getConfig = require('webpack.config')
module.exports = (on) => {
return getConfig().then((webpackConfig) => {
on('file:preprocessor', webpack(webpackConfig))
})
} |
Beta Was this translation helpful? Give feedback.
-
Very good, thanks. This certainly gets the webpack config as required by cypress ct I just had to make a few modifications as follows to my setup (through trial and error, may not be optimal - it may be due to my config being pretty hacked up) Reason was 1) It says getConfig must return a function, 2) It says needs webpack needs to return a dev-server:start or something Don't know - but it's working so I'm not touching it webpack.config.js // prev:
// const configPromise = new Promise(function (resolve, reject) {
// new: (return func)
const configPromise = () => new Promise(function (resolve, reject) {
// ..
} plguins/index.ts const {startDevServer} = require("@cypress/webpack-dev-server")
// const webpack = require("@cypress/webpack-preprocessor")
const getConfig = require("../../webpack.config")
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
if (config.testingType === "component") {
on("dev-server:start", options => {
return getConfig().then(webpackConfig => {
return startDevServer({options, webpackConfig})
})
})
return config
}
// Doc [2021-06-20, Sun, 14:46]
//
// ELSE, NOT component testing, fire rest of plugins:
//
// mocha awesome
// db seed
// coverage
// babel plugins
// ....
|
Beta Was this translation helpful? Give feedback.
-
I also had to modify the code everyone else posted as of cypress 8.2.0 so I made a gist so I don't forget. (Thanks for the other code which helped a lot getting started) https://gist.github.com/SimeonC/72f9d0336556416692714689e27c59bb |
Beta Was this translation helpful? Give feedback.
-
Got any ideas on #1700 , E2E testing? |
Beta Was this translation helpful? Give feedback.
-
Has anyone managed to get cypress component testing working with razzle?
If so, what webpack config are you pointing plugins/index.ts/js to?
e.g. my best guess was (not working):
Beta Was this translation helpful? Give feedback.
All reactions