@nx/next:cypress-component-configuration
Add Cypress Componet Testing to an existing NextJS project.
Add Cypress Componet Testing to an existing NextJS project.
Next component testing with Nx requires Cypress version 10.7.0 and up.
You can migrate with to v11 via the migrate-to-cypress-11 generator.
This generator is for Cypress based component testing.
If you want to test components via Storybook with Cypress, then check out the storybook-configuration generator docs. However, this functionality is deprecated, and will be removed on Nx version 19.
This generator is designed to get your Next project up and running with Cypress Component Testing.
โฏ
nx g @nx/next:cypress-component-configuration --project=my-cool-next-project
Running this generator, adds the required files to the specified project with a preconfigured cypress.config.ts
designed for Nx workspaces.
1import { defineConfig } from 'cypress';
2import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';
3
4export default defineConfig({
5 component: nxComponentTestingPreset(__filename),
6});
7
Here is an example on how to add custom options to the configuration
1import { defineConfig } from 'cypress';
2import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';
3
4export default defineConfig({
5 component: {
6 ...nxComponentTestingPreset(__filename),
7 // extra options here
8 },
9});
10
โฏ
nx g @nx/next:cypress-component-project --project=my-cool-next-project
You can optionally use the --generate-tests
flag to generate a test file for each component in your project.
โฏ
nx g @nx/next:cypress-component-configuration --project=my-cool-next-project --generate-tests
A new component-test
target will be added to the specified project to run your component tests.
โฏ
nx g component-test my-cool-next-project
Here is an example of the project configuration that is generated.
1{
2 "targets" {
3 "component-test": {
4 "executor": "@nx/cypress:cypress",
5 "options": {
6 "cypressConfig": "<path-to-project-root>/cypress.config.ts",
7 "testingType": "component",
8 "skipServe": true
9 }
10 }
11 }
12}
13
Nx also supports Angular component testing.
1nx generate cypress-component-configuration ...
2
By default, Nx will search for cypress-component-configuration
in the default collection provisioned in workspace.json.
You can specify the collection explicitly as follows:
1nx g @nx/next:cypress-component-configuration ...
2
Show what will be generated without writing to disk:
1nx g cypress-component-configuration ... --dry-run
2
Add component testing to your Next project:
1nx g @nx/next:cypress-component-configuration --project=my-next-project
2
Add component testing to your Next project and generate component tests for your existing components:
1nx g @nx/next:cypress-component-configuration --project=my-next-project --generate-tests
2
The name of the project to add cypress component testing configuration to
false
Generate default component tests for existing components in the project
false
Skip formatting files
In case you missed Monorepo World, it is now available for replay.