This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
grep-pick-tests.js
62 lines (57 loc) · 1.9 KB
/
grep-pick-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Returns only the names of the tests we want to run using
* Cypress env variables "fgrep" and "grep".
*/
const grepPickTests = (filename, foundTests, cypressConfig) => {
// only leave some of the tests, picking by name
// each test name is a list of strings
// [suite name, suite name, ..., test name]
// we could use Cypress env variables to use same options as Mocha
// see https://mochajs.org/
// --fgrep, -f Only run tests containing this string [string]
// --grep, -g Only run tests matching this string or regexp [string]
// --invert, -i Inverts --grep and --fgrep matches [boolean]
// for example, only leave tests where the test name is "works"
// return foundTests.filter(testName => R.last(testName) === 'works')
const fgrep = cypressConfig.env.fgrep
const grep = cypressConfig.env.grep // assume string for now, not regexp
const invert = cypressConfig.env.invert
if (fgrep) {
if (invert) {
console.log('\tJust tests with a name that does not contain: %s', fgrep)
if (filename.includes(fgrep)) {
console.warn(
'\tTest filename %s matched fgrep "%s"',
filename,
fgrep
)
return
}
} else {
console.log('\tJust tests with a name that contains: %s', fgrep)
if (!filename.includes(fgrep)) {
console.warn(
'\tTest filename %s did not match fgrep "%s"',
filename,
fgrep
)
return
}
}
}
if (grep) {
if (invert) {
console.log('\tJust tests not tagged with: %s', grep)
return foundTests.filter(testName =>
!testName.some(part => part && part.includes(grep))
)
} else {
console.log('\tJust tests tagged with: %s', grep)
return foundTests.filter(testName =>
testName.some(part => part && part.includes(grep))
)
}
}
return foundTests
}
module.exports = { grepPickTests }