Skip to content

Commit dace029

Browse files
authored
feat: add expose input for Cypress.expose() API (#1749)
1 parent b7a7441 commit dace029

11 files changed

Lines changed: 2368 additions & 2 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: example-expose
2+
# In the example jobs, the action is called with
3+
# uses: ./
4+
# which runs the action code from the current branch.
5+
# If you copy this workflow to another repo, replace the line with
6+
# uses: cypress-io/github-action@v7
7+
on:
8+
push:
9+
branches:
10+
- 'master'
11+
pull_request:
12+
workflow_dispatch:
13+
14+
jobs:
15+
with-expose:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v6
20+
21+
- name: Cypress run with expose
22+
uses: ./
23+
with:
24+
working-directory: examples/expose
25+
expose: host=http://api.dev.local,apiPort=4222
26+
spec: cypress/e2e/spec.cy.js

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ See [Releases](https://github.com/cypress-io/github-action/releases) for full de
66

77
| Version | Changes |
88
| ------- | ------------------------------------------------------------------------------------------------------------ |
9+
| v7.3.0 | Add parameter `expose` for [`Cypress.expose()`](https://docs.cypress.io/api/cypress-api/expose) support |
910
| v7.2.0 | Examples remove Node.js 20. End of support for Node.js 20. |
1011
| v7.1.0 | Add parameter `package-manager-cache` |
1112
| v7.0.0 | Action runs under Node.js 24 instead of Node.js 20 |

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The following examples demonstrate the actions' functions.
3737
- using [headed mode](#headed)
3838
- Using [Docker image](#docker-image)
3939
- Specify [environment variables](#env)
40+
- Specify [expose variables](#expose)
4041
- Run only some [spec files](#specs)
4142
- Test [project in subfolder](#project)
4243
- [Record results](#record-test-results-on-cypress-cloud) on Cypress Cloud
@@ -358,6 +359,30 @@ For more examples, see the workflows below, using environment variables for [rec
358359

359360
[![Env example](https://github.com/cypress-io/github-action/actions/workflows/example-env.yml/badge.svg)](.github/workflows/example-env.yml)
360361

362+
### Expose
363+
364+
Specify the expose argument with `expose` parameter. Expose variables are for non-sensitive, public config values that are synchronous and exposed to the browser (requires Cypress 15.10.0 or later).
365+
366+
```yml
367+
name: Cypress tests
368+
on: push
369+
jobs:
370+
cypress-run:
371+
runs-on: ubuntu-24.04
372+
steps:
373+
- name: Checkout
374+
uses: actions/checkout@v6
375+
376+
- name: Cypress run with expose
377+
uses: cypress-io/github-action@v7
378+
with:
379+
expose: host=api.dev.local,port=4222
380+
```
381+
382+
For more information, see [Cypress.expose()](https://docs.cypress.io/api/cypress-api/expose) in the Cypress documentation.
383+
384+
[![Expose example](https://github.com/cypress-io/github-action/actions/workflows/example-expose.yml/badge.svg)](.github/workflows/example-expose.yml)
385+
361386
### Specs
362387

363388
Specify the [spec files to run](https://docs.cypress.io/guides/guides/command-line.html#cypress-run-spec-lt-spec-gt) with `spec` parameter
@@ -1619,6 +1644,7 @@ jobs:
16191644
| `--config-file`, `-C` | [`config-file`](#config-file) | Specify configuration file |
16201645
| `--e2e` | [`component: false`](#component-testing) (default) | Run end to end tests |
16211646
| `--env`, `-e` | [`env`](#env) | Specify environment variables |
1647+
| `--expose`, `-x` | [`expose`](#expose) | Specify expose variables for non-sensitive, public config values |
16221648
| `--group` | [`group`](#parallel) | Group recorded tests together under a single run for Cloud recording |
16231649
| `--headed` | [`headed`](#headed) | Display the browser instead of running headlessly |
16241650
| `--headless` | [`headed: false`](#headed) (default) | Hide the browser instead of running headed |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ inputs:
2929
env:
3030
description: 'Sets Cypress environment variables'
3131
required: false
32+
expose:
33+
description: 'Sets Cypress expose variables for non-sensitive, public config values (requires Cypress 15.10.0 or later)'
34+
required: false
3235
group:
3336
description: 'Group setting for recording tests'
3437
required: false

dist/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102320,6 +102320,12 @@ const runTestsUsingCommandLine = async () => {
102320102320
cmd.push(envInput)
102321102321
}
102322102322

102323+
const exposeInput = core.getInput('expose')
102324+
if (exposeInput) {
102325+
cmd.push('--expose')
102326+
cmd.push(exposeInput)
102327+
}
102328+
102323102329
const quiet = getInputBool('quiet')
102324102330
if (quiet) {
102325102331
cmd.push('--quiet')
@@ -102360,6 +102366,7 @@ const commandIgnoredStringInputs = [
102360102366
'config',
102361102367
'config-file',
102362102368
'env',
102369+
'expose',
102363102370
'group',
102364102371
'project',
102365102372
'spec',
@@ -102383,7 +102390,9 @@ const validateCustomCommand = () => {
102383102390
})
102384102391
if (ignoredInputParameters.length > 0) {
102385102392
core.warning(
102386-
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters.sort().join(', ')}.`
102393+
`command parameter is used and the following other parameters are ignored: ${ignoredInputParameters
102394+
.sort()
102395+
.join(', ')}.`
102387102396
)
102388102397
}
102389102398
}
@@ -102479,6 +102488,10 @@ const runTests = async () => {
102479102488
cypressOptions.env = core.getInput('env')
102480102489
}
102481102490

102491+
if (core.getInput('expose')) {
102492+
cypressOptions.expose = core.getInput('expose')
102493+
}
102494+
102482102495
if (cypressOptions.parallel || cypressOptions.group) {
102483102496
const { branch, buildId } = await getCiBuildId()
102484102497
if (branch) {

examples/expose/cypress.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
fixturesFolder: false,
5+
e2e: {
6+
setupNodeEvents (on, config) {
7+
console.log('logging from cypress.config.js')
8+
console.log('entire config.expose', config.expose)
9+
},
10+
supportFile: false,
11+
},
12+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
it('has all expected expose variables', () => {
2+
expect(Cypress.expose('host'), 'host is an URL').to.match(
3+
/^https?:\/\//,
4+
)
5+
expect(
6+
Cypress.expose(),
7+
'full expose includes API info',
8+
).to.deep.include({
9+
host: 'http://api.dev.local',
10+
apiPort: 4222,
11+
})
12+
})

0 commit comments

Comments
 (0)