Skip to content

Commit 55058e7

Browse files
authored
fix(grep): @cypress/grep types (#24844)
Co-authored-by: Jordan <jordan@jpdesigning.com> Closes undefined Fixes #24512
1 parent 3a46679 commit 55058e7

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

npm/grep/README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ yarn add -D @cypress/grep
7979

8080
### Support file
8181

82-
**required:** load this module from the [support file](https://on.cypress.io/writing-and-organizing-tests#Support-file) or at the top of the spec file if not using the support file. You improve the registration function and then call it:
82+
**required:** load this module from the [support file](https://on.cypress.io/writing-and-organizing-tests#Support-file) or at the top of the spec file if not using the support file. You import the registration function and then call it:
8383

8484
```js
8585
// cypress/support/index.js
@@ -89,6 +89,16 @@ const registerCypressGrep = require('@cypress/grep')
8989
registerCypressGrep()
9090

9191
// if you want to use the "import" keyword
92+
// note: `./index.d.ts` currently extends the global Cypress types and
93+
// does not define `registerCypressGrep` so the import path is directly
94+
// pointed to the `support.js` file
95+
import registerCypressGrep from '@cypress/grep/src/support'
96+
registerCypressGrep()
97+
98+
99+
// "import" with `@ts-ignore`
100+
// @see error 2306 https://github.com/microsoft/TypeScript/blob/3fcd1b51a1e6b16d007b368229af03455c7d5794/src/compiler/diagnosticMessages.json#L1635
101+
// @ts-ignore
92102
import registerCypressGrep from '@cypress/grep'
93103
registerCypressGrep()
94104
```
@@ -207,7 +217,7 @@ $ npx cypress run --env grep="-hello world"
207217
$ npx cypress run --env grep="hello; -world"
208218
```
209219

210-
**Note:** Inverted title filter is not compativle with the `grepFilterSpecs` option
220+
**Note:** Inverted title filter is not compatible with the `grepFilterSpecs` option
211221

212222
## Filter with tags
213223

@@ -277,7 +287,7 @@ If you want to run all tests with tag `@slow` but without tag `@smoke`:
277287
--env grepTags=@slow+-@smoke
278288
```
279289

280-
**Note:** Inverted tag filter is not compativle with the `grepFilterSpecs` option
290+
**Note:** Inverted tag filter is not compatible with the `grepFilterSpecs` option
281291

282292
### NOT tags
283293

@@ -417,7 +427,7 @@ This package comes with [src/index.d.ts](./src/index.d.ts) definition file that
417427

418428
```js
419429
// cypress/integration/my-spec.js
420-
/// <reference types="cypress-grep" />
430+
/// <reference types="@cypress/grep" />
421431
```
422432

423433
If you have `tsconfig.json` file, add this library to the types list
@@ -427,7 +437,7 @@ If you have `tsconfig.json` file, add this library to the types list
427437
"compilerOptions": {
428438
"target": "es5",
429439
"lib": ["es5", "dom"],
430-
"types": ["cypress", "cypress-grep"]
440+
"types": ["cypress", "@cypress/grep"]
431441
},
432442
"include": ["**/*.ts"]
433443
}

npm/grep/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@cypress/grep",
33
"version": "0.0.0-development",
44
"description": "Filter tests using substring",
5-
"main": "src/support",
5+
"main": "src/support.js",
66
"scripts": {
77
"cy:run": "node ../../scripts/cypress.js run --config specPattern='**/unit.js'",
88
"cy:open": "node ../../scripts/cypress.js open --e2e -b electron --config specPattern='**/unit.js'"

npm/grep/src/index.d.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
/// <reference types="cypress" />
22

33
declare namespace Cypress {
4+
interface SuiteConfigOverrides {
5+
/**
6+
* List of tags for this suite
7+
* @example a single tag
8+
* describe('block with config tag', { tags: '@smoke' }, () => {})
9+
* @example multiple tags
10+
* describe('block with config tag', { tags: ['@smoke', '@slow'] }, () => {})
11+
*/
12+
tags?: string | string[]
13+
}
14+
415
// specify additional properties in the TestConfig object
516
// in our case we will add "tags" property
617
interface TestConfigOverrides {
@@ -17,4 +28,4 @@ declare namespace Cypress {
1728
interface Cypress {
1829
grep?: (grep?: string, tags?: string, burn?: string) => void
1930
}
20-
}
31+
}

0 commit comments

Comments
 (0)