@bahmutov/cy-grep 1.3.1 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -1
- package/package.json +5 -5
- package/src/plugin.js +27 -0
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-12.
|
1
|
+
# @bahmutov/cy-grep ![cypress version](https://img.shields.io/badge/cypress-12.4.1-brightgreen)
|
2
2
|
|
3
3
|
> Filter tests using substring or tag
|
4
4
|
|
@@ -430,6 +430,10 @@ it('cleans up the data', { requiredTags: '@nightly' }, () => {...})
|
|
430
430
|
|
431
431
|
When you run the tests now, this test will be skipped, as if it were `it.skip`. It will only run if you use the tag `@nightly`, for example: `npx cypress run --env grepTags=@nightly`.
|
432
432
|
|
433
|
+
If `grepFilterSpecs=true` and a spec has only required tags, and you are running without any tags, the the spec will be skipped completely.
|
434
|
+
|
435
|
+
Read the blog post 📝 [Required Tags](https://glebbahmutov.com/blog/required-tags/).
|
436
|
+
|
433
437
|
## TypeScript support
|
434
438
|
|
435
439
|
Because the Cypress test config object type definition does not have the `tags` property we are using above, the TypeScript linter will show an error. Just add an ignore comment above the test:
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bahmutov/cy-grep",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.4.1",
|
4
4
|
"description": "Filter Cypress tests using title or tags",
|
5
5
|
"main": "src/support.js",
|
6
6
|
"scripts": {
|
@@ -12,15 +12,15 @@
|
|
12
12
|
"dependencies": {
|
13
13
|
"cypress-plugin-config": "^1.2.0",
|
14
14
|
"debug": "^4.3.2",
|
15
|
-
"find-test-names": "1.25.
|
15
|
+
"find-test-names": "1.25.1",
|
16
16
|
"globby": "^11.0.4"
|
17
17
|
},
|
18
18
|
"devDependencies": {
|
19
|
-
"cypress": "12.
|
19
|
+
"cypress": "12.4.1",
|
20
20
|
"cypress-each": "^1.11.0",
|
21
|
-
"cypress-expect": "^
|
21
|
+
"cypress-expect": "^3.1.0",
|
22
22
|
"prettier": "^2.8.1",
|
23
|
-
"semantic-release": "^20.0
|
23
|
+
"semantic-release": "^20.1.0",
|
24
24
|
"typescript": "^4.7.4"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
package/src/plugin.js
CHANGED
@@ -143,6 +143,33 @@ function cypressGrepPlugin(config) {
|
|
143
143
|
|
144
144
|
debug('found grep tags "%s" in %d specs', grepTags, greppedSpecs.length)
|
145
145
|
debug('%o', greppedSpecs)
|
146
|
+
} else {
|
147
|
+
// we have no tags to grep
|
148
|
+
debug('will try eliminating specs with required tags')
|
149
|
+
|
150
|
+
greppedSpecs = specFiles.filter((specFile) => {
|
151
|
+
const text = fs.readFileSync(specFile, { encoding: 'utf8' })
|
152
|
+
|
153
|
+
try {
|
154
|
+
const testTags = findEffectiveTestTags(text)
|
155
|
+
debug('spec file %s', specFile)
|
156
|
+
debug('effective test tags %o', testTags)
|
157
|
+
// eliminate all tests with required tags, since we have no tags right now
|
158
|
+
const testsWithoutRequiredTags = Object.keys(testTags).filter(
|
159
|
+
(testTitle) => {
|
160
|
+
return testTags[testTitle].requiredTags.length === 0
|
161
|
+
},
|
162
|
+
)
|
163
|
+
// if there are any tests remaining, we should run this spec
|
164
|
+
// (we should not run empty specs where all tests have required tags)
|
165
|
+
return testsWithoutRequiredTags.length
|
166
|
+
} catch (err) {
|
167
|
+
console.error('Could not determine test names in file: %s', specFile)
|
168
|
+
console.error('Will run it to let the grep filter the tests')
|
169
|
+
|
170
|
+
return true
|
171
|
+
}
|
172
|
+
})
|
146
173
|
}
|
147
174
|
|
148
175
|
if (greppedSpecs.length) {
|