@bahmutov/cy-grep 1.11.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-13.13.0-brightgreen)
1
+ # @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-13.15.0-brightgreen)
2
2
 
3
3
  > Filter tests using substring or tag
4
4
 
@@ -30,6 +30,9 @@ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=H
30
30
  - [Lesson k5: Filter the tests to run using OR of several tags](https://cypress.tips/courses/cypress-plugins/lessons/k5)
31
31
  - [Lesson k6: Repeat selected tests N times](https://cypress.tips/courses/cypress-plugins/lessons/k6)
32
32
  - [Lesson k7: Pick the tests to run in the interactive mode](https://cypress.tips/courses/cypress-plugins/lessons/k7)
33
+ - [Lesson k8: Automatically prefix tags with the "@" character](https://cypress.tips/courses/cypress-plugins/lessons/k8)
34
+ - [Lesson k9: Set baseUrl depending on the test tag](https://cypress.tips/courses/cypress-plugins/lessons/k9)
35
+ - [Lesson k10: Limit test tags to specific values](https://cypress.tips/courses/cypress-plugins/lessons/k10)
33
36
 
34
37
  ## Table of Contents
35
38
 
@@ -76,6 +79,8 @@ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=H
76
79
  - [Examples](#examples)
77
80
  - [See also](#see-also)
78
81
  - [cy-grep vs cypress-grep vs @cypress/grep](#cy-grep-vs-cypress-grep-vs-cypressgrep)
82
+ - [Major migrations](#major-migrations)
83
+ - [v1 to v2](#v1-to-v2)
79
84
  - [Small Print](#small-print)
80
85
 
81
86
  <!-- /MarkdownTOC -->
@@ -559,23 +564,41 @@ it('runs on deploy', { tags: 'smoke' }, () => {
559
564
  })
560
565
  ```
561
566
 
562
- This package comes with [src/index.d.ts](./src/index.d.ts) definition file that adds the property `tags` to the Cypress test overrides interface. Include this file in your specs or TS config settings. For example, you can load it using a reference comment
563
-
564
- ```js
565
- // cypress/integration/my-spec.js
566
- /// <reference types="@bahmutov/cy-grep" />
567
- ```
568
-
569
- If you have `tsconfig.json` file, add this library to the types list
567
+ If you want to allow any strings to be test tags, simply include [src/tags-are-strings.d.ts](./src/tags-are-strings.d.ts) included with this package in your project TS config:
570
568
 
571
569
  ```json
572
570
  {
571
+ "include": [
572
+ "cypress/**/*",
573
+ "node_modules/@bahmutov/cy-grep/src/tags-are-strings.d.ts"
574
+ ],
573
575
  "compilerOptions": {
574
- "target": "es5",
575
- "lib": ["es5", "dom"],
576
576
  "types": ["cypress", "@bahmutov/cy-grep"]
577
- },
578
- "include": ["**/*.ts"]
577
+ }
578
+ }
579
+ ```
580
+
581
+ If you want to provide your _own_ list of allowed tags, create a `.d.ts` file or extend your `index.d.ts` file
582
+
583
+ ```ts
584
+ // your project's index.d.ts file
585
+ /// <reference types="cypress" />
586
+
587
+ /**
588
+ * The only allowed test tags in this project
589
+ */
590
+ type AllowedTag = '@smoke' | '@misc' | '@new-todo'
591
+
592
+ declare namespace Cypress {
593
+ interface SuiteConfigOverrides {
594
+ tags?: AllowedTag | AllowedTag[]
595
+ requiredTags?: AllowedTag | AllowedTag[]
596
+ }
597
+
598
+ interface TestConfigOverrides {
599
+ tags?: AllowedTag | AllowedTag[]
600
+ requiredTags?: AllowedTag | AllowedTag[]
601
+ }
579
602
  }
580
603
  ```
581
604
 
@@ -742,6 +765,45 @@ Many years ago I wrote a plugin `cypress-grep`. When I left the company Cypress,
742
765
 
743
766
  I plan to maintain the plugin `@bahmutov/cy-grep` in the future, since I rely on it myself **a lot**.
744
767
 
768
+ ## Major migrations
769
+
770
+ ### v1 to v2
771
+
772
+ Adding a type for `tags` and `requiredTags` moved from default to its own `.d.ts` file.
773
+
774
+ **v1**
775
+
776
+ For example, the plugin `@bahmutov/cy-grep@v1` simply could add itself to the `types` list in your `tsconfig.json` / `jsconfig.json` file
777
+
778
+ ```json
779
+ {
780
+ "include": ["cypress/**/*"],
781
+ "compilerOptions": {
782
+ "types": ["cypress", "@bahmutov/cy-grep"]
783
+ }
784
+ }
785
+ ```
786
+
787
+ This made `tags` property a string, so you could use `it('works', { tags: '@smoke' }, () => ...)`
788
+
789
+ **v2**
790
+
791
+ If you want to use _any_ strings as tags, you need to add the file [src/tags-are-strings.d.ts](./src/tags-are-strings.d.ts)
792
+
793
+ ```json
794
+ {
795
+ "include": [
796
+ "cypress/**/*",
797
+ "node_modules/@bahmutov/cy-grep/src/tags-are-strings.d.ts"
798
+ ],
799
+ "compilerOptions": {
800
+ "types": ["cypress", "@bahmutov/cy-grep"]
801
+ }
802
+ }
803
+ ```
804
+
805
+ **Note:** you still want to include the `@bahmutov/cy-grep` default types, since they provide additional static methods, like `Cypress.grep`
806
+
745
807
  ## Small Print
746
808
 
747
809
  Author: Gleb Bahmutov &lt;gleb.bahmutov@gmail.com&gt; &copy; 2022
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bahmutov/cy-grep",
3
- "version": "1.11.6",
3
+ "version": "2.0.0",
4
4
  "description": "Filter Cypress tests using title or tags",
5
5
  "main": "src/support.js",
6
6
  "scripts": {
@@ -20,11 +20,11 @@
20
20
  "globby": "^11.1.0"
21
21
  },
22
22
  "devDependencies": {
23
- "cypress": "13.15.0",
23
+ "cypress": "13.17.0",
24
24
  "cypress-each": "^1.11.0",
25
25
  "cypress-expect": "^3.1.0",
26
26
  "prettier": "^3.0.0",
27
- "semantic-release": "^24.1.2",
27
+ "semantic-release": "^24.2.0",
28
28
  "stop-only": "^3.3.1",
29
29
  "typescript": "^5.0.0"
30
30
  },
package/src/index.d.ts CHANGED
@@ -1,44 +1,6 @@
1
1
  /// <reference types="cypress" />
2
2
 
3
3
  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
- * @see https://github.com/bahmutov/cy-grep
12
- */
13
- tags?: string | string[]
14
- /**
15
- * Provide a tag or a list of tags that is required for this suite to run.
16
- * @example describe('mobile tests', { requiredTags: '@mobile' }, () => {})
17
- * @see https://github.com/bahmutov/cy-grep
18
- */
19
- requiredTags?: string | string[]
20
- }
21
-
22
- // specify additional properties in the TestConfig object
23
- // in our case we will add "tags" property
24
- interface TestConfigOverrides {
25
- /**
26
- * List of tags for this test
27
- * @example a single tag
28
- * it('logs in', { tags: '@smoke' }, () => { ... })
29
- * @example multiple tags
30
- * it('works', { tags: ['@smoke', '@slow'] }, () => { ... })
31
- * @see https://github.com/bahmutov/cy-grep
32
- */
33
- tags?: string | string[]
34
- /**
35
- * Provide a tag or a list of tags that is required for this test to run.
36
- * @example it('cleans the data', { requiredTags: '@nightly' }, () => {})
37
- * @see https://github.com/bahmutov/cy-grep
38
- */
39
- requiredTags?: string | string[]
40
- }
41
-
42
4
  interface Cypress {
43
5
  /**
44
6
  * Runs only the tests that contain the given "grep" string
@@ -0,0 +1,45 @@
1
+ /// <reference types="cypress" />
2
+
3
+ // default types for test "tags" and "requiredTags" properties
4
+ // tags could be a single string or an array of strings
5
+ // see https://github.com/bahmutov/cy-grep?tab=readme-ov-file#typescript-support
6
+
7
+ declare namespace Cypress {
8
+ interface SuiteConfigOverrides {
9
+ /**
10
+ * List of tags for this suite
11
+ * @example a single tag
12
+ * describe('block with config tag', { tags: '@smoke' }, () => {})
13
+ * @example multiple tags
14
+ * describe('block with config tag', { tags: ['@smoke', '@slow'] }, () => {})
15
+ * @see https://github.com/bahmutov/cy-grep
16
+ */
17
+ tags?: string | string[]
18
+ /**
19
+ * Provide a tag or a list of tags that is required for this suite to run.
20
+ * @example describe('mobile tests', { requiredTags: '@mobile' }, () => {})
21
+ * @see https://github.com/bahmutov/cy-grep
22
+ */
23
+ requiredTags?: string | string[]
24
+ }
25
+
26
+ // specify additional properties in the TestConfig object
27
+ // in our case we will add "tags" property
28
+ interface TestConfigOverrides {
29
+ /**
30
+ * List of tags for this test
31
+ * @example a single tag
32
+ * it('logs in', { tags: '@smoke' }, () => { ... })
33
+ * @example multiple tags
34
+ * it('works', { tags: ['@smoke', '@slow'] }, () => { ... })
35
+ * @see https://github.com/bahmutov/cy-grep
36
+ */
37
+ tags?: string | string[]
38
+ /**
39
+ * Provide a tag or a list of tags that is required for this test to run.
40
+ * @example it('cleans the data', { requiredTags: '@nightly' }, () => {})
41
+ * @see https://github.com/bahmutov/cy-grep
42
+ */
43
+ requiredTags?: string | string[]
44
+ }
45
+ }