@bahmutov/cy-grep 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +12 -1
- package/package.json +1 -1
- package/src/index.d.ts +14 -0
- package/src/support.js +34 -0
package/README.md
CHANGED
@@ -25,7 +25,7 @@ Table of Contents
|
|
25
25
|
|
26
26
|
<!-- MarkdownTOC autolink="true" -->
|
27
27
|
|
28
|
-
- [@bahmutov/cy-grep](#bahmutovcy-grep)
|
28
|
+
- [@bahmutov/cy-grep ](#bahmutovcy-grep-)
|
29
29
|
- [Install](#install)
|
30
30
|
- [Support file](#support-file)
|
31
31
|
- [Config file](#config-file)
|
@@ -49,6 +49,7 @@ Table of Contents
|
|
49
49
|
- [TypeScript support](#typescript-support)
|
50
50
|
- [General advice](#general-advice)
|
51
51
|
- [DevTools console](#devtools-console)
|
52
|
+
- [grepFailed](#grepfailed)
|
52
53
|
- [Debugging](#debugging)
|
53
54
|
- [Log messages](#log-messages)
|
54
55
|
- [Debugging in the plugin](#debugging-in-the-plugin)
|
@@ -494,6 +495,16 @@ Cypress.grep('hello', '@smoke', 10)
|
|
494
495
|
|
495
496
|
- to remove the grep strings enter `Cypress.grep()`
|
496
497
|
|
498
|
+
### grepFailed
|
499
|
+
|
500
|
+
Once the tests finish, you can run just the failed tests from DevTools console
|
501
|
+
|
502
|
+
```text
|
503
|
+
> Cypress.grepFailed()
|
504
|
+
```
|
505
|
+
|
506
|
+
**Tip:** use `Cypress.grep()` to reset and run all the tests
|
507
|
+
|
497
508
|
## Debugging
|
498
509
|
|
499
510
|
When debugging a problem, first make sure you are using the expected version of this plugin, as some features might be only available in the [later releases](https://github.com/cypress-io/cypress-grep/releases).
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
@@ -26,6 +26,20 @@ declare namespace Cypress {
|
|
26
26
|
}
|
27
27
|
|
28
28
|
interface Cypress {
|
29
|
+
/**
|
30
|
+
* Runs only the tests that contain the given "grep" string
|
31
|
+
* in the title, or have specific tags.
|
32
|
+
* @param grep Part of the test title
|
33
|
+
* @param tags Tags to filter tests by
|
34
|
+
* @param burn Number of times to repeat each test
|
35
|
+
*/
|
29
36
|
grep?: (grep?: string, tags?: string, burn?: string) => void
|
37
|
+
/**
|
38
|
+
* Take the current test statuses and run only the failed tests.
|
39
|
+
* Run this static method from the DevTools console.
|
40
|
+
* Tip: use Cypress.grep() to reset and run all tests.
|
41
|
+
* @example Cypress.grepFailed()
|
42
|
+
*/
|
43
|
+
grepFailed?: () => void
|
30
44
|
}
|
31
45
|
}
|
package/src/support.js
CHANGED
@@ -253,4 +253,38 @@ if (!Cypress.grep) {
|
|
253
253
|
}
|
254
254
|
}
|
255
255
|
|
256
|
+
if (!Cypress.grepFailed) {
|
257
|
+
Cypress.grepFailed = function () {
|
258
|
+
// @ts-ignore
|
259
|
+
let root = Cypress.state('runnable')
|
260
|
+
while (root.parent) {
|
261
|
+
root = root.parent
|
262
|
+
}
|
263
|
+
const failedTestTitles = []
|
264
|
+
|
265
|
+
function findFailedTests(suite) {
|
266
|
+
suite.tests.forEach((test) => {
|
267
|
+
if (test.state === 'failed') {
|
268
|
+
// TODO use the full test title
|
269
|
+
failedTestTitles.push(test.title)
|
270
|
+
}
|
271
|
+
})
|
272
|
+
suite.suites.forEach((suite) => {
|
273
|
+
findFailedTests(suite)
|
274
|
+
})
|
275
|
+
}
|
276
|
+
findFailedTests(root)
|
277
|
+
|
278
|
+
if (!failedTestTitles.length) {
|
279
|
+
console.log('No failed tests found')
|
280
|
+
} else {
|
281
|
+
console.log('running only the failed tests')
|
282
|
+
console.log(failedTestTitles)
|
283
|
+
const grepTitles = failedTestTitles.join(';')
|
284
|
+
// @ts-ignore
|
285
|
+
Cypress.grep(grepTitles)
|
286
|
+
}
|
287
|
+
}
|
288
|
+
}
|
289
|
+
|
256
290
|
module.exports = cypressGrep
|