Skip to content

Commit fe4ade8

Browse files
committed
test: rework custom test command and example
1 parent 831a51d commit fe4ade8

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
name: example-custom-command
2+
# example using the command parameter
3+
# this allows any cli command to be run
4+
# the command parameter causes other action parameters that would be passed to Cypress
5+
# to be ignored and so it should not be used with these other parameters
6+
# for example, browsers, config, record, parallel, spec, etc would be ignored
27
on:
38
push:
49
branches:
@@ -8,18 +13,16 @@ on:
813

914
jobs:
1015
start:
11-
# example where instead of forming the default "cypress run ..."
12-
# the user can specify their own command
1316
runs-on: ubuntu-24.04
1417
steps:
15-
- name: Checkout 🛎
18+
- name: Checkout
1619
uses: actions/checkout@v4
1720

18-
- name: Custom tests 🧪
21+
- name: Custom tests
1922
uses: ./
2023
with:
2124
command: npm run custom-test
2225
working-directory: examples/custom-command
2326

24-
- name: Show saved file 🖨
27+
- name: Show saved file
2528
run: cat examples/custom-command/results.json

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The following examples demonstrate the actions' functions.
5757
- [`wait-on` with Node.js 18+](#wait-on-with-nodejs-18) workarounds
5858
- Use [custom install command](#custom-install-command)
5959
- Use [command prefix](#command-prefix)
60-
- Use [own custom test command](#custom-test-command)
60+
- Use [custom test command](#custom-test-command)
6161
- Pass [custom build id](#custom-build-id) when recording to Cypress Cloud
6262
- Generate a [robust custom build id](#robust-custom-build-id) to allow re-running the workflow
6363
- Use different [working-directory](#working-directory)
@@ -964,22 +964,28 @@ jobs:
964964

965965
### Custom test command
966966

967-
You can overwrite the Cypress run command with your own command.
967+
The `command` parameter executes a CLI command using the GitHub [@actions/exec](https://github.com/actions/toolkit/tree/main/packages/exec) action.
968+
969+
This parameter is useful for special test cases, for example:
970+
971+
- in the project [examples/custom-command](./examples/custom-command/), a JavaScript [examples/custom-command/index.js](./examples/custom-command/index.js) is run with `node .` through `command: npm run custom-test`
972+
- in the workflow [example-yarn-modern-pnp.yml](.github/workflows/example-yarn-modern-pnp.yml) Yarn Modern with Plug'n'Play is run with `command: yarn run --binaries-only cypress run` since [Yarn Plug'n'Play](#yarn-plugnplay) is not natively supported by the action.
973+
974+
If you don't have a special case and you just need to convert a `cypress run` CLI command to use the Cypress GitHub Action, refer to the section [Migrating from CLI command](#migrating-from-cli-command) which explains how to map CLI options to equivalent action parameters, avoiding the need for the `command` parameter in most cases.
975+
976+
There are some parameters that cannot be used together with the `command` parameter, and these are ignored. The parameters include action input parameters listed in the table [CLI Run Option / Action Parameter](#cli-run-option--action-parameter), the [publish-summary](#suppress-job-summary), [summary-title](#job-summary-title) and [command-prefix](#command-prefix). If any such parameters are passed to the action, a warning message appears in the logs that the parameters have been ignored.
977+
978+
Correct Example:
968979

969980
```yml
970981
steps:
971-
- name: Checkout 🛎
972-
uses: actions/checkout@v4
973-
974-
- name: Custom tests 🧪
975-
uses: cypress-io/github-action@v6
982+
- uses: actions/checkout@v4
983+
- uses: cypress-io/github-action@v6
976984
with:
977-
command: npm run e2e:ci
985+
command: npm run custom-test
978986
```
979987

980-
**Caution**: using the action parameter `command` causes multiple other parameters to be ignored including: `auto-cancel-after-failures`, `browser`, `ci-build-id`, `command-prefix`, `component`, `config`, `config-file`, `env`, `group`, `headed`, `parallel`, `project`, `publish-summary`, `quiet`, `record`, `spec` and `tag`.
981-
982-
See [example-custom-command.yml](.github/workflows/example-custom-command.yml) file.
988+
[![command example](https://github.com/cypress-io/github-action/actions/workflows/example-custom-command.yml/badge.svg)](.github/workflows/example-custom-command.yml)
983989

984990
### Custom build id
985991

@@ -1607,7 +1613,7 @@ If you configure a `workflow_dispatch` event in your own workflows, you will be
16071613

16081614
### Outputs
16091615

1610-
This action sets a GitHub step output `resultsUrl` if the run was recorded on [Cypress Cloud](https://on.cypress.io/cloud-introduction) using the action parameter setting `record: true` (see [Record test results on Cypress Cloud](#record-test-results-on-cypress-cloud)). Note that if a custom test command with the [command](#custom-test-command) option or the [command-prefix](#command-prefix) option are used then no `resultsUrl` step output is saved.
1616+
This action sets a GitHub step output `resultsUrl` if the run was recorded on [Cypress Cloud](https://on.cypress.io/cloud-introduction) using the action parameter setting `record: true` (see [Record test results on Cypress Cloud](#record-test-results-on-cypress-cloud)). Note that if a custom test command with the [command](#custom-test-command) parameter or the [command-prefix](#command-prefix) parameter are used then no `resultsUrl` step output is saved.
16111617

16121618
This is an example of using the step output `resultsUrl`:
16131619

0 commit comments

Comments
 (0)