Skip to content

Commit a241e73

Browse files
committed
add tag support
1 parent 20e6ff2 commit a241e73

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ package = "netlify-plugin-cypress"
8282

8383
See [cypress-example-kitchensink](https://github.com/cypress-io/cypress-example-kitchensink) and recorded results at [![Cypress Dashboard](https://img.shields.io/badge/cypress-dashboard-brightgreen.svg)](https://dashboard.cypress.io/#/projects/4b7344/runs)
8484

85+
#### group
86+
8587
You can change the group name for the recorded run using `group` parameter
8688

8789
```toml
@@ -93,6 +95,20 @@ package = "netlify-plugin-cypress"
9395
group = "built site"
9496
```
9597

98+
#### tag
99+
100+
You can give recorded run [tags](https://on.cypress.io/module-api#cypress-run) using a comma-separated string
101+
102+
```toml
103+
[[plugins]]
104+
# local Cypress plugin will test our site after it is built
105+
package = "netlify-plugin-cypress"
106+
[plugins.inputs]
107+
record = true
108+
group = "built site"
109+
tag = "nightly,production"
110+
```
111+
96112
### spec
97113

98114
Run only a single spec or specs matching a wildcard
@@ -134,7 +150,7 @@ By default this plugin tests static site _after build_. But maybe you want to ru
134150
wait-on-timeout = '30' # seconds
135151
```
136152

137-
Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-timeout`, `spec`, `record`, and `group`.
153+
Parameters you can place into `preBuild` inputs: `start`, `wait-on`, `wait-on-timeout`, `spec`, `record`, `group`, and `tag`.
138154

139155
## Debugging
140156

src/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function waitOnMaybe (options = {}) {
6262
}
6363
}
6464

65-
async function runCypressTests (baseUrl, record, spec, group) {
65+
async function runCypressTests (baseUrl, record, spec, group, tag) {
6666
// we will use Cypress via its NPM module API
6767
// https://on.cypress.io/module-api
6868
const cypress = require('cypress')
@@ -74,7 +74,7 @@ async function runCypressTests (baseUrl, record, spec, group) {
7474
ciBuildId = process.env.BUILD_ID
7575
}
7676

77-
debug('run cypress params %o', { baseUrl, record, spec, group, ciBuildId })
77+
debug('run cypress params %o', { baseUrl, record, spec, group, tag, ciBuildId })
7878

7979
return await cypress.run({
8080
config: {
@@ -83,6 +83,10 @@ async function runCypressTests (baseUrl, record, spec, group) {
8383
spec,
8484
record,
8585
group,
86+
// ignoring the TS error for now
87+
// https://github.com/cypress-io/cypress/pull/6796
88+
// @ts-ignore
89+
tag,
8690
ciBuildId
8791
})
8892
}
@@ -122,14 +126,14 @@ const processCypressResults = (results, failBuild) => {
122126
}
123127
}
124128

125-
async function postBuild({ fullPublishFolder, record, spec, group, failBuild }) {
129+
async function postBuild({ fullPublishFolder, record, spec, group, tag, failBuild }) {
126130
const port = 8080
127131
const server = serveFolder(fullPublishFolder, port)
128132
debug('local server listening on port %d', port)
129133

130134
const baseUrl = `http://localhost:${port}`
131135

132-
const results = await runCypressTests(baseUrl, record, spec, group)
136+
const results = await runCypressTests(baseUrl, record, spec, group, tag)
133137

134138
await new Promise((resolve, reject) => {
135139
server.close(err => {
@@ -170,11 +174,15 @@ module.exports = function cypressPlugin (pluginConfig) {
170174
const record = Boolean(preBuildInputs.record)
171175
const spec = preBuildInputs.spec
172176
let group
177+
let tag
173178
if (record) {
174179
group = preBuildInputs.group || 'preBuild'
180+
if (preBuildInputs.tag) {
181+
tag = preBuildInputs.tag
182+
}
175183
}
176184

177-
const results = await runCypressTests(baseUrl, record, spec, group)
185+
const results = await runCypressTests(baseUrl, record, spec, group, tag)
178186

179187
if (closeServer) {
180188
debug('closing server')
@@ -200,8 +208,12 @@ module.exports = function cypressPlugin (pluginConfig) {
200208

201209
const spec = pluginConfig.spec
202210
let group
211+
let tag
203212
if (record) {
204213
group = pluginConfig.group || 'postBuild'
214+
if (pluginConfig.tag) {
215+
tag = pluginConfig.tag
216+
}
205217
}
206218

207219
const failBuild = arg.utils && arg.utils.build && arg.utils.build.failBuild
@@ -212,6 +224,7 @@ module.exports = function cypressPlugin (pluginConfig) {
212224
record,
213225
spec,
214226
group,
227+
tag,
215228
failBuild
216229
})
217230
}

0 commit comments

Comments
 (0)