|
1 | | -# @currents/nx |
| 1 | +# Debug, troubleshoot and record Cypress CI tests in Cloud |
2 | 2 |
|
3 | | -[NX](https://nx.dev/) plugin for running cypress tests on Currents.dev |
| 3 | +[NX](https://nx.dev/) plugin for running cypress tests using [Currents](https://currents.dev) or [Sorry Cypress](https://sorry-cypress.dev). |
| 4 | + |
| 5 | +Integrate Cypress with alternative cloud services like Currents or Sorry Cypress. |
| 6 | + |
| 7 | +The plugin is designed for CI environments and runs Cypress in headless mode. Please use `@nrwl/cypress` for running cypress in interactive mode. |
| 8 | + |
| 9 | +## Example |
| 10 | + |
| 11 | +See [./apps/web-e2e](./apps/web-e2e) for an example installation: |
| 12 | + |
| 13 | +```sh |
| 14 | +npx nx run web-e2e:currents --key <recordKey> --ci-build-id hello-currents-nx |
| 15 | +``` |
4 | 16 |
|
5 | 17 | ## Setup |
6 | 18 |
|
7 | 19 | Install `@currents/nx` |
8 | 20 |
|
9 | 21 | ```sh |
10 | 22 | npm i --save-dev @currents/nx |
| 23 | +npx nx g @currents/nx:init <destination_project> |
11 | 24 | ``` |
12 | 25 |
|
13 | | -Add `currents` target to your project configuration |
| 26 | +Add target `currents` to your project configuration: |
14 | 27 |
|
15 | 28 | ```js |
16 | | - |
17 | 29 | { |
18 | | -// ... |
19 | | -"targets": { |
20 | | - "currents": { |
21 | | - "executor": "@currents/nx:currents", |
22 | | - "options": { |
23 | | - "cypressExecutor": "e2e" // target name that runs "@nrwl/cypress:cypress" |
24 | | - } |
25 | | - }, |
26 | | - "e2e": { |
27 | | - "executor": "@nrwl/cypress:cypress", |
28 | | - "options": { |
29 | | - // ... |
30 | | - }, |
31 | | - "configurations": { |
32 | | - // ... |
| 30 | + // ... |
| 31 | + "targets": { |
| 32 | + "currents": { |
| 33 | + "executor": "@currents/nx:currents", |
| 34 | + "options": { |
| 35 | + "record": true, |
| 36 | + "parallel": true, |
| 37 | + "cypressConfig": "apps/app-e2e/cypres.config.ts", |
| 38 | + "devServerTarget": "my-react-app:serve", |
| 39 | + "testingType": "e2e" |
| 40 | + } |
33 | 41 | } |
34 | 42 | } |
35 | | -} |
36 | | -// ... |
| 43 | + // ... |
37 | 44 | ``` |
38 | 45 |
|
39 | | -Run cypress tests, using Currents.dev as a dashboard |
| 46 | +Create a new configuration file: `currents.config.js` next to `cypress.config.{jt}s` |
| 47 | +
|
| 48 | +```js |
| 49 | +// currents.config.js |
| 50 | +module.exports = { |
| 51 | + // Set the `projectId` and the record key obtained from https://app.currents.dev or your self-hosted instance of Sorry Cypress |
| 52 | + projectId: 'Ij0RfK', |
| 53 | + // Sorry Cypress users - set the director service URL |
| 54 | + cloudServiceUrl: 'https://cy.currents.dev', |
| 55 | +}; |
| 56 | +``` |
| 57 | +
|
| 58 | +Add `cypress-cloud/plugin` to `cypress.config.{js|ts|mjs}` |
| 59 | +
|
| 60 | +```ts |
| 61 | +import { nxE2EPreset } from '@nrwl/cypress/plugins/cypress-preset'; |
| 62 | +import { defineConfig } from 'cypress'; |
| 63 | +import cloudPlugin from 'cypress-cloud/plugin'; |
| 64 | + |
| 65 | +export default defineConfig({ |
| 66 | + e2e: { |
| 67 | + ...nxE2EPreset(__dirname, { |
| 68 | + bundler: 'vite', |
| 69 | + }), |
| 70 | + specPattern: './src/**/*.cy.ts', |
| 71 | + setupNodeEvents(on, config) { |
| 72 | + return cloudPlugin(on, config); |
| 73 | + }, |
| 74 | + }, |
| 75 | +}); |
| 76 | +``` |
| 77 | +
|
| 78 | +## Usage |
40 | 79 |
|
41 | 80 | ```sh |
42 | | -nx run project:currents --group nx --record --key <key> --ci-build-id hello-currents-nx |
| 81 | +npx nx run web-e2e:currents --key <recordKey> --ci-build-id hello-currents-nx |
43 | 82 | ``` |
44 | 83 |
|
45 | | -- The plugin requires an already installed `@nrwl/cypress` and a configured target that's running `@nrwl/cypress:cypress` |
46 | | -- `@currents/nx:currents` will run `@nrwl/cypress:cypress` behind the scenes |
47 | | -- You can set predefined options in target definition |
48 | 84 | - Update your `cypress.json` file with `projectId` obtained at https://app.currents.dev |
49 | 85 | - Use the record key obtained at https://app.currents.dev |
50 | 86 |
|
51 | | -### Example |
| 87 | +## Configuration |
| 88 | +
|
| 89 | +Options can be configured in `project.json` when defining the executor, or when invoking it. Read more about how to configure targets and executors here: https://nx.dev/reference/project-configuration#targets. |
| 90 | +
|
| 91 | +See the [schema.json](./src/executors/schema.json) for the list of available options |
| 92 | +
|
| 93 | +## Migration |
| 94 | +
|
| 95 | +### Version `2.0.0` |
| 96 | +
|
| 97 | +- Using [`cypress-cloud`](https://github.com/currents-dev/cypress-cloud) as the orchestration tool |
| 98 | +
|
| 99 | +### Version `1.0.0` |
52 | 100 |
|
53 | | -See https://github.com/currents-dev/currents-nx-example for example integration |
| 101 | +- `@nrwl/cypress` no longer required - the plugin is a standalone implementation that is not dependent on `@nrwl/cypress`. Use the available configuration options to configure the execution of cypress runs. |
0 commit comments