fix(grep): @cypress/grep types (#24844)

Co-authored-by: Jordan <jordan@jpdesigning.com>
Closes undefined
Fixes https://github.com/cypress-io/cypress/issues/24512
This commit is contained in:
Sam Tsai
2022-12-14 11:04:07 -05:00
committed by GitHub
parent 3a46679776
commit 55058e7783
3 changed files with 28 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ yarn add -D @cypress/grep
### Support file
**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:
**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:
```js
// cypress/support/index.js
@@ -89,6 +89,16 @@ const registerCypressGrep = require('@cypress/grep')
registerCypressGrep()
// if you want to use the "import" keyword
// note: `./index.d.ts` currently extends the global Cypress types and
// does not define `registerCypressGrep` so the import path is directly
// pointed to the `support.js` file
import registerCypressGrep from '@cypress/grep/src/support'
registerCypressGrep()
// "import" with `@ts-ignore`
// @see error 2306 https://github.com/microsoft/TypeScript/blob/3fcd1b51a1e6b16d007b368229af03455c7d5794/src/compiler/diagnosticMessages.json#L1635
// @ts-ignore
import registerCypressGrep from '@cypress/grep'
registerCypressGrep()
```
@@ -207,7 +217,7 @@ $ npx cypress run --env grep="-hello world"
$ npx cypress run --env grep="hello; -world"
```
**Note:** Inverted title filter is not compativle with the `grepFilterSpecs` option
**Note:** Inverted title filter is not compatible with the `grepFilterSpecs` option
## Filter with tags
@@ -277,7 +287,7 @@ If you want to run all tests with tag `@slow` but without tag `@smoke`:
--env grepTags=@slow+-@smoke
```
**Note:** Inverted tag filter is not compativle with the `grepFilterSpecs` option
**Note:** Inverted tag filter is not compatible with the `grepFilterSpecs` option
### NOT tags
@@ -417,7 +427,7 @@ This package comes with [src/index.d.ts](./src/index.d.ts) definition file that
```js
// cypress/integration/my-spec.js
/// <reference types="cypress-grep" />
/// <reference types="@cypress/grep" />
```
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
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "cypress-grep"]
"types": ["cypress", "@cypress/grep"]
},
"include": ["**/*.ts"]
}

View File

@@ -2,7 +2,7 @@
"name": "@cypress/grep",
"version": "0.0.0-development",
"description": "Filter tests using substring",
"main": "src/support",
"main": "src/support.js",
"scripts": {
"cy:run": "node ../../scripts/cypress.js run --config specPattern='**/unit.js'",
"cy:open": "node ../../scripts/cypress.js open --e2e -b electron --config specPattern='**/unit.js'"

View File

@@ -1,6 +1,17 @@
/// <reference types="cypress" />
declare namespace Cypress {
interface SuiteConfigOverrides {
/**
* List of tags for this suite
* @example a single tag
* describe('block with config tag', { tags: '@smoke' }, () => {})
* @example multiple tags
* describe('block with config tag', { tags: ['@smoke', '@slow'] }, () => {})
*/
tags?: string | string[]
}
// specify additional properties in the TestConfig object
// in our case we will add "tags" property
interface TestConfigOverrides {
@@ -17,4 +28,4 @@ declare namespace Cypress {
interface Cypress {
grep?: (grep?: string, tags?: string, burn?: string) => void
}
}
}