Skip to content

Commit c83df82

Browse files
committed
breaking: convert @cypress/grep to TypeScript and change what is exported
BREAKING CHANGE: @cypress/grep now exports a register function that can be imported from the users spec file. Additionally, the plugin can be imported via @cypress/grep/plugin.
1 parent d35349b commit c83df82

35 files changed

+595
-555
lines changed

.circleci/src/workflows/@workflows.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,9 +2368,34 @@ jobs:
23682368
resource_class: small
23692369
steps:
23702370
- restore_cached_workspace
2371+
- run: yarn workspace @cypress/grep cypress:run:tags:before
2372+
- run: yarn workspace @cypress/grep cypress:run:tags:describe
2373+
- run: yarn workspace @cypress/grep cypress:run:tags:config
2374+
- run: yarn workspace @cypress/grep cypress:run:burn
2375+
- run: yarn workspace @cypress/grep cypress:run:tags:inherit
2376+
- run: yarn workspace @cypress/grep cypress:run:multiple-registrations
2377+
- run: yarn workspace @cypress/grep cypress:run:tags:nested-describe
2378+
- run: yarn workspace @cypress/grep cypress:run:skip
2379+
- run: yarn workspace @cypress/grep cypress:run:this
2380+
- run: yarn workspace @cypress/grep cypress:run:tags
2381+
- run: yarn workspace @cypress/grep cypress:run:each
2382+
- run: yarn workspace @cypress/grep cypress:run:grep
2383+
- run: yarn workspace @cypress/grep cypress:run:tags:or
2384+
- run: yarn workspace @cypress/grep cypress:run:tags:and
2385+
- run: yarn workspace @cypress/grep cypress:run:tags:and:not
2386+
- run: yarn workspace @cypress/grep cypress:run:or
2387+
- run: yarn workspace @cypress/grep cypress:run:and
2388+
- run: yarn workspace @cypress/grep cypress:run:and:not
2389+
- run: yarn workspace @cypress/grep cypress:run:filter:specs
2390+
- run: yarn workspace @cypress/grep cypress:run:tags:filter:specs
2391+
- run: yarn workspace @cypress/grep cypress:run:omit:specs
2392+
- run: yarn workspace @cypress/grep cypress:run:tags:omit:specs
2393+
- run: yarn workspace @cypress/grep cypress:run:untagged
2394+
- run: yarn workspace @cypress/grep cypress:run:tag:inverted
2395+
- run: yarn workspace @cypress/grep cypress:run:inverted
23712396
- run:
2372-
name: Run tests
2373-
command: yarn workspace @cypress/grep cy:run
2397+
name: Run unit tests
2398+
command: yarn workspace @cypress/grep test
23742399
- sanitize-verify-and-store-mocha-results:
23752400
testResultsPath: npm/grep/test_results
23762401

.circleci/workflows.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,9 +2002,34 @@ jobs:
20022002
resource_class: small
20032003
steps:
20042004
- restore_cached_workspace
2005-
- run:
2006-
command: yarn workspace @cypress/grep cy:run
2007-
name: Run tests
2005+
- run: yarn workspace @cypress/grep cypress:run:tags:before
2006+
- run: yarn workspace @cypress/grep cypress:run:tags:describe
2007+
- run: yarn workspace @cypress/grep cypress:run:tags:config
2008+
- run: yarn workspace @cypress/grep cypress:run:burn
2009+
- run: yarn workspace @cypress/grep cypress:run:tags:inherit
2010+
- run: yarn workspace @cypress/grep cypress:run:multiple-registrations
2011+
- run: yarn workspace @cypress/grep cypress:run:tags:nested-describe
2012+
- run: yarn workspace @cypress/grep cypress:run:skip
2013+
- run: yarn workspace @cypress/grep cypress:run:this
2014+
- run: yarn workspace @cypress/grep cypress:run:tags
2015+
- run: yarn workspace @cypress/grep cypress:run:each
2016+
- run: yarn workspace @cypress/grep cypress:run:grep
2017+
- run: yarn workspace @cypress/grep cypress:run:tags:or
2018+
- run: yarn workspace @cypress/grep cypress:run:tags:and
2019+
- run: yarn workspace @cypress/grep cypress:run:tags:and:not
2020+
- run: yarn workspace @cypress/grep cypress:run:or
2021+
- run: yarn workspace @cypress/grep cypress:run:and
2022+
- run: yarn workspace @cypress/grep cypress:run:and:not
2023+
- run: yarn workspace @cypress/grep cypress:run:filter:specs
2024+
- run: yarn workspace @cypress/grep cypress:run:tags:filter:specs
2025+
- run: yarn workspace @cypress/grep cypress:run:omit:specs
2026+
- run: yarn workspace @cypress/grep cypress:run:tags:omit:specs
2027+
- run: yarn workspace @cypress/grep cypress:run:untagged
2028+
- run: yarn workspace @cypress/grep cypress:run:tag:inverted
2029+
- run: yarn workspace @cypress/grep cypress:run:inverted
2030+
- run:
2031+
command: yarn workspace @cypress/grep test
2032+
name: Run unit tests
20082033
- sanitize-verify-and-store-mocha-results:
20092034
testResultsPath: npm/grep/test_results
20102035
working_directory: ~/cypress

npm/grep/README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ yarn add --dev @cypress/grep
3737

3838
```js
3939
// cypress/support/e2e.js
40-
const registerCypressGrep = require('@cypress/grep')
40+
const { register: registerCypressGrep } = require('@cypress/grep')
4141
registerCypressGrep()
4242
```
4343

4444
Or using ES modules / TypeScript:
4545

4646
```ts
4747
// cypress/support/e2e.ts
48-
import registerCypressGrep from '@cypress/grep/src/support'
48+
import { register as registerCypressGrep } from '@cypress/grep'
4949
registerCypressGrep()
5050
```
5151

@@ -60,7 +60,24 @@ const { defineConfig } = require('cypress')
6060
module.exports = defineConfig({
6161
e2e: {
6262
setupNodeEvents(on, config) {
63-
require('@cypress/grep/src/plugin')(config)
63+
const { plugin: cypressGrepPlugin } = require('@cypress/grep/plugin')
64+
cypressGrepPlugin(config)
65+
return config
66+
},
67+
},
68+
})
69+
```
70+
71+
Or using ES modules / TypeScript:
72+
73+
```ts
74+
// cypress.config.ts
75+
import { plugin as cypressGrepPlugin } from '@cypress/grep/plugin'
76+
77+
export default defineConfig({
78+
e2e: {
79+
setupNodeEvents(on, config) {
80+
cypressGrepPlugin(config)
6481
return config
6582
},
6683
},
@@ -227,9 +244,10 @@ npx cypress run --env grepUntagged=true
227244
### In cypress.config.js
228245

229246
```js
230-
const { defineConfig } = require('cypress')
247+
import { defineConfig } from 'cypress'
248+
import { plugin as cypressGrepPlugin } from '@cypress/grep/plugin'
231249

232-
module.exports = defineConfig({
250+
export default defineConfig({
233251
env: {
234252
// Always filter by viewport tests
235253
grep: "viewport",
@@ -240,7 +258,7 @@ module.exports = defineConfig({
240258
},
241259
e2e: {
242260
setupNodeEvents(on, config) {
243-
require('@cypress/grep/src/plugin')(config)
261+
cypressGrepPlugin(config)
244262
return config
245263
},
246264
},
@@ -262,6 +280,10 @@ module.exports = defineConfig({
262280

263281
## TypeScript Support
264282

283+
As of v5 of `@cypress/grep`, TypeScript declaration files are now included.
284+
These definitions should be automatically detected, but in the case you are using
285+
an older `moduleResolution` or configuration, some of the below techniques should work.
286+
265287
### Option 1: Reference types (Recommended)
266288

267289
```js
@@ -400,16 +422,40 @@ Then refresh and run tests.
400422

401423
## Migration
402424

403-
### From v1 to v2
425+
### From v4 to v5
404426

405-
- `--env grep="tag1 tag2"``--env grepTags="tag1 tag2"`
406-
- Title filtering and tag filtering are now separate
427+
The support file registration and plugin have changed their export signature, meaning:
407428

408-
### From v2 to v3+
429+
In your support file, change the registration function from
430+
```js
431+
const registerCypressGrep = require('@cypress/grep')
432+
```
433+
434+
to the following
435+
```js
436+
const { register: registerCypressGrep } = require('@cypress/grep')
437+
```
438+
439+
Additionally, in your support file, change the plugin registration from
440+
```js
441+
const cypressGrepPlugin = require('@cypress/grep/src/plugin')
442+
```
443+
444+
to the following
445+
```js
446+
const { plugin: cypressGrepPlugin } = require('@cypress/grep/plugin')
447+
```
448+
449+
### From v2 to v3/v4
409450

410451
- Requires Cypress 10.0.0+
411452
- No breaking changes in functionality
412453

454+
### From v1 to v2
455+
456+
- `--env grep="tag1 tag2"``--env grepTags="tag1 tag2"`
457+
- Title filtering and tag filtering are now separate
458+
413459
## Support
414460

415461
- **Documentation**: [Cypress Docs](https://docs.cypress.io)

npm/grep/cypress.config.js renamed to npm/grep/cypress.config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { defineConfig } = require('cypress')
2-
const cypressGrepPlugin = require('./src/plugin')
1+
import { defineConfig } from 'cypress'
2+
import { plugin as cypressGrepPlugin } from './src/plugin'
33

4-
module.exports = defineConfig({
4+
export default defineConfig({
55
e2e: {
66
defaultCommandTimeout: 1000,
77
setupNodeEvents (on, config) {
@@ -15,7 +15,6 @@ module.exports = defineConfig({
1515

1616
return config
1717
},
18-
specPattern: '**/spec.js',
1918
},
2019
fixturesFolder: false,
2120
})
File renamed without changes.

npm/grep/cypress/e2e/burn-spec.js renamed to npm/grep/cypress/e2e/burn.cy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="cypress" />
2-
31
// if we specify just the burn parameter
42
// then this test will be repeated N times
53
describe('burning a test N times', () => {

npm/grep/cypress/e2e/config-tags-spec.js renamed to npm/grep/cypress/e2e/config-tags.cy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
/// <reference path="../../src/index.d.ts" />
31
describe('tags in the config object', () => {
42
it('works as an array', { tags: ['config', 'some-other-tag'] }, () => {
53
expect(true).to.be.true

npm/grep/cypress/e2e/config-spec.js renamed to npm/grep/cypress/e2e/config.cy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
/// <reference types="cypress" />
31
describe('tests that use config object', () => {
42
it('still works @config', { baseUrl: 'http://localhost:8000' }, () => {
53
expect(Cypress.config('baseUrl')).to.equal('http://localhost:8000')

npm/grep/cypress/e2e/describe-tags-spec.js renamed to npm/grep/cypress/e2e/describe-tags.cy.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/// <reference path="../../src/index.d.ts" />
2-
3-
// @ts-check
4-
51
describe('block with no tags', () => {
62
it('inside describe 1', () => {})
73

npm/grep/cypress/e2e/each-spec.js renamed to npm/grep/cypress/e2e/each.cy.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="cypress" />
2-
31
// https://github.com/bahmutov/cypress-each
42
import 'cypress-each'
53

0 commit comments

Comments
 (0)