Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CLI filtering --spec when commas in glob pattern #19557

Merged
merged 20 commits into from Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 32 additions & 3 deletions packages/server/lib/util/args.js
Expand Up @@ -5,6 +5,8 @@ const path = require('path')
const debug = require('debug')('cypress:server:args')
const minimist = require('minimist')
const { getPublicConfigKeys } = require('@packages/config')
const ig = require('is-glob')
const glob = require('glob')

const coerceUtil = require('./coerce')
const proxyUtil = require('./proxy')
Expand Down Expand Up @@ -204,6 +206,18 @@ const sanitizeAndConvertNestedArgs = (str, argname) => {
}
}

const parseSpecArgvAsGlob = (spec, cwd) => {
return {
isGlob: ig(spec),
setGlob: (pattern) => {
const globbed = glob.sync(path.resolve(cwd, pattern))

// This is needed to output the glob pattern on error.
return globbed.length ? globbed : [spec]
},
}
}

module.exports = {
normalizeBackslashes,

Expand Down Expand Up @@ -303,12 +317,27 @@ module.exports = {
spec = spec.substring(1, spec.length - 1)
}

options.spec = strToArray(spec).map(resolvePath)
// Before blindly parsing to an array of path, check if spec is not
// a glob pattern with commas.
const { isGlob, setGlob } = parseSpecArgvAsGlob(spec, options.cwd)

if (isGlob) {
options.spec = setGlob(spec)
} else {
options.spec = strToArray(spec).map(resolvePath)
}
} else {
options.spec = spec.map(resolvePath)
const stringifiedArg = spec.join()
const { isGlob, setGlob } = parseSpecArgvAsGlob(stringifiedArg, options.cwd)

if (isGlob) {
options.spec = setGlob(stringifiedArg)
} else {
options.spec = spec.map(resolvePath)
}
}
} catch (err) {
debug('could not pass config spec value %s', spec)
debug('could not parse config spec value %s', spec)
debug('error %o', err)

return errors.throw('COULD_NOT_PARSE_ARGUMENTS', 'spec', spec, 'spec must be a string or comma-separated list')
Expand Down
1 change: 1 addition & 0 deletions packages/server/package.json
Expand Up @@ -70,6 +70,7 @@
"human-interval": "1.0.0",
"image-size": "0.8.3",
"is-fork-pr": "2.5.0",
"is-glob": "4.0.3",
"is-html": "2.0.0",
"jimp": "0.14.0",
"jsonlint": "1.6.3",
Expand Down
21 changes: 8 additions & 13 deletions yarn.lock
Expand Up @@ -19746,12 +19746,7 @@ follow-redirects@1.5.10:
dependencies:
debug "=3.1.0"

follow-redirects@^1.0.0:
version "1.12.1"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.12.1.tgz#de54a6205311b93d60398ebc01cf7015682312b6"
integrity sha512-tmRv0AVuR7ZyouUHLeNSiO6pqulF7dYa3s19c6t+wz9LD69/uSzdMxJ2S91nTI9U3rt/IldxpzMOFejp6f0hjg==

follow-redirects@^1.14.0:
follow-redirects@^1.0.0, follow-redirects@^1.14.0:
version "1.14.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.5.tgz#f09a5848981d3c772b5392309778523f8d85c381"
integrity sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==
Expand Down Expand Up @@ -22992,6 +22987,13 @@ is-generator-function@^1.0.7:
resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.0.8.tgz#dfb5c2b120e02b0a8d9d2c6806cd5621aa922f7b"
integrity sha512-2Omr/twNtufVZFr1GhxjOMFPAj2sjc/dKaIqBhvo4qciXfJmITGH6ZGd8eZYNHza8t1y0e01AuqRhJwfWp26WQ==

is-glob@4.0.3, is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.3"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
dependencies:
is-extglob "^2.1.1"

is-glob@^2.0.0, is-glob@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863"
Expand All @@ -23006,13 +23008,6 @@ is-glob@^3.0.0, is-glob@^3.1.0:
dependencies:
is-extglob "^2.1.0"

is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
dependencies:
is-extglob "^2.1.1"

is-hexadecimal@^1.0.0:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
Expand Down