Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit ffa0608

Browse files
authored
fix: filter specs using parsed grep (#97)
* add failing test showing OR not working with filtered specs option * fix: filter specs using parsed grep, closes #96
1 parent b2d47fa commit ffa0608

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ jobs:
111111
--env grep="hello; works 2" \
112112
--expect ./expects/hello-or-works-2.json
113113
114+
# https://github.com/cypress-io/cypress-grep/issues/96
115+
- name: Run tests with "hello" or "works 2" with spec filtering 🧪
116+
run: |
117+
npx cypress-expect run \
118+
--env grep="hello; works 2",grepFilterSpecs=true \
119+
--expect ./expects/hello-or-works-2.json
120+
114121
tests2:
115122
runs-on: ubuntu-20.04
116123
needs: install

src/plugin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { getTestNames } = require('find-test-names')
44
const fs = require('fs')
55
const path = require('path')
66
const { version } = require('../package.json')
7+
const { parseGrep, shouldTestRun } = require('./utils')
78

89
/**
910
* Prints the cypress-grep environment values if any.
@@ -62,6 +63,9 @@ function cypressGrepPlugin(config) {
6263
debug('found %d spec files', specFiles.length)
6364
debug('%o', specFiles)
6465

66+
const parsedGrep = parseGrep(grep)
67+
debug('parsed grep %o', parsedGrep)
68+
6569
const specsWithText = specFiles.filter((specFile) => {
6670
const text = fs.readFileSync(
6771
path.join(config.integrationFolder, specFile),
@@ -73,7 +77,10 @@ function cypressGrepPlugin(config) {
7377
debug('spec file %s', specFile)
7478
debug('suite and test names: %o', testAndSuiteNames)
7579

76-
return testAndSuiteNames.some((name) => name.includes(grep))
80+
return testAndSuiteNames.some((name) => {
81+
const shouldRun = shouldTestRun(parsedGrep, name)
82+
return shouldRun
83+
})
7784
} catch (err) {
7885
console.error('Could not determine test names in file: %s', specFile)
7986
console.error('Will run it to let the grep filter the tests')
@@ -113,6 +120,7 @@ function cypressGrepPlugin(config) {
113120
debug('test info: %o', testInfo.tests)
114121

115122
return testInfo.tests.some((info) => {
123+
// TODO: switch to using "shouldTestRun"
116124
return info.tags && info.tags.includes(grepTags)
117125
})
118126
} catch (err) {

0 commit comments

Comments
 (0)