@bahmutov/cy-grep 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/package.json +4 -2
- package/src/plugin.js +42 -28
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.7.0-brightgreen)
|
2
2
|
|
3
3
|
> Filter tests using substring or tag
|
4
4
|
|
@@ -84,7 +84,7 @@ npm i -D @bahmutov/cy-grep
|
|
84
84
|
yarn add -D @bahmutov/cy-grep
|
85
85
|
```
|
86
86
|
|
87
|
-
**Note**: @bahmutov/cy-grep
|
87
|
+
**Note**: @bahmutov/cy-grep should work with all Cypress versions, but I mostly test it on the newest versions.
|
88
88
|
|
89
89
|
### Support file
|
90
90
|
|
package/package.json
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bahmutov/cy-grep",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.0",
|
4
4
|
"description": "Filter Cypress tests using title or tags",
|
5
5
|
"main": "src/support.js",
|
6
6
|
"scripts": {
|
7
7
|
"cy:run": "cypress run --config specPattern='**/unit.js'",
|
8
8
|
"cy:open": "cypress open --e2e -b electron --config specPattern='**/unit.js'",
|
9
9
|
"badges": "npx -p dependency-version-badge update-badge cypress",
|
10
|
-
"semantic-release": "semantic-release"
|
10
|
+
"semantic-release": "semantic-release",
|
11
|
+
"deps": "npm audit --report --omit dev"
|
11
12
|
},
|
12
13
|
"dependencies": {
|
13
14
|
"cypress-plugin-config": "^1.2.0",
|
14
15
|
"debug": "^4.3.2",
|
16
|
+
"find-cypress-specs": "^1.29.4",
|
15
17
|
"find-test-names": "1.28.1",
|
16
18
|
"globby": "^11.0.4"
|
17
19
|
},
|
package/src/plugin.js
CHANGED
@@ -1,27 +1,19 @@
|
|
1
|
+
// @ts-check
|
1
2
|
const debug = require('debug')('cy-grep')
|
2
3
|
const globby = require('globby')
|
4
|
+
|
5
|
+
const { getSpecs } = require('find-cypress-specs')
|
3
6
|
const { getTestNames, findEffectiveTestTags } = require('find-test-names')
|
4
7
|
const fs = require('fs')
|
8
|
+
const path = require('path')
|
5
9
|
const { version } = require('../package.json')
|
6
10
|
const { parseGrep, shouldTestRun } = require('./utils')
|
7
11
|
|
8
|
-
|
9
|
-
* Prints the cy-grep environment values if any.
|
10
|
-
* @param {Cypress.ConfigOptions} config
|
11
|
-
*/
|
12
|
-
function cypressGrepPlugin(config) {
|
13
|
-
if (!config || !config.env) {
|
14
|
-
return config
|
15
|
-
}
|
12
|
+
const isCypressV9 = (config) => !('specPattern' in config)
|
16
13
|
|
14
|
+
function getGrepSettings(config) {
|
17
15
|
const { env } = config
|
18
16
|
|
19
|
-
if (!config.specPattern) {
|
20
|
-
throw new Error(
|
21
|
-
'Incompatible versions detected, cy-grep requires Cypress 10.0.0+',
|
22
|
-
)
|
23
|
-
}
|
24
|
-
|
25
17
|
debug('cy-grep plugin version %s', version)
|
26
18
|
debug('Cypress config env object: %o', env)
|
27
19
|
|
@@ -58,20 +50,24 @@ function cypressGrepPlugin(config) {
|
|
58
50
|
console.log('cy-grep: will omit filtered tests')
|
59
51
|
}
|
60
52
|
|
61
|
-
const { specPattern, excludeSpecPattern } = config
|
62
|
-
const integrationFolder = env.grepIntegrationFolder || process.cwd()
|
63
|
-
|
64
53
|
const grepFilterSpecs = env.grepFilterSpecs === true
|
65
54
|
|
55
|
+
return { grep, grepTags, grepFilterSpecs }
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Prints the cy-grep environment values if any.
|
60
|
+
* @param {Cypress.ConfigOptions} config
|
61
|
+
*/
|
62
|
+
function cypressGrepPlugin(config) {
|
63
|
+
if (!config || !config.env) {
|
64
|
+
return config
|
65
|
+
}
|
66
|
+
|
67
|
+
const { grep, grepTags, grepFilterSpecs } = getGrepSettings(config)
|
68
|
+
|
66
69
|
if (grepFilterSpecs) {
|
67
|
-
|
68
|
-
debug('excludeSpecPattern', excludeSpecPattern)
|
69
|
-
debug('integrationFolder', integrationFolder)
|
70
|
-
const specFiles = globby.sync(specPattern, {
|
71
|
-
cwd: integrationFolder,
|
72
|
-
ignore: excludeSpecPattern,
|
73
|
-
absolute: true,
|
74
|
-
})
|
70
|
+
const specFiles = getSpecs(config)
|
75
71
|
|
76
72
|
debug('found %d spec files', specFiles.length)
|
77
73
|
debug('%o', specFiles)
|
@@ -86,7 +82,7 @@ function cypressGrepPlugin(config) {
|
|
86
82
|
const text = fs.readFileSync(specFile, { encoding: 'utf8' })
|
87
83
|
|
88
84
|
try {
|
89
|
-
const names = getTestNames(text)
|
85
|
+
const names = getTestNames(text, false)
|
90
86
|
const testAndSuiteNames = names.suiteNames.concat(names.testNames)
|
91
87
|
|
92
88
|
debug('spec file %s', specFile)
|
@@ -127,7 +123,7 @@ function cypressGrepPlugin(config) {
|
|
127
123
|
const requiredTags = testTags[testTitle].requiredTags
|
128
124
|
return shouldTestRun(
|
129
125
|
parsedGrep,
|
130
|
-
|
126
|
+
undefined,
|
131
127
|
effectiveTags,
|
132
128
|
false,
|
133
129
|
requiredTags,
|
@@ -173,7 +169,25 @@ function cypressGrepPlugin(config) {
|
|
173
169
|
}
|
174
170
|
|
175
171
|
if (greppedSpecs.length) {
|
176
|
-
config
|
172
|
+
if (isCypressV9(config)) {
|
173
|
+
debug('setting selected %d specs (< v10)', greppedSpecs.length)
|
174
|
+
// @ts-ignore
|
175
|
+
const integrationFolder = config.integrationFolder
|
176
|
+
const relativeNames = greppedSpecs.map((filename) =>
|
177
|
+
path.relative(integrationFolder, filename),
|
178
|
+
)
|
179
|
+
debug(
|
180
|
+
'specs in the integration folder %s %s',
|
181
|
+
integrationFolder,
|
182
|
+
relativeNames.join(', '),
|
183
|
+
)
|
184
|
+
// @ts-ignore
|
185
|
+
config.testFiles = relativeNames.join(',')
|
186
|
+
} else {
|
187
|
+
debug('setting selected %d specs (>= v10)', greppedSpecs.length)
|
188
|
+
// @ts-ignore
|
189
|
+
config.specPattern = greppedSpecs
|
190
|
+
}
|
177
191
|
} else {
|
178
192
|
// hmm, we filtered out all specs, probably something is wrong
|
179
193
|
console.warn('grep and/or grepTags has eliminated all specs')
|