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

[WIP] Issue 1281 warning on no write #5584

Closed
8 changes: 8 additions & 0 deletions packages/server/__snapshots__/8_read_only_fs.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports['e2e project dir access / warns when unable to write to dir'] = `
Can't run because no spec files were found.

We searched for any files matching this glob pattern:

cypress/integration/spec.js

`
7 changes: 7 additions & 0 deletions packages/server/lib/errors.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,13 @@ getMsgByType = (type, arg1 = {}, arg2, arg3) ->
"""
Failed to connect to Chrome, retrying in 1 second (attempt #{chalk.yellow(arg1)}/32)
"""
when "FOLDER_NOT_ACCESSIBLE"
"""
Folder #{arg1} is not writable.

Either enable write permission to this directory to enable screen shot and video collection.

Or ignore this warning if you do not need enable screen shot and video.
when "DEPRECATED_BEFORE_BROWSER_LAUNCH_ARGS"
"""
Deprecation Warning: The `before:browser:launch` plugin event changed its signature in version `4.0.0`
Expand Down
5 changes: 3 additions & 2 deletions packages/server/lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = {
.then(() => {
// if it does also check that the projectRoot
// directory is writable
return fs.accessAsync(projectRoot, fs.W_OK)
return fs.accessAsync(projectRoot, fs.constants.W_OK)
}).catch({ code: 'ENOENT' }, () => {
// cypress.json does not exist, we missing project
log('cannot find file %s', file)
Expand All @@ -126,8 +126,9 @@ module.exports = {
throw err
}

throw err
// else we cannot read due to folder permissions
return this._logReadErr(file, err)
// return errors.warning('FOLDER_NOT_ACCESSIBLE', projectRoot)
})
},

Expand Down
55 changes: 55 additions & 0 deletions packages/server/test/e2e/8_read_only_fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as fs from 'fs-extra'
import * as os from 'os'
import * as path from 'path'
import * as crypto from 'crypto'

const e2e = require('../support/helpers/e2e')

describe('e2e project dir access', function () {
e2e.setup()
let projectDir: string

beforeEach(() => {
const tmpdir = os.tmpdir()

// get a random dir that dosen't clash with other runs
projectDir = path.join(tmpdir, crypto.randomBytes(4).toString('hex'))

// write out the project structure
// we cant sue one define by source code since we need to modify the file permissions on the dir and files
fs.mkdirSync(path.join(projectDir))
fs.mkdirSync(path.join(projectDir, 'cypress'))
fs.mkdirSync(path.join(projectDir, 'cypress', 'integration'))
fs.writeFileSync(path.join(projectDir, 'cypress', 'integration', 'spec.js'), `it('test',() => expect(true).to.be.true )`)

// setup the file/folder permissions
// 500 means individual read + execute
// the dir needs executable for debugging
// the main test here is that it isn't writable, which would be either 6 or 7
// See here for more info on these numbers http://permissions-calculator.org/
const readExe = 0o500

fs.chmodSync(path.join(projectDir), readExe)
fs.chmodSync(path.join(projectDir, 'cypress'), readExe)
fs.chmodSync(path.join(projectDir, 'cypress', 'integration'), readExe)
fs.chmodSync(path.join(projectDir, 'cypress', 'integration', 'spec.js'), readExe)

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

try {
fs.accessSync(projectDir, fs.constants.W_OK)
} catch (e) {
err = e
}
expect(err).to.not.be.undefined
})

e2e.it('warns when unable to write to dir', {
project: projectDir,
spec: 'spec.js',
browser: 'chrome',
expectedExitCode: 1,
snapshot: true,
})
})