Skip to content

Commit 8e0f6fb

Browse files
Dennis BergevinDennis Bergevin
Dennis Bergevin
authored and
Dennis Bergevin
committed
adding specs titles tags flags
1 parent 662e962 commit 8e0f6fb

File tree

4 files changed

+102
-49
lines changed

4 files changed

+102
-49
lines changed

cypress.config.js

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ module.exports = defineConfig({
44
e2e: {
55
trashAssetsBeforeRuns: false,
66
setupNodeEvents(on, config) {
7-
// on("before:run", (details) => {
8-
// console.log(details);
9-
// });
107
require("@bahmutov/cy-grep/src/plugin")(config);
118
on("task", {
129
log(message) {

index.js

+99-43
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ async function runSelectedSpecs() {
115115
process.env.SUBMIT_FOCUSED = true;
116116
}
117117

118+
if (process.argv.includes("--titles")) {
119+
findAndRemoveArgv("--titles");
120+
process.env.TEST_TITLES = true;
121+
process.env.CY_GREP_FILTER_METHOD = "Titles";
122+
}
123+
124+
if (process.argv.includes("--specs")) {
125+
findAndRemoveArgv("--specs");
126+
process.env.TEST_SPECS = true;
127+
}
128+
129+
if (process.argv.includes("--tags")) {
130+
findAndRemoveArgv("--tags");
131+
process.env.TEST_TAGS = true;
132+
process.env.CY_GREP_FILTER_METHOD = "Tags";
133+
}
134+
118135
// set the testing type
119136
// this is used by find-cypress-specs package to get the appropriate spec list
120137
if (process.argv.includes("--component")) {
@@ -125,6 +142,30 @@ async function runSelectedSpecs() {
125142

126143
try {
127144
// help menu options
145+
yarg
146+
.completion("--specs", false)
147+
.option("specs", {
148+
desc: "Skips to spec selection prompt",
149+
type: "boolean",
150+
})
151+
.example("npx cypress-cli-select run --specs");
152+
153+
yarg
154+
.completion("--titles", false)
155+
.option("titles", {
156+
desc: "Skips to test title selection prompt",
157+
type: "boolean",
158+
})
159+
.example("npx cypress-cli-select run --titles");
160+
161+
yarg
162+
.completion("--tags", false)
163+
.option("tags", {
164+
desc: "Skips to tag selection prompt",
165+
type: "boolean",
166+
})
167+
.example("npx cypress-cli-select run --tags");
168+
128169
yarg
129170
.completion("--print-selected", false)
130171
.option("print-selected", {
@@ -174,51 +215,66 @@ async function runSelectedSpecs() {
174215
* Test titles/tags requires the cy-grep package
175216
*/
176217
// Prompt for use to select spec and test titles or tags option
177-
const specAndTestPrompt = await select({
178-
message: "Choose to filter by specs, specific test titles or tags: ",
179-
multiple: disableTitleTagChoice ? false : true,
180-
defaultValue: disableTitleTagChoice ? "Specs" : null,
181-
clearInputWhenSelected: true,
182-
selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED,
183-
canToggleAll: true,
184-
options: [
185-
{
186-
name: "Specs",
187-
value: "Specs",
188-
},
189-
{
190-
name: "Test titles or tags (requires cy-grep)",
191-
value: "Tests or tags",
192-
disabled: disableTitleTagChoice,
193-
},
194-
],
195-
required: true,
196-
});
197-
198-
/*
199-
200-
/*
201-
* NOTE:: Choose test titles or tags
202-
* This requires the cy-grep package
203-
*/
204-
if (specAndTestPrompt.includes("Tests or tags")) {
205-
// Prompt for use to select test titles or tags option
206-
const titleOrTagPrompt = await select({
207-
message: "Choose to filter by specific test titles or tags: ",
208-
multiple: false,
218+
if (
219+
!process.env.TEST_TITLES &&
220+
!process.env.TEST_SPECS &&
221+
!process.env.TEST_TAGS
222+
) {
223+
const specAndTestPrompt = await select({
224+
message: "Choose to filter by specs, specific test titles or tags: ",
225+
multiple: disableTitleTagChoice ? false : true,
226+
defaultValue: disableTitleTagChoice ? "Specs" : null,
227+
clearInputWhenSelected: true,
228+
selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED,
229+
canToggleAll: true,
209230
options: [
210231
{
211-
name: "Test titles",
212-
value: "Titles",
232+
name: "Specs",
233+
value: "Specs",
213234
},
214235
{
215-
name: "Test tags",
216-
value: "Tags",
236+
name: "Test titles or tags (requires cy-grep)",
237+
value: "Tests or tags",
238+
disabled: disableTitleTagChoice,
217239
},
218240
],
219241
required: true,
220242
});
221-
process.env.CY_GREP_FILTER_METHOD = titleOrTagPrompt;
243+
if (specAndTestPrompt.includes("Specs")) {
244+
process.env.TEST_SPECS = true;
245+
}
246+
247+
/*
248+
249+
/*
250+
* NOTE:: Choose test titles or tags
251+
* This requires the cy-grep package
252+
*/
253+
if (specAndTestPrompt.includes("Tests or tags")) {
254+
// Prompt for use to select test titles or tags option
255+
const titleOrTagPrompt = await select({
256+
message: "Choose to filter by specific test titles or tags: ",
257+
multiple: false,
258+
options: [
259+
{
260+
name: "Test titles",
261+
value: "Titles",
262+
},
263+
{
264+
name: "Test tags",
265+
value: "Tags",
266+
},
267+
],
268+
required: true,
269+
});
270+
process.env.CY_GREP_FILTER_METHOD = titleOrTagPrompt;
271+
if (titleOrTagPrompt.includes("Titles")) {
272+
process.env.TEST_TITLES = true;
273+
}
274+
if (titleOrTagPrompt.includes("Tags")) {
275+
process.env.TEST_TAGS = true;
276+
}
277+
}
222278
}
223279
// Arrays for storing specs and/or tests
224280
// If user passes --print-selected
@@ -228,7 +284,7 @@ async function runSelectedSpecs() {
228284
/*
229285
* NOTE:: Spec section
230286
*/
231-
if (specAndTestPrompt.includes("Specs")) {
287+
if (process.env.TEST_SPECS) {
232288
const specs = getSpecs(undefined, process.env.TESTING_TYPE, false);
233289

234290
if (specs.length > 0) {
@@ -334,7 +390,7 @@ async function runSelectedSpecs() {
334390
/*
335391
* NOTE:: Test Title section
336392
*/
337-
if (process.env.CY_GREP_FILTER_METHOD === "Titles") {
393+
if (process.env.TEST_TITLES) {
338394
const specs = getSpecs(undefined, process.env.TESTING_TYPE, false);
339395

340396
if (specs.length > 0) {
@@ -463,7 +519,7 @@ async function runSelectedSpecs() {
463519
/*
464520
* NOTE:: Tags section
465521
*/
466-
if (process.env.CY_GREP_FILTER_METHOD === "Tags") {
522+
if (process.env.TEST_TAGS) {
467523
const specs = getSpecs(undefined, process.env.TESTING_TYPE, false);
468524

469525
if (specs.length > 0) {
@@ -532,19 +588,19 @@ async function runSelectedSpecs() {
532588
// NOTE : --print-selected used to show all selected specs/titles/tags
533589
if (process.argv.includes("--print-selected")) {
534590
findAndRemoveArgv("--print-selected");
535-
if (specAndTestPrompt.includes("Specs")) {
591+
if (process.env.TEST_SPECS) {
536592
console.log("\n");
537593
console.log(pc.bgGreen(pc.black(pc.bold(` Spec(s) selected: `))));
538594
console.log("\n");
539595
console.log(specArr);
540596
}
541-
if (process.env.CY_GREP_FILTER_METHOD === "Titles") {
597+
if (process.env.TEST_TITLES) {
542598
console.log("\n");
543599
console.log(pc.bgGreen(pc.black(pc.bold(` Test(s) selected: `))));
544600
console.log("\n");
545601
console.log(testArr);
546602
}
547-
if (process.env.CY_GREP_FILTER_METHOD === "Tags") {
603+
if (process.env.TEST_TAGS) {
548604
console.log("\n");
549605
console.log(pc.bgGreen(pc.black(pc.bold(` Tag(s) selected: `))));
550606
console.log("\n");

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cypress-cli-select",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "A Cypress cli prompt to select and run specs, tests or tags",
55
"main": "index.js",
66
"bin": {

0 commit comments

Comments
 (0)