Skip to content
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

fix(testing): handle more complex projects for react component testing #11725

Merged

Conversation

barbados-clemens
Copy link
Contributor

@barbados-clemens barbados-clemens commented Aug 25, 2022

This change will now use @nrwl/web:webpack utilities and requires a build target to be provided in the @nrwl/cypress:cypress executor options. Using nxComponentTestingPreset will load the @nrwl/web:webpack executor options from the provided build target in order to create the webpack configuration for cypress dev server. As of right now, if it's unable to build the webpack configuration, it will fallback to the default configuration that was there before. Which will handle simple cases/can be extended as needed.

When generating a new component testing configuration, a new option for --build-target is available. this allows for manually specifying the target to use for component testing. If one isn't provided the project graph is used to try to find an existing valid build configuration by looking for parent projects that use @nrwl/web:webpack (i.e. a React App)

Potential issues

if working in a workspace without a project using @nrwl/web:webpack i.e. a publishable react lib without apps. 2 options.

  1. Allow for @nrwl/cypress:cypress to accept a full configuration for @nrwl/web:webpack / make a new component testing executor that has these options (might not be ideal as new frameworks might have different needs i.e. angular)
  2. generate a target that has uses @nrwl/web:webpack and pass to the component testing options. i.e. make a dummy app or add a custom ct-build target with @nrwl/web:webpack in the current project.

Current Behavior

the default webpack configuration used for cypress component testing (in react) fails when having more "complex" set ups i.e. tailwinds via setup-tailwinds generator.

Expected Behavior

things automagically work.

Related Issue(s)

Fixes #11372
Fixes #11509

@vercel
Copy link

vercel bot commented Aug 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
nx-dev ⬜️ Ignored (Inspect) Aug 30, 2022 at 4:22PM (UTC)

@barbados-clemens barbados-clemens self-assigned this Aug 25, 2022
@barbados-clemens barbados-clemens added the scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx label Aug 25, 2022
@barbados-clemens barbados-clemens force-pushed the fix/react-component-testing branch 5 times, most recently from d107318 to f26cb15 Compare August 26, 2022 16:35
packages/cypress/plugins/cypress-preset.ts Outdated Show resolved Hide resolved
forEachExecutorOptions<CypressExecutorOptions>(
tree,
'@nrwl/cypress:cypress',
(options, projectName, targetName, configName) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this handle async callback (maybe follow up PR)

packages/react/plugins/component-testing/index.ts Outdated Show resolved Hide resolved
packages/react/plugins/component-testing/index.ts Outdated Show resolved Hide resolved
packages/react/plugins/component-testing/index.ts Outdated Show resolved Hide resolved
packages/cypress/src/utils/find-target-options.ts Outdated Show resolved Hide resolved
packages/cypress/src/utils/find-target-options.ts Outdated Show resolved Hide resolved
packages/react/plugins/component-testing/index.ts Outdated Show resolved Hide resolved
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx
Projects
None yet
2 participants