-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat: allow usage of @react/plugins with cypress.config.js #17738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for taking the time to open a PR!
|
Test summaryRun details
View run in Cypress Dashboard ➡️ Flakiness
This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are mostly about consistency. We have the following dev servers:
- @cypress/webpack-dev-server
- @cypress/vite-dev-server
- @cypress/react/plugins/babel
- @cypress/react/plugins/craco
- @cypress/react/plugins/load-webpack
- @cypress/react/plugins/next
- @cypress/react/plugins/react-scripts
I think this PR should ensure:
- all dev server function signatures are both backwards- and forwards-compatible in the same way, with signatures as-defined in the notion document
- all dev server modules export their functions consistently
- all the examples refer to the dev servers consistently
// New CT plugin signature: setupDevServer(options) | ||
const [options, additionalOptions] = args | ||
|
||
return devServer(options, additionalOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to have a postProcessConfig
we also need to call it with the setupDevServer(options)
signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot postProcess the config in this case, can we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed with Jessica, I don't think this should be part of the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a followup issue to address this? I want to make sure these dev server modules behave consistently when used with the new signature. /cc @JessicaSachs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming aside, I did a QA locally and it seems to function correctly. I checked this out, then merged in #17000, fixed conflicts, ran yarn
and then did yarn cy:open
in npm/react
and it functions as expected. Anything else I should look at?
I'll approve this for now, but we should definitely resolve @cowboy's comments before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the names to be consistent.
I've been through the code for the following dev server modules:
All the dev server modules in this PR follow the pattern outlined in the notion doc, which I have duplicated here: // no additionalOptions
function setupDevServer(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): void
function setupDevServer(options: Cypress.DevServerOptions): Cypress.ResolvedDevServerConfig
// optional additionalOptions
function setupDevServer(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, additionalOptions?: TBDType): void
function setupDevServer(options: Cypress.DevServerOptions, additionalOptions?: TBDType): Cypress.ResolvedDevServerConfig
// required additionalOptions
function setupDevServer(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, additionalOptions: TBDType): void
function setupDevServer(options: Cypress.DevServerOptions, additionalOptions: TBDType): Cypress.ResolvedDevServerConfig For example, react/plugins/babel exports a default (not a named) function, eg. module.exports = returnSetupDevServerFunction(startBabelDevServer, (config) => {
// code
}) That has the following signatures: interface AdditionalOptions {
setWebpackConfig?(config: Configuration): Configuration
}
declare function setupBabelDevServer(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions,
additionalOptions?: AdditionalOptions
): void
declare function setupBabelDevServer(
options: Cypress.DevServerOptions,
additionalOptions?: AdditionalOptions
): Cypress.ResolvedDevServerConfig Which will be used like this in index/plugins.js: const setupDevServer = require('@cypress/react/plugins/babel')
module.exports = (on, config) => {
setupDevServer(on, config)
return config
} And like this in cypress.config.js: const setupDevServer = require('@cypress/react/plugins/babel')
module.exports = {
component: {
startDevServer(options) {
return startDevServer(options)
}
}
} However, the vite-dev-server and webpack-dev-server behave differently. They export named, not default, functions, and their function signatures deviate from the pattern used in the dev server modules in this PR. For example, vite-dev-server exports a named function with a very different signature, eg. export async function startDevServer(startDevServerArgs: StartDevServerOptions): Promise<ResolvedDevServerConfig> {
// code
} export interface StartDevServerOptions {
options: Cypress.DevServerOptions
viteConfig?: UserConfig
} Which will be used like this in index/plugins.js: import { startDevServer } from '@cypress/vite-dev-server'
module.exports = (on, config) => {
on('dev-server:start', async (options) => startDevServer({ options }))
return config
} And like this in cypress.config.js: const { startDevServer } = require('@cypress/vite-dev-server')
module.exports = {
component: {
startDevServer(options) {
return startDevServer({ options })
}
}
} Before this PR is merged, I would like us to decide on a consistent pattern for the signatures and exports for all the dev server modules listed above, and make sure that pattern is followed both in this PR and in follow-up PRs for the vite-dev-server and webpack-dev-server modules, if necessary. Questions to be answered:
I think that all dev server functions should be a named export, for all the reasons listed here and that all dev server functions should conform to the signature patterns outlined in the notion doc (shown above). |
I spoke with @JessicaSachs, and we agreed on the following:
const { defineConfig } = require("cypress");
const cracoConfig = require('./craco.config.js')
const setupCracoDevServer = require("@cypress/react/plugins/craco");
module.exports = defineConfig({
component: {
setupDevServer(devServerConfig) {
return setupCracoDevServer(devServerConfig, { cracoConfig })
}
}
})
// no additionalOptions
function setupDevServer(devServerConfig: Cypress.DevServerConfig): Cypress.ResolvedDevServerConfig
// optional additionalOptions
function setupDevServer(devServerConfig: Cypress.DevServerConfig, options?: TBDType): Cypress.ResolvedDevServerConfig
// required additionalOptions
function setupDevServer(devServerConfig: Cypress.DevServerConfig, options: TBDType): Cypress.ResolvedDevServerConfig
setupCracoDevServer(devServerConfig, { cracoConfig }) |
I am continuing this work in #17817 |
…onfig-cowboy React dev server plugins additional updates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed some
npm/react/examples/react-scripts-folder/cypress/plugins/index.js
Outdated
Show resolved
Hide resolved
npm/react/examples/visual-testing-with-applitools/cypress/plugins/index.js
Outdated
Show resolved
Hide resolved
npm/react/examples/visual-testing-with-happo/cypress/plugins/index.js
Outdated
Show resolved
Hide resolved
npm/react/examples/visual-testing-with-percy/cypress/plugins/index.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…p-gui-gql-stitching * unified-desktop-gui: fix: Global Mode Crashes on Launch (#18059) fix(launchpad): add a11y support to Settings Card (#18027) fix transient dep problem fix(vite-dev-server): remove base and root from inlineVitConfig types (#17180) chore: adding the new app package for the unified app experience (#18053) feat: allow usage of @react/plugins with cypress.config.js (#17738) rename inject into devServer fix: add missing clientCertificate type to ResolvedConfigOptions (#18028) docs: restore author of react,vue,ng component testing (#16800) fix(cypress/schematic): add edge to list of allowed browsers (#17637) fix: global hooks cause duplicated hooks after domain navigation (#17884) chore: release @cypress/webpack-dev-server-v1.5.0 chore: release @cypress/vite-dev-server-v2.0.8
hi, this looks useful - but what's the status now that #17000 has been closed? |
Closes https://cypress-io.atlassian.net/browse/UNIFY-278
User facing changelog
When #17000 is merged, this PR will make this code valid and work
it also will make nextjs installs easier
Changelog of this PR