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

allow list of search patterns in testFiles config option #5402

Merged
merged 20 commits into from
Oct 31, 2019

Conversation

bahmutov
Copy link
Contributor

@bahmutov bahmutov commented Oct 21, 2019

User facing changelog

  • allows a list of specs when searching for test files via config argument testFiles which follows the principle in ignoreTestFiles config option

Additional details

Using glob to select several groups of spec names is not obvious. For example to select both .md and *spec.js files one would need to write without spaces

{
  "testFiles": "{*.md,*spec.js}"
}

With this change, user could write

{
  "testFiles": ["*.md", "*spec.js"]
}

which to me looks more natural and easier to remember. Also added debug log messages during DEBUG=cypress:server:specs that show how the search happens in case on needs to debug it.

How has the user experience changed?

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 21, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@bahmutov bahmutov changed the title WIP: log spec search steps WIP: allow list of search patterns in testFiles config option Oct 21, 2019
path.join(cfg.projectRoot, "cypress", "integration", "js_spec.js")
])
]
specsUtil.find(cfg, specPattern)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

being a little bit clearer on the arguments

.then (files) ->
expect(files.length).to.equal(1)
expect(files[0].name).to.equal("js_spec.js")

it "filters using specPattern as array of glob patterns", ->
config.get(FixturesHelper.projectPath("various-file-types"))
.then (cfg) ->
specsUtil.find(cfg, [
debug("test config testFiles is %o", cfg.testFiles)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a few debug statements to the test itself is useful when iterating on the test and understanding what is going on

.tap((files) => {
return debug('found %d spec files: %o', files.length, files)
})
return Promise.mapSeries(testFilesPatterns, findOnePattern).then(_.flatten)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find matching spec files one pattern at a time and then merging them

bahmutov and others added 6 commits October 21, 2019 11:47
Change `testFiles` from a string to either a string **or** array of strings; following similar pattern as `ignoreTestFiles`
Seems to fail for similar reason as #4543 and is likely resolved with PR #4849
@CLAassistant
Copy link

CLAassistant commented Oct 21, 2019

CLA assistant check
All committers have signed the CLA.

Comment on lines 345 to 360
it "runs project by limiting spec files via config.testFiles as an array of string glob patterns", ->
cypress.start(["--run-project=#{@todosPath}", "--config=testFiles=**/test2.coffee,**/test1.js"])
.then =>
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, {url: "http://localhost:8888/__/#/tests/integration/test2.coffee"})
.then =>
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, {url: "http://localhost:8888/__/#/tests/integration/test1.js"})
@expectExitWith(0)

it "runs project by limiting spec files via config.testFiles as an array of string glob patterns", ->
cypress.start(["--run-project=#{@todosPath}", "--config='[\"testFiles=**/test2.coffee\",\"**/test1.js\"]'"])
.then =>
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, {url: "http://localhost:8888/__/#/tests/integration/test2.coffee"})
.then =>
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, {url: "http://localhost:8888/__/#/tests/integration/test1.js"})
@expectExitWith(0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bahmutov per the commit message, I'll echo it here, I think these fail for similar reasons as #4896. There is an outstanding PR for this issue. I can review the PR, get it merged when ready, and then update this branch to see if it resolves this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retract my assessment. It looks like we do not need the functionality in that PR. Furthermore, supporting the syntax --config=testFiles=["**/*.js", "**/*.coffee"] is how other mutli-value config values work; such as ignoreTestFiles. I do not see any documentation or elsewhere in tests indicating that the format, --config=testFiles=**/*.js,**/*.coffee, is actually supported.

Distinguish between the two tests; as they are subtly different.
@@ -43,7 +43,7 @@ declare module 'cypress' {
*/
reporter: string,
/**
* A String glob pattern of the test files to load.
* A String or Array of string glob pattern of the test files to load.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got to update the type here as well

testFiles: string | string[]

Updated the comments, but forgot to update the actual type. This commit rectifies that.
`--config` was not being passed the appropriate value. Now matches other test cases; such as that found in [args_spec](https://github.com/cypress-io/cypress/blob/92b91fe514e5ff6286b4d4e26d2df23062bdf869/packages/server/test/unit/args_spec.coffee#L210)
From looking at other tests, it does not appear that the syntax `--config=testFiles=glob1,glob2` is current supported. Removing the test for this test case.
@andrew-codes andrew-codes self-assigned this Oct 21, 2019
@andrew-codes andrew-codes changed the title WIP: allow list of search patterns in testFiles config option allow list of search patterns in testFiles config option Oct 22, 2019
@@ -322,9 +322,18 @@ describe "lib/config", ->
@setup({testFiles: "**/*.coffee"})
@expectValidationPasses()

it "fails if not a string", ->
it "passes if an array of strings", ->
@setup({ignoreTestFiles: ["**/*.coffee", "**/*.jsx"]})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean testFiles here right ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, let me change these two places within config_spec

@expectValidationFails("be a string or an array of string")

it "fails if not an array of strings", ->
@setup({ignoreTestFiles: [5]})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean testFiles

Copy link
Contributor Author

@bahmutov bahmutov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see two comments in tests

@bahmutov bahmutov requested a review from kuceb October 22, 2019 14:39
Previously was testing `ignoreTestFiles` instead of `testFies`
cli/schema/cypress.schema.json Outdated Show resolved Hide resolved
cli/schema/cypress.schema.json Outdated Show resolved Hide resolved
packages/server/test/integration/cypress_spec.coffee Outdated Show resolved Hide resolved
kuceb
kuceb previously approved these changes Oct 29, 2019
Copy link
Contributor

@kuceb kuceb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept that wording change if you want. but LGTM

@kuceb
Copy link
Contributor

kuceb commented Oct 29, 2019

make sure to merge in develop and rebuild after we get this circle zip file size figured out

Co-Authored-By: Ben Kucera <14625260+Bkucera@users.noreply.github.com>
@jennifer-shehane jennifer-shehane merged commit b3e40b0 into develop Oct 31, 2019
jennifer-shehane added a commit to cypress-io/cypress-documentation that referenced this pull request Oct 31, 2019
* update docs to reflect changes to `testFiles`

Content updates due ot changes in [PR](cypress-io/cypress#5402)

* examples of multi-value config properties via CLI


Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing a list of glob patterns in testFiles config option
5 participants