@bahmutov/cy-grep 1.10.0 → 1.11.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 +10 -1
- package/package.json +3 -2
- package/src/file-utils.js +35 -0
- package/src/plugin.js +18 -0
- package/src/support.js +7 -0
package/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# @bahmutov/cy-grep 
|
2
2
|
|
3
3
|
> Filter tests using substring or tag
|
4
4
|
|
@@ -60,6 +60,7 @@ Watch the video [intro to cypress-grep plugin](https://www.youtube.com/watch?v=H
|
|
60
60
|
- [Omit filtered tests (grepOmitFiltered)](#omit-filtered-tests-grepomitfiltered)
|
61
61
|
- [Disable grep](#disable-grep)
|
62
62
|
- [Burn (repeat) tests](#burn-repeat-tests)
|
63
|
+
- [grepExtraSpecs](#grepextraspecs)
|
63
64
|
- [Required tags](#required-tags)
|
64
65
|
- [Negative grep](#negative-grep)
|
65
66
|
- [TypeScript support](#typescript-support)
|
@@ -505,6 +506,14 @@ You can pass the number of times to run the tests via environment name `burn` or
|
|
505
506
|
|
506
507
|
If you do not specify the "grep" or "grep tags" option, the "burn" will repeat _every_ test.
|
507
508
|
|
509
|
+
## grepExtraSpecs
|
510
|
+
|
511
|
+
Sometimes you want to pre-filter specs using tags AND then run extra specs without any filtering. You can set the list of specs / patterns using the `grepExtraSpecs` env string. For example, to filter specs using tag `@a` plus run the spec "b.cy.js":
|
512
|
+
|
513
|
+
```
|
514
|
+
npx cypress run --env grepTags=@a,grepExtraSpecs=cypress/e2e/b.cy.js
|
515
|
+
```
|
516
|
+
|
508
517
|
## Required tags
|
509
518
|
|
510
519
|
Sometimes you might want to run a test or a suite of tests _only_ if a specific tag or tags are present. For example, you might have a test that cleans the data. This test is meant to run nightly, not on every test run. Thus you can set a `required` tag:
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bahmutov/cy-grep",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.11.0",
|
4
4
|
"description": "Filter Cypress tests using title or tags",
|
5
5
|
"main": "src/support.js",
|
6
6
|
"scripts": {
|
@@ -16,7 +16,8 @@
|
|
16
16
|
"cypress-plugin-config": "^1.2.0",
|
17
17
|
"debug": "^4.3.2",
|
18
18
|
"find-cypress-specs": "^1.35.1",
|
19
|
-
"find-test-names": "1.28.21"
|
19
|
+
"find-test-names": "1.28.21",
|
20
|
+
"globby": "^11.1.0"
|
20
21
|
},
|
21
22
|
"devDependencies": {
|
22
23
|
"cypress": "13.11.0",
|
@@ -0,0 +1,35 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
const globby = require('globby')
|
4
|
+
const debug = require('debug')('cy-grep')
|
5
|
+
|
6
|
+
function resolveFilePattern(pattern) {
|
7
|
+
if (pattern.includes('*')) {
|
8
|
+
const globbyOptions = {
|
9
|
+
sort: true,
|
10
|
+
objectMode: false,
|
11
|
+
}
|
12
|
+
debug('globby options "%s" %o', pattern, globbyOptions)
|
13
|
+
|
14
|
+
const files = globby.sync(pattern, globbyOptions)
|
15
|
+
debug('found %d file(s) %o', files.length, files)
|
16
|
+
return files
|
17
|
+
} else {
|
18
|
+
return pattern
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
function resolveFilePatterns(patterns) {
|
23
|
+
const extraSpecsList = patterns
|
24
|
+
.split(',')
|
25
|
+
.map((s) => s.trim())
|
26
|
+
.filter(Boolean)
|
27
|
+
debug('extra specs list %o', extraSpecsList)
|
28
|
+
|
29
|
+
return extraSpecsList.flatMap(resolveFilePattern)
|
30
|
+
}
|
31
|
+
|
32
|
+
module.exports = {
|
33
|
+
resolveFilePattern,
|
34
|
+
resolveFilePatterns,
|
35
|
+
}
|
package/src/plugin.js
CHANGED
@@ -7,6 +7,7 @@ const fs = require('fs')
|
|
7
7
|
const path = require('path')
|
8
8
|
const { version } = require('../package.json')
|
9
9
|
const { parseGrep, shouldTestRun, getMentionedTags } = require('./utils')
|
10
|
+
const { resolveFilePatterns } = require('./file-utils')
|
10
11
|
const minimatch = require('minimatch')
|
11
12
|
|
12
13
|
const MINIMATCH_OPTIONS = { dot: true, matchBase: true }
|
@@ -224,6 +225,23 @@ function cypressGrepPlugin(config) {
|
|
224
225
|
})
|
225
226
|
}
|
226
227
|
|
228
|
+
const extraSpecsPattern = config.env.grepExtraSpecs
|
229
|
+
if (extraSpecsPattern) {
|
230
|
+
debug('processing the extra specs pattern "%s"', extraSpecsPattern)
|
231
|
+
const extraSpecs = resolveFilePatterns(extraSpecsPattern)
|
232
|
+
// update the config env object with resolved extra specs
|
233
|
+
const resolvedExtraSpecs = []
|
234
|
+
extraSpecs.forEach((specFilename) => {
|
235
|
+
if (!greppedSpecs.includes(specFilename)) {
|
236
|
+
greppedSpecs.push(specFilename)
|
237
|
+
resolvedExtraSpecs.push(specFilename)
|
238
|
+
debug('added extra spec %s', specFilename)
|
239
|
+
}
|
240
|
+
})
|
241
|
+
|
242
|
+
config.env.grepExtraSpecs = resolvedExtraSpecs
|
243
|
+
}
|
244
|
+
|
227
245
|
if (greppedSpecs.length) {
|
228
246
|
if (isCypressV9(config)) {
|
229
247
|
debug('setting selected %d specs (< v10)', greppedSpecs.length)
|
package/src/support.js
CHANGED
@@ -58,6 +58,8 @@ function registerCyGrep() {
|
|
58
58
|
getPluginConfigValue('grepUntagged') ||
|
59
59
|
getPluginConfigValue('grep-untagged')
|
60
60
|
|
61
|
+
const extraSpecs = getPluginConfigValue('grepExtraSpecs')
|
62
|
+
|
61
63
|
// if (!grep && !grepTags && !burnSpecified && !grepUntagged) {
|
62
64
|
// nothing to do, the user has no specified the "grep" string
|
63
65
|
// debug('Nothing to grep, version %s', version)
|
@@ -125,6 +127,11 @@ function registerCyGrep() {
|
|
125
127
|
configRequiredTags = [configRequiredTags]
|
126
128
|
}
|
127
129
|
|
130
|
+
if (extraSpecs?.length && extraSpecs.includes(Cypress.spec.relative)) {
|
131
|
+
// the user wants to run all tests in this extra spec file
|
132
|
+
return _it(name, options, callback)
|
133
|
+
}
|
134
|
+
|
128
135
|
const nameToGrep = suiteStack
|
129
136
|
.map((item) => item.name)
|
130
137
|
.concat(name)
|