Skip to content

Commit 0510bec

Browse files
committed
breaking: release version 6.0.0 of @cypress/grep
BREAKING CHANGE: use Cypress.expose() instead of Cypress.env(), which requires a peer dependency on Cypress 15.10.0
1 parent c301833 commit 0510bec

File tree

7 files changed

+101
-86
lines changed

7 files changed

+101
-86
lines changed

npm/grep/README.md

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ export default defineConfig({
9191
Run tests with "login" in the title:
9292

9393
```shell
94-
npx cypress run --env grep="login"
94+
npx cypress run --expose grep="login"
9595
```
9696

9797
Run tests with "user authentication" in the title:
9898

9999
```shell
100-
npx cypress run --env grep="user authentication"
100+
npx cypress run --expose grep="user authentication"
101101
```
102102

103103
Multiple title patterns (OR logic):
104104

105105
```shell
106-
npx cypress run --env grep="login; logout; signup"
106+
npx cypress run --expose grep="login; logout; signup"
107107
```
108108

109109
### Filter by Tags
@@ -134,39 +134,39 @@ Then run by tags:
134134
Run tests with @smoke tag:
135135

136136
```shell
137-
npx cypress run --env grepTags="@smoke"
137+
npx cypress run --expose grepTags="@smoke"
138138
```
139139

140140
Run tests with @smoke OR @critical tags:
141141

142142
```shell
143-
npx cypress run --env grepTags="@smoke @critical"
143+
npx cypress run --expose grepTags="@smoke @critical"
144144
```
145145

146146
Run tests with BOTH @smoke AND @critical tags:
147147

148148
```shell
149-
npx cypress run --env grepTags="@smoke+@critical"
149+
npx cypress run --expose grepTags="@smoke+@critical"
150150
```
151151

152152
Run tests with @smoke tag but NOT @slow tag:
153153

154154
```shell
155-
npx cypress run --env grepTags="@smoke+-@slow"
155+
npx cypress run --expose grepTags="@smoke+-@slow"
156156
```
157157

158158
### Combine Title and Tag Filters
159159

160160
Run tests with "login" in title AND tagged @smoke:
161161

162162
```shell
163-
npx cypress run --env grep="login",grepTags="@smoke"
163+
npx cypress run --expose grep="login",grepTags="@smoke"
164164
```
165165

166166
Run tests with "user" in title AND tagged @critical OR @smoke:
167167

168168
```shell
169-
npx cypress run --env grep="user",grepTags="@critical @smoke"
169+
npx cypress run --expose grep="user",grepTags="@critical @smoke"
170170
```
171171

172172
## Advanced Features
@@ -178,21 +178,21 @@ Skip loading specs that don't contain matching tests (requires plugin setup):
178178
Only run specs containing tests with "login" in title:
179179

180180
```shell
181-
npx cypress run --env grep="login",grepFilterSpecs=true
181+
npx cypress run --expose grep="login",grepFilterSpecs=true
182182
```
183183

184184
Only run specs containing tests tagged @smoke:
185185

186186
```shell
187-
npx cypress run --env grepTags="@smoke",grepFilterSpecs=true
187+
npx cypress run --expose grepTags="@smoke",grepFilterSpecs=true
188188
```
189189

190190
### Omit Filtered Tests
191191

192192
By default, filtered tests are marked as pending. To completely omit them:
193193

194194
```shell
195-
npx cypress run --env grep="login",grepOmitFiltered=true
195+
npx cypress run --expose grep="login",grepOmitFiltered=true
196196
```
197197

198198
### Test Burning (Repeat Tests)
@@ -202,41 +202,41 @@ Run filtered tests multiple times to catch flaky behavior:
202202
Run matching tests 5 times:
203203

204204
```shell
205-
npx cypress run --env grep="login",burn=5
205+
npx cypress run --expose grep="login",burn=5
206206
```
207207

208208
Run all tests 10 times:
209209

210210
```shell
211-
npx cypress run --env burn=10
211+
npx cypress run --expose burn=10
212212
```
213213

214214
### Inverted Filters
215215

216216
Run tests WITHOUT "slow" in the title:
217217

218218
```shell
219-
npx cypress run --env grep="-slow"
219+
npx cypress run --expose grep="-slow"
220220
```
221221

222222
Run tests WITHOUT @slow tag:
223223

224224
```shell
225-
npx cypress run --env grepTags="-@slow"
225+
npx cypress run --expose grepTags="-@slow"
226226
```
227227

228228
Complex combinations:
229229

230230
```shell
231-
npx cypress run --env grep="login; -slow",grepTags="@smoke+-@regression"
231+
npx cypress run --expose grep="login; -slow",grepTags="@smoke+-@regression"
232232
```
233233

234234
### Run Untagged Tests
235235

236236
Run only tests without any tags:
237237

238238
```shell
239-
npx cypress run --env grepUntagged=true
239+
npx cypress run --expose grepUntagged=true
240240
```
241241

242242
## Configuration Examples
@@ -248,7 +248,7 @@ import { defineConfig } from 'cypress'
248248
import { plugin as cypressGrepPlugin } from '@cypress/grep/plugin'
249249

250250
export default defineConfig({
251-
env: {
251+
expose: {
252252
// Always filter by viewport tests
253253
grep: "viewport",
254254
// Always enable spec filtering
@@ -270,10 +270,10 @@ export default defineConfig({
270270
```json
271271
{
272272
"scripts": {
273-
"cy:smoke": "cypress run --env grepTags=@smoke",
274-
"cy:critical": "cypress run --env grepTags=@critical",
275-
"cy:fast": "cypress run --env grepTags=@fast",
276-
"cy:burn": "cypress run --env grepTags=@smoke,burn=5"
273+
"cy:smoke": "cypress run --expose grepTags=@smoke",
274+
"cy:critical": "cypress run --expose grepTags=@critical",
275+
"cy:fast": "cypress run --expose grepTags=@fast",
276+
"cy:burn": "cypress run --expose grepTags=@smoke,burn=5"
277277
}
278278
}
279279
```
@@ -338,7 +338,7 @@ Cypress.grep()
338338

339339
1. **Spec Loading**: When not using `grepFilterSpecs`, all spec files are loaded before filtering occurs
340340
2. **Inverted Filters**: Negative filters (`-tag`, `-title`) are not compatible with `grepFilterSpecs`
341-
3. **Runtime Changes**: Cannot change grep filters at runtime using `Cypress.env()`
341+
3. **Runtime Changes**: Cannot change grep filters at runtime using `Cypress.expose()`
342342
4. **Cloud Recordings**: Filtered tests may still appear in Cypress Cloud recordings as pending tests
343343

344344
## Best Practices
@@ -369,7 +369,7 @@ it('should work', { tags: ['@smoke', '@fast'] }, () => {
369369
1. Run smoke tests first:
370370

371371
```shell
372-
npx cypress run --env grepTags="@smoke"
372+
npx cypress run --expose grepTags="@smoke"
373373
```
374374

375375
2. If smoke tests pass, run all tests:
@@ -381,11 +381,11 @@ npx cypress run
381381
3. For debugging, run specific test groups:
382382

383383
```shell
384-
npx cypress run --env grep="user management"
384+
npx cypress run --expose grep="user management"
385385
```
386386

387387
```shell
388-
npx cypress run --env grepTags="@critical"
388+
npx cypress run --expose grepTags="@critical"
389389
```
390390

391391
### Performance Tips
@@ -403,7 +403,7 @@ Enable debug logging to see what's happening:
403403
Terminal debug (for plugin):
404404

405405
```shell
406-
DEBUG=@cypress/grep npx cypress run --env grep="login"
406+
DEBUG=@cypress/grep npx cypress run --expose grep="login"
407407
```
408408

409409
Browser debug (for support file):
@@ -422,6 +422,21 @@ Then refresh and run tests.
422422

423423
## Migration
424424

425+
### From v5 to v6
426+
427+
`Cypress.env()` is deprecated in Cypress 15.10.0. For public configuration, the API has been replaced with `Cypress.expose()`
428+
429+
To migrate, change your `--env`/`-e` CLI arguments from
430+
```sh
431+
npx cypress run --env grepTags="tag1 tag2"
432+
```
433+
434+
to the following to use `--expose`/`-x`
435+
```sh
436+
npx cypress run --expose grepTags="tag1 tag2"
437+
```
438+
439+
425440
### From v4 to v5
426441

427442
The support file registration and plugin have changed their export signature, meaning:

npm/grep/cypress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import debug from 'debug'
88
const debugInstance = debug('cypress:grep:compare-results')
99

1010
export default defineConfig({
11-
allowCypressEnv: true,
11+
allowCypressEnv: false,
1212
e2e: {
1313
defaultCommandTimeout: 1000,
1414
setupNodeEvents (on, config) {

npm/grep/cypress/e2e/grep-task.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ describe('plugin', () => {
44
cy.task('grep', {
55
excludeSpecPattern: ['**/test2.cy.ts', '**/test3.cy.ts'],
66
specPattern: '**/*.cy.ts',
7-
env: {
7+
expose: {
88
grepTags: 'smoke',
99
grepFilterSpecs: true,
1010
},
@@ -18,7 +18,7 @@ describe('plugin', () => {
1818
cy.task('grep', {
1919
excludeSpecPattern: '**/test2.cy.ts',
2020
specPattern: '**/*.cy.ts',
21-
env: {
21+
expose: {
2222
grepTags: 'smoke',
2323
grepFilterSpecs: true,
2424
},

npm/grep/package.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77
"cypress:open": "node ../../scripts/cypress.js open",
88
"test": "vitest",
99
"test-debug": "vitest --inspect-brk --no-file-parallelism --test-timeout=0",
10-
"and": "PROJECT_NAME=and node ../../scripts/cypress.js run --env grep='Test 2',grepTags='smoke+high' --config specPattern='**/tags/*.cy.ts'",
11-
"and:not": "PROJECT_NAME=and-not node ../../scripts/cypress.js run --env grep='Test 2',grepTags='smoke+-high' --config specPattern='**/tags/*.cy.ts'",
12-
"burn": "PROJECT_NAME=burn node ../../scripts/cypress.js run --env burn=5 --config specPattern='**/burn.cy.ts'",
10+
"and": "PROJECT_NAME=and node ../../scripts/cypress.js run --expose grep='Test 2',grepTags='smoke+high' --config specPattern='**/tags/*.cy.ts'",
11+
"and:not": "PROJECT_NAME=and-not node ../../scripts/cypress.js run --expose grep='Test 2',grepTags='smoke+-high' --config specPattern='**/tags/*.cy.ts'",
12+
"burn": "PROJECT_NAME=burn node ../../scripts/cypress.js run --expose burn=5 --config specPattern='**/burn.cy.ts'",
1313
"each": "PROJECT_NAME=each node ../../scripts/cypress.js run --config specPattern='**/each.cy.ts'",
14-
"filter:specs": "PROJECT_NAME=filter-specs node ../../scripts/cypress.js run --env grep='Test 2',grepFilterSpecs=true --config specPattern='**/tags/*.cy.ts'",
14+
"filter:specs": "PROJECT_NAME=filter-specs node ../../scripts/cypress.js run --expose grep='Test 2',grepFilterSpecs=true --config specPattern='**/tags/*.cy.ts'",
1515
"grep": "PROJECT_NAME=grep node ../../scripts/cypress.js run --config specPattern='**/grep-task.cy.ts'",
16-
"inverted": "PROJECT_NAME=inverted node ../../scripts/cypress.js run --env grep='-Test 2' --config specPattern='**/tags/*.cy.ts'",
16+
"inverted": "PROJECT_NAME=inverted node ../../scripts/cypress.js run --expose grep='-Test 2' --config specPattern='**/tags/*.cy.ts'",
1717
"lint": "eslint",
1818
"multiple-registrations": "PROJECT_NAME=multiple-registrations node ../../scripts/cypress.js run --config specPattern='**/multiple-registrations.cy.ts'",
19-
"omit:specs": "PROJECT_NAME=omit-specs node ../../scripts/cypress.js run --env grep='Test 2',grepOmitFiltered=true --config specPattern='**/tags/*.cy.ts'",
20-
"or": "PROJECT_NAME=or node ../../scripts/cypress.js run --env grep='Test 1',grepTags='regression high' --config specPattern='**/tags/*.cy.ts'",
19+
"omit:specs": "PROJECT_NAME=omit-specs node ../../scripts/cypress.js run --expose grep='Test 2',grepOmitFiltered=true --config specPattern='**/tags/*.cy.ts'",
20+
"or": "PROJECT_NAME=or node ../../scripts/cypress.js run --expose grep='Test 1',grepTags='regression high' --config specPattern='**/tags/*.cy.ts'",
2121
"skip": "PROJECT_NAME=skip node ../../scripts/cypress.js run --config specPattern='**/*skip.cy.ts'",
22-
"tags:inverted": "PROJECT_NAME=tag-inverted node ../../scripts/cypress.js run --env grepTags='-regression' --config specPattern='**/tags/*.cy.ts'",
23-
"tags": "PROJECT_NAME=tags node ../../scripts/cypress.js run --env grepTags=smoke --config specPattern='**/tags/*.cy.ts'",
24-
"tags:and": "PROJECT_NAME=tags-and node ../../scripts/cypress.js run --env grepTags='smoke+high' --config specPattern='**/tags/*.cy.ts'",
25-
"tags:and:not": "PROJECT_NAME=tags-and-not node ../../scripts/cypress.js run --env grepTags='smoke+-high' --config specPattern='**/tags/*.cy.ts'",
26-
"tags:before": "PROJECT_NAME=tags-before node ../../scripts/cypress.js run --env grepTags=@staging --config specPattern='**/before.cy.ts'",
27-
"tags:config": "PROJECT_NAME=tags-config node ../../scripts/cypress.js run --env grepTags=config --config specPattern='**/config-tags.cy.ts'",
28-
"tags:describe": "PROJECT_NAME=tags-describe node ../../scripts/cypress.js run --env grepTags=@smoke --config specPattern='**/describe-tags.cy.ts'",
29-
"tags:filter:specs": "PROJECT_NAME=tags-filter-specs node ../../scripts/cypress.js run --env grepTags='regression',grepFilterSpecs=true --config specPattern='**/tags/*.cy.ts'",
30-
"tags:inherit": "PROJECT_NAME=tags-inherit node ../../scripts/cypress.js run --env grepTags=@screen-b --config specPattern='**/inherits-tag.cy.ts'",
31-
"tags:nested-describe": "PROJECT_NAME=tags-nested-describe node ../../scripts/cypress.js run --env grepTags='@smoke @integration' --config specPattern='**/nested-describe.cy.ts'",
32-
"tags:omit:specs": "PROJECT_NAME=tags-omit-specs node ../../scripts/cypress.js run --env grepTags='regression',grepOmitFiltered=true --config specPattern='**/tags/*.cy.ts'",
33-
"tags:or": "PROJECT_NAME=tags-or node ../../scripts/cypress.js run --env grepTags='regression high' --config specPattern='**/tags/*.cy.ts'",
34-
"this": "PROJECT_NAME=this node ../../scripts/cypress.js run --env grep='this context' --config specPattern='**/this.cy.ts'",
35-
"untagged": "PROJECT_NAME=untagged node ../../scripts/cypress.js run --env grepUntagged=true --config specPattern='**/tags/*.cy.ts'"
22+
"tags:inverted": "PROJECT_NAME=tag-inverted node ../../scripts/cypress.js run --expose grepTags='-regression' --config specPattern='**/tags/*.cy.ts'",
23+
"tags": "PROJECT_NAME=tags node ../../scripts/cypress.js run --expose grepTags=smoke --config specPattern='**/tags/*.cy.ts'",
24+
"tags:and": "PROJECT_NAME=tags-and node ../../scripts/cypress.js run --expose grepTags='smoke+high' --config specPattern='**/tags/*.cy.ts'",
25+
"tags:and:not": "PROJECT_NAME=tags-and-not node ../../scripts/cypress.js run --expose grepTags='smoke+-high' --config specPattern='**/tags/*.cy.ts'",
26+
"tags:before": "PROJECT_NAME=tags-before node ../../scripts/cypress.js run --expose grepTags=@staging --config specPattern='**/before.cy.ts'",
27+
"tags:config": "PROJECT_NAME=tags-config node ../../scripts/cypress.js run --expose grepTags=config --config specPattern='**/config-tags.cy.ts'",
28+
"tags:describe": "PROJECT_NAME=tags-describe node ../../scripts/cypress.js run --expose grepTags=@smoke --config specPattern='**/describe-tags.cy.ts'",
29+
"tags:filter:specs": "PROJECT_NAME=tags-filter-specs node ../../scripts/cypress.js run --expose grepTags='regression',grepFilterSpecs=true --config specPattern='**/tags/*.cy.ts'",
30+
"tags:inherit": "PROJECT_NAME=tags-inherit node ../../scripts/cypress.js run --expose grepTags=@screen-b --config specPattern='**/inherits-tag.cy.ts'",
31+
"tags:nested-describe": "PROJECT_NAME=tags-nested-describe node ../../scripts/cypress.js run --expose grepTags='@smoke @integration' --config specPattern='**/nested-describe.cy.ts'",
32+
"tags:omit:specs": "PROJECT_NAME=tags-omit-specs node ../../scripts/cypress.js run --expose grepTags='regression',grepOmitFiltered=true --config specPattern='**/tags/*.cy.ts'",
33+
"tags:or": "PROJECT_NAME=tags-or node ../../scripts/cypress.js run --expose grepTags='regression high' --config specPattern='**/tags/*.cy.ts'",
34+
"this": "PROJECT_NAME=this node ../../scripts/cypress.js run --expose grep='this context' --config specPattern='**/this.cy.ts'",
35+
"untagged": "PROJECT_NAME=untagged node ../../scripts/cypress.js run --expose grepUntagged=true --config specPattern='**/tags/*.cy.ts'"
3636
},
3737
"dependencies": {
3838
"debug": "^4.3.4",
@@ -46,7 +46,7 @@
4646
"typescript": "~5.4.5"
4747
},
4848
"peerDependencies": {
49-
"cypress": ">=10"
49+
"cypress": ">=15.10.0"
5050
},
5151
"exports": {
5252
".": {

npm/grep/src/plugin.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { parseGrep, shouldTestRun } from './utils'
77
const debug = debugModule('@cypress/grep')
88

99
interface CypressConfigOptions {
10-
env?: Record<string, any>
10+
expose?: Record<string, any>
1111
specPattern?: string | string[]
1212
excludeSpecPattern?: string | string[]
1313
}
@@ -17,11 +17,11 @@ interface CypressConfigOptions {
1717
* @param {Cypress.ConfigOptions} config
1818
*/
1919
export function plugin (config: CypressConfigOptions): CypressConfigOptions {
20-
if (!config || !config.env) {
20+
if (!config || !config.expose) {
2121
return config
2222
}
2323

24-
const { env } = config
24+
const { expose } = config
2525

2626
if (!config.specPattern) {
2727
throw new Error(
@@ -30,15 +30,15 @@ export function plugin (config: CypressConfigOptions): CypressConfigOptions {
3030
}
3131

3232
debug('@cypress/grep plugin version %s', version)
33-
debug('Cypress config env object: %o', env)
33+
debug('Cypress config expose object: %o', expose)
3434

35-
const grep = env.grep ? String(env.grep) : undefined
35+
const grep = expose.grep ? String(expose.grep) : undefined
3636

3737
if (grep) {
3838
console.log('@cypress/grep: tests with "%s" in their names', grep.trim())
3939
}
4040

41-
const grepTags = env.grepTags || env['grep-tags']
41+
const grepTags = expose.grepTags || expose['grep-tags']
4242

4343
if (grepTags) {
4444
console.log('@cypress/grep: filtering using tag(s) "%s"', grepTags)
@@ -47,28 +47,28 @@ export function plugin (config: CypressConfigOptions): CypressConfigOptions {
4747
debug('parsed grep tags %o', parsedGrep.tags)
4848
}
4949

50-
const grepBurn = env.grepBurn || env['grep-burn'] || env.burn
50+
const grepBurn = expose.grepBurn || expose['grep-burn'] || expose.burn
5151

5252
if (grepBurn) {
5353
console.log('@cypress/grep: running filtered tests %d times', grepBurn)
5454
}
5555

56-
const grepUntagged = env.grepUntagged || env['grep-untagged']
56+
const grepUntagged = expose.grepUntagged || expose['grep-untagged']
5757

5858
if (grepUntagged) {
5959
console.log('@cypress/grep: running untagged tests')
6060
}
6161

62-
const omitFiltered = env.grepOmitFiltered || env['grep-omit-filtered']
62+
const omitFiltered = expose.grepOmitFiltered || expose['grep-omit-filtered']
6363

6464
if (omitFiltered) {
6565
console.log('@cypress/grep: will omit filtered tests')
6666
}
6767

6868
const { specPattern, excludeSpecPattern } = config
69-
const integrationFolder = env.grepIntegrationFolder || process.cwd()
69+
const integrationFolder = expose.grepIntegrationFolder || process.cwd()
7070

71-
const grepFilterSpecs = env.grepFilterSpecs === true || String(env.grepFilterSpecs).toLowerCase() === 'true'
71+
const grepFilterSpecs = expose.grepFilterSpecs === true || String(expose.grepFilterSpecs).toLowerCase() === 'true'
7272

7373
if (grepFilterSpecs) {
7474
debug('specPattern', specPattern)

0 commit comments

Comments
 (0)