-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: adding timeout option to writeFile command #19015
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
Changes from all commits
707b17a
0a4fc36
86917da
2cc5b89
57b8c9f
0ca8f09
8405842
2a61915
814ad09
65fed27
7a5e813
7f210f7
51afbfc
2e4af33
67f0f0c
f053a9c
152a121
e928959
84e92f1
58f2475
ab7b52d
f6bc87f
7137e5e
bdb0694
58d8b2b
9d149ec
c16be3a
845e1c5
bf1c901
fef9779
6d6045b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
// @ts-nocheck | ||
import _ from 'lodash' | ||
import Promise from 'bluebird' | ||
|
||
import $errUtils from '../../cypress/error_utils' | ||
|
||
|
@@ -22,6 +21,7 @@ export default (Commands, Cypress, cy) => { | |
// to restore the default node behavior. | ||
encoding: encoding === undefined ? 'utf8' : encoding, | ||
log: true, | ||
timeout: Cypress.config('defaultCommandTimeout'), | ||
}) | ||
|
||
const consoleProps = {} | ||
|
@@ -43,21 +43,33 @@ export default (Commands, Cypress, cy) => { | |
}) | ||
} | ||
|
||
// We clear the default timeout so we can handle | ||
// the timeout ourselves | ||
cy.clearTimeout() | ||
|
||
const verifyAssertions = () => { | ||
return Cypress.backend('read:file', file, _.pick(options, 'encoding')) | ||
return Cypress.backend('read:file', file, _.pick(options, 'encoding')).timeout(options.timeout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So no server-side timeout? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not with this PR, no. I'm going to log a separate issue to track and evaluate how we want to handle command/server timeouts and increase the determinism of those workflows. |
||
.catch((err) => { | ||
if (err.code === 'ENOENT') { | ||
return { | ||
contents: null, | ||
filePath: err.filePath, | ||
} | ||
if (err.name === 'TimeoutError') { | ||
return $errUtils.throwErrByPath('files.timed_out', { | ||
onFail: options._log, | ||
args: { cmd: 'readFile', file, timeout: options.timeout }, | ||
}) | ||
} | ||
|
||
return $errUtils.throwErrByPath('files.unexpected_error', { | ||
onFail: options._log, | ||
args: { cmd: 'readFile', action: 'read', file, filePath: err.filePath, error: err.message }, | ||
}) | ||
}).then(({ contents, filePath }) => { | ||
// Non-ENOENT errors are not retried | ||
if (err.code !== 'ENOENT') { | ||
return $errUtils.throwErrByPath('files.unexpected_error', { | ||
onFail: options._log, | ||
args: { cmd: 'readFile', action: 'read', file, filePath: err.filePath, error: err.message }, | ||
}) | ||
} | ||
|
||
return { | ||
contents: null, | ||
filePath: err.filePath, | ||
} | ||
}).then(({ filePath, contents }) => { | ||
// https://github.com/cypress-io/cypress/issues/1558 | ||
// We invoke Buffer.from() in order to transform this from an ArrayBuffer - | ||
// which socket.io uses to transfer the file over the websocket - into a | ||
|
@@ -110,14 +122,15 @@ export default (Commands, Cypress, cy) => { | |
encoding: encoding === undefined ? 'utf8' : encoding, | ||
flag: userOptions.flag ? userOptions.flag : 'w', | ||
log: true, | ||
timeout: Cypress.config('defaultCommandTimeout'), | ||
}) | ||
|
||
const consoleProps = {} | ||
|
||
if (options.log) { | ||
options._log = Cypress.log({ | ||
message: fileName, | ||
timeout: 0, | ||
timeout: options.timeout, | ||
consoleProps () { | ||
return consoleProps | ||
}, | ||
|
@@ -142,19 +155,25 @@ export default (Commands, Cypress, cy) => { | |
contents = JSON.stringify(contents, null, 2) | ||
} | ||
|
||
return Cypress.backend('write:file', fileName, contents, _.pick(options, ['encoding', 'flag'])) | ||
.then(({ contents, filePath }) => { | ||
// We clear the default timeout so we can handle | ||
// the timeout ourselves | ||
cy.clearTimeout() | ||
|
||
return Cypress.backend('write:file', fileName, contents, _.pick(options, 'encoding', 'flag')).timeout(options.timeout) | ||
.then(({ filePath, contents }) => { | ||
consoleProps['File Path'] = filePath | ||
consoleProps['Contents'] = contents | ||
|
||
return null | ||
}).catch(Promise.TimeoutError, () => { | ||
return $errUtils.throwErrByPath('files.timed_out', { | ||
onFail: options._log, | ||
args: { cmd: 'writeFile', file: fileName, timeout: options.timeout }, | ||
}) | ||
}) | ||
.catch((err) => { | ||
if (err.name === 'TimeoutError') { | ||
return $errUtils.throwErrByPath('files.timed_out', { | ||
onFail: options._log, | ||
args: { cmd: 'writeFile', file: fileName, timeout: options.timeout }, | ||
}) | ||
} | ||
|
||
return $errUtils.throwErrByPath('files.unexpected_error', { | ||
onFail: options._log, | ||
args: { cmd: 'writeFile', action: 'write', file: fileName, filePath: err.filePath, error: err.message }, | ||
|
Uh oh!
There was an error while loading. Please reload this page.