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

Cypress 10 watch all files when executing cypress run #22054

Closed
anlambert opened this issue Jun 2, 2022 · 2 comments · Fixed by #22060
Closed

Cypress 10 watch all files when executing cypress run #22054

anlambert opened this issue Jun 2, 2022 · 2 comments · Fixed by #22060
Assignees

Comments

@anlambert
Copy link

Current behavior

Today, I took some time to upgrade the project I am working on to Cypress 10 (see details).

The upgrade went fine (nice work on the migration tool, btw) and I could still run my e2e tests locally without an issue.

However when executing the tests on our Jenkins instance, the following error is raised when executing cypress run (see build log):

[2022-06-02T17:33:36.831Z] $ /var/lib/jenkins/workspace/DWAPPS/tests-on-diff/node_modules/.bin/cypress run --config numTestsKeptInMemory=0 --config watchForFileChanges=false

[2022-06-02T17:33:38.697Z] [627:0602/173338.326243:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.

[2022-06-02T17:33:38.697Z] [627:0602/173338.333408:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

[2022-06-02T17:33:41.180Z] 

[2022-06-02T17:33:41.180Z] tput: No value for $TERM and no -T specified

[2022-06-02T17:33:41.180Z] ====================================================================================================

[2022-06-02T17:33:41.180Z] 

[2022-06-02T17:33:41.180Z]   (Run Starting)

[2022-06-02T17:33:41.180Z] 

[2022-06-02T17:33:41.180Z]   ┌────────────────────────────────────────────────────────────────────────────────────────────────┐

[2022-06-02T17:33:41.180Z]   │ Cypress:        10.0.1                                                                         │

[2022-06-02T17:33:41.180Z]   │ Browser:        Electron 100 (headless)                                                        │

[2022-06-02T17:33:41.180Z]   │ Node Version:   v14.19.3 (/usr/bin/node)                                                       │

[2022-06-02T17:33:41.180Z]   │ Specs:          25 found (add-forge-now-request-create.cy.js, add-forge-now-request-dashboard. │

[2022-06-02T17:33:41.180Z]   │                 cy.js, add-forge-now-requests-moderation.cy.js, admin.cy.js, api-tokens.cy.js, │

[2022-06-02T17:33:41.180Z]   │                  back-to-top.cy.js, code-highlighting.cy.js, content-display.cy.js, content-re │

[2022-06-02T17:33:41.180Z]   │                 ndering.cy.js, deposit-...)                                                    │

[2022-06-02T17:33:41.180Z]   │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │

[2022-06-02T17:33:41.180Z]   └────────────────────────────────────────────────────────────────────────────────────────────────┘

[2022-06-02T17:33:41.180Z] 

[2022-06-02T17:33:41.180Z] 

[2022-06-02T17:33:41.180Z] ────────────────────────────────────────────────────────────────────────────────────────────────────

[2022-06-02T17:33:41.180Z]                                                                                                     

[2022-06-02T17:33:41.180Z]   Running:  add-forge-now-request-create.cy.js                                             (1 of 25)

[2022-06-02T17:33:42.523Z] ENOSPC: System limit for number of file watchers reached, watch '/var/lib/jenkins/workspace/DWAPPS/tests-on-diff/.tox/mypy/lib/python3.7/site-packages/rest_framework/decorators.py'

[2022-06-02T17:33:42.523Z] Error: ENOSPC: System limit for number of file watchers reached, watch '/var/lib/jenkins/workspace/DWAPPS/tests-on-diff/.tox/mypy/lib/python3.7/site-packages/rest_framework/decorators.py'

[2022-06-02T17:33:42.523Z]     at FSWatcher.<computed> (node:internal/fs/watchers:244:19)

[2022-06-02T17:33:42.523Z]     at Object.watch (node:fs:2247:34)

[2022-06-02T17:33:42.523Z]     at createFsWatchInstance (/home/jenkins/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js:119:15)

[2022-06-02T17:33:42.523Z]     at setFsWatchListener (/home/jenkins/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js:166:15)

[2022-06-02T17:33:42.523Z]     at NodeFsHandler._watchWithNodeFs (/home/jenkins/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js:331:14)

[2022-06-02T17:33:42.523Z]     at NodeFsHandler._handleFile (/home/jenkins/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js:395:23)

[2022-06-02T17:33:42.523Z]     at NodeFsHandler._addToNodeFs (/home/jenkins/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js:629:21)

[2022-06-02T17:33:42.523Z] 

[2022-06-02T17:33:44.385Z] error Command failed with exit code 1.

[2022-06-02T17:33:44.385Z] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I tweaked my local system to increase the maximum allowed number of files to watch so that's why I did not spot it prior executing the tests on our CI.

I patched the ~/.cache/Cypress/10.0.1/Cypress/resources/app/packages/data-context/node_modules/chokidar/lib/nodefs-handler.js file to print the watched files and I can confirm that all project files are watched when executing cypress run.

Desired behavior

The previous behavior should be restored, no files should be watched when executing cypress run as there is no point to do it when running tests in headless mode.

Test code to reproduce

This is a cypress regression, not related to tests implementation.

Cypress Version

10.0.1

Other

No response

@cypress-bot cypress-bot bot added the stage: investigating Someone from Cypress is looking into this label Jun 2, 2022
@tgriesser
Copy link
Member

tgriesser commented Jun 2, 2022

There are 2 issues here:

  1. We should not be watching spec files in run mode, we should have an early return if (this.ctx.isRunMode) here:

startSpecWatcher ({
projectRoot,
testingType,
specPattern,
configSpecPattern,
excludeSpecPattern,
additionalIgnorePattern,
}: FindSpecs<string[]>) {
this.stopSpecWatcher()
const currentProject = this.ctx.currentProject

  1. The behavior here changed as a result of removing integrationFolder and replacing it with a glob. We now need to be more specific about our ignore patterns, right now we're filtering out node_modules and some of the other exclude/ignore patterns, since we changed to watching on . due to issues w/ globbing in chokidar not detecting directories being added/removed (see commit/convo here). Instead we need to make a change here, I'd assume this would be using the function signature of ignored and return true if we're matching the excludes, or not matching the includes:

// We respond to all changes to the project's filesystem when
// files or directories are added and removed that are not explicitly
// ignored by config
this._specWatcher = chokidar.watch('.', {
ignoreInitial: true,
ignorePermissionErrors: true,
cwd: projectRoot,
ignored: ['**/node_modules/**', ...excludeSpecPattern, ...additionalIgnorePattern],
})

https://github.com/paulmillr/chokidar#path-filtering

// https://github.com/micromatch/anymatch
ignored: (file) => {
 if (file.includes('node_modules') || file.includes('.git')) { // maybe determine a way to ignore .gitignored files?
   return true
 }
 if (!path.extname(file)) {  // don't ignore things that look like directories
   return false
 }
 if (anymatch(file, `**/${excludeSpecPattern}`) || anymatch(file, `**/${additionalIgnorePattern}`)) {
   return true
 }
 if (anymatch(file, `**/${specPattern}`)) {
   return false
 }
 return true // other files that are unrelated to the project
}

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: investigating Someone from Cypress is looking into this labels Jun 2, 2022
@mjhenkes mjhenkes linked a pull request Jun 2, 2022 that will close this issue
4 tasks
@cypress-bot cypress-bot bot added stage: routed to ct and removed stage: needs review The PR code is done & tested, needs review labels Jun 2, 2022
@mjhenkes mjhenkes added stage: needs review The PR code is done & tested, needs review E2E-core and removed stage: routed to ct labels Jun 2, 2022
@cypress-bot cypress-bot bot added stage: routed to e2e-core and removed stage: needs review The PR code is done & tested, needs review labels Jun 2, 2022
@mjhenkes mjhenkes assigned estrada9166 and unassigned ZachJW34 Jun 2, 2022
@mjhenkes mjhenkes closed this as completed Jun 2, 2022
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: pending release labels Jun 2, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 2, 2022

Released in 10.0.2.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v10.0.2, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Jun 2, 2022
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 2, 2022
@mjhenkes mjhenkes removed the PATCH label Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants