Skip to content

Commit

Permalink
replace fs write error with warning
Browse files Browse the repository at this point in the history
This change replaces the error with a warning
when cypress is executing tests in a readonly fs.
  • Loading branch information
Fabian Wiles authored and Daniel Muller committed May 9, 2020
1 parent d284269 commit 8f6d58d
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 1 deletion.
169 changes: 169 additions & 0 deletions packages/server/__snapshots__/8_read_only_fs_spec.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
exports['e2e project dir access / warns when unable to write to dir'] = `
Folder /foo/bar/.projects/e2e is not writable.
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: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (simple_spec.coffee) │
│ Searched: cypress/integration/simple_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: simple_spec.coffee (1 of 1)
✓ is true
1 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: simple_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Warning: We failed to record the video.
This error will not alter the exit code.
Error: ffmpeg exited with code 1: /foo/bar/.projects/e2e/cypress/videos/simple_spec.coffee.mp4: Permission denied
[stack trace lines]
Warning: We failed processing this video.
This error will not alter the exit code.
Error: ffmpeg exited with code 1: /foo/bar/.projects/e2e/cypress/videos/simple_spec.coffee.mp4: Permission denied
[stack trace lines]
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ simple_spec.coffee XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 1 1 - - -
`

exports['e2e project dir access / warns when unable to write a screenshot to disk'] = `
Folder /foo/bar/.projects/e2e is not writable.
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: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (simple_failing_spec.coffee) │
│ Searched: cypress/integration/simple_failing_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: simple_failing_spec.coffee (1 of 1)
simple failing spec
1) fails1
2) fails2
0 passing
2 failing
1) simple failing spec
fails1:
Error: EACCES: permission denied, mkdir '/foo/bar/.projects/e2e/cypress/screenshots/simple_failing_spec.coffee'
2) simple failing spec
fails2:
Error: EACCES: permission denied, mkdir '/foo/bar/.projects/e2e/cypress/screenshots/simple_failing_spec.coffee'
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 0 │
│ Failing: 2 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true │
│ Duration: X seconds │
│ Spec Ran: simple_failing_spec.coffee │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Warning: We failed to record the video.
This error will not alter the exit code.
Error: ffmpeg exited with code 1: /foo/bar/.projects/e2e/cypress/videos/simple_failing_spec.coffee.mp4: Permission denied
[stack trace lines]
Warning: We failed processing this video.
This error will not alter the exit code.
Error: ffmpeg exited with code 1: /foo/bar/.projects/e2e/cypress/videos/simple_failing_spec.coffee.mp4: Permission denied
[stack trace lines]
====================================================================================================
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✖ simple_failing_spec.coffee XX:XX 2 - 2 - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✖ 1 of 1 failed (100%) XX:XX 2 - 2 - -
`
10 changes: 10 additions & 0 deletions packages/server/lib/errors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,16 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
To avoid this error, ensure that there are no other instances of Firefox launched by Cypress running.
"""
when "FOLDER_NOT_ACCESSIBLE"
"""
Folder #{arg1} is not writable.
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.
"""

get = (type, arg1, arg2, arg3) ->
msg = getMsgByType(type, arg1, arg2, arg3)
Expand Down
4 changes: 3 additions & 1 deletion packages/server/lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ module.exports = {
log('cannot find file %s', file)

return this._err('CONFIG_FILE_NOT_FOUND', this.configFile(options), projectRoot)
}).catch({ code: 'EACCES' }, () => {
// we cannot read due to folder permissions
return errors.warning('FOLDER_NOT_ACCESSIBLE', projectRoot)
}).catch((err) => {
if (errors.isCypressErr(err)) {
throw err
}

// else we cannot read due to folder permissions
return this._logReadErr(file, err)
})
},
Expand Down
61 changes: 61 additions & 0 deletions packages/server/test/e2e/8_read_only_fs_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const e2e = require('../support/helpers/e2e')
const Fixtures = require('../support/helpers/fixtures')
const path = require('path')
import * as fs from 'fs'

describe('e2e project dir access', function () {
e2e.setup()

const projectPath = Fixtures.projectPath('e2e') // copied from `test/support/fixtures/projects/e2e`

const chmodr = (p: string, mode: number) => {
const stats = fs.statSync(p)

fs.chmodSync(p, mode)
if (stats.isDirectory()) {
fs.readdirSync(p).forEach((child) => {
chmodr(path.join(p, child), mode)
})
}
}

const onRun = (exec) => {
// Manually create these directories to prevent cypress crashing.
fs.mkdirSync(path.join(projectPath, 'cypress', 'videos'))
fs.mkdirSync(path.join(projectPath, 'cypress', 'screenshots'))

chmodr(projectPath, 0o500)

// test that we setup the folder structure correctly
let err: any

try {
fs.accessSync(projectPath, fs.constants.W_OK)
} catch (e) {
err = e
}
expect(err).to.include({ code: 'EACCES' })

return exec().finally(() => {
chmodr(projectPath, 0o777)
})
}

e2e.it('warns when unable to write to dir', {
project: projectPath,
browser: 'chrome',
expectedExitCode: 0,
spec: 'simple_spec.coffee',
snapshot: true,
onRun,
})

e2e.it('warns when unable to write a screenshot to disk', {
project: projectPath,
browser: 'chrome',
expectedExitCode: 2,
spec: 'simple_failing_spec.coffee',
snapshot: true,
onRun,
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('simple specs', () => {
it('should pass', () => {

})
})

0 comments on commit 8f6d58d

Please sign in to comment.