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

Read-only warning given even when screenshots and videos folders writable #30810

Open
MikeMcC399 opened this issue Dec 31, 2024 · 2 comments
Open
Labels
stage: needs investigating Someone from Cypress needs to look at this type: error message

Comments

@MikeMcC399
Copy link
Contributor

MikeMcC399 commented Dec 31, 2024

Current behavior

If the root directory of a Cypress project is read-only, then Cypress outputs a warning that the folder is not writeable, even when the screenshots and videos folders are located outside of the project and are writable. The warning is:

This folder is not writable: <Location of Cypress project>

Writing to this directory is required by Cypress in order to store screenshots and videos.

Enable write permissions to this directory to ensure screenshots and videos are stored.

If you don't require screenshots or videos to be stored you can safely ignore this warning.

Alternatively, if the root directory of the Cypress project is writeable, the cypress directory is read-only, the screenshotsFolder and the videosFolder use default locations and video is enabled, then there is no warning message, only EACCES failure messages when trying to capture video and save screenshots.

So, in summary, the check produces warnings when it shouldn't (false positive), and neglects to warn when it should do (false negative).

The issue is also relevant for Docker usage when Docker is run as a non-root user.

Desired behavior

There should be no warning requiring that the root directory of a Cypress project should be writable if Cypress is configured so that screenshots and videos can be written.

Cypress should check the locations of the screenshotsFolder and the videosFolder (if video is enabled) and only output a warning if these locations are read-only. It should not be a requirement for the root of the Cypress project to be writeable.

Test code to reproduce

GitHub Actions

Run the following example from https://github.com/cypress-io/cypress-docker-images in a GitHub Actions workflow:

steps:
  - uses: actions/checkout@v4
  - working-directory: examples/included-as-non-root
    run: docker run --rm -v .:/test -w /test -u node cypress/included

In this situation the test directory is mounted using GitHub Actions' 1001 runner user. The Cypress Docker image however needs the built-in node user in order to run, and it has no write access to the files of the runner user.

Standalone

mkdir cy-read-only
cd cy-read-only
git init
npm init -y
npm install cypress
npx cypress open

Scaffold a single default E2E test spec. Change spec.cy.js to add a screenshot capture:

describe('template spec', () => {
  it('passes', () => {
    cy.visit('https://example.cypress.io')
    cy.screenshot()
  })
})

Replace cypress.config.js with the following to move volatile directories to /tmp and to enable video:

const { defineConfig } = require("cypress");

module.exports = defineConfig({
  downloadsFolder: '/tmp/cypress/downloads',
  screenshotsFolder: '/tmp/cypress/screenshots',
  video: true,
  videosFolder: '/tmp/cypress/videos',
  fixturesFolder: false,
  e2e: {
    supportFile: false,
  },
});
chown -w ../cy-read-only
npx cypress run

Cypress Version

13.17.0

Node version

v22.12.0 LTS

Operating System

Ubuntu 24.04.1 LTS

Debug Logs

The logs show Cypress first warning that it can't capture screenshots and videos, and then contradicting this information by capturing both screenshots and videos to /tmp.

$ npx cypress run

DevTools listening on ws://127.0.0.1:38899/devtools/browser/73418185-d301-4725-aa05-22e0e44837dd
This folder is not writable: /home/mike/github/cy-read-only

Writing to this directory is required by Cypress in order to store screenshots and videos.

Enable write permissions to this directory to ensure screenshots and videos are stored.

If you don't require screenshots or videos to be stored you can safely ignore this warning.

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        13.17.0                                                                        │
  │ Browser:        Electron 118 (headless)                                                        │
  │ Node Version:   v22.12.0 (/home/mike/.nvm/versions/node/v22.12.0/bin/node)                     │
  │ Specs:          1 found (spec.cy.js)                                                           │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

  Running:  spec.cy.js                                                                      (1 of 1)


  template spec
    ✓ passes (2878ms)


  1 passing (4s)


  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      1                                                                                │
  │ Failing:      0                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  1                                                                                │
  │ Video:        true                                                                             │
  │ Duration:     4 seconds                                                                        │
  │ Spec Ran:     spec.cy.js                                                                       │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Screenshots)

  -  /tmp/cypress/screenshots/spec.cy.js/template spec -- passes.png                     (1000x4885)


  (Video)

  -  Video output: /tmp/cypress/videos/spec.cy.js.mp4


====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✔  spec.cy.js                               00:04        1        1        -        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✔  All specs passed!                        00:04        1        1        -        -        -

Other

No response

@MikeMcC399
Copy link
Contributor Author

Source code inspection confirms that Cypress indeed is only checking the projectRoot for write access. This means by implication that Cypress incorrectly assumes that screenshotsFolder and videosFolder are using their default location of cypress/screenshots and cypress/videos, although the locations are configurable and are not tied to being within the project root's directory tree.

FOLDER_NOT_WRITABLE: (arg1: string) => {
return errTemplate`\
This folder is not writable: ${fmt.path(arg1)}
Writing to this directory is required by Cypress in order to store screenshots and videos.
Enable write permissions to this directory to ensure screenshots and videos are stored.
If you don't require screenshots or videos to be stored you can safely ignore this warning.`
},

async function checkAccess (folderPath) {
return fs.access(folderPath, fs.constants.W_OK).catch((err) => {
if (['EACCES', 'EPERM', 'EROFS'].includes(err.code)) {
// we cannot write due to folder permissions, or read-only filesystem
return errors.warning('FOLDER_NOT_WRITABLE', folderPath)
}
throw err
})
}
const createAndOpenProject = async (options) => {
const { projectRoot, projectId, socketId } = options
await checkAccess(projectRoot)

@MikeMcC399
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this type: error message
Projects
None yet
Development

No branches or pull requests

2 participants