gorgeous-kitchen-56640
05/15/2023, 4:53 PMvisit command is started (whichever comes first).
The issue is that, in order to output to the stdout, I am using cy.task('log', ...), a pretty familiar pattern, I'm sure, since it's outlined in Cypress' own docs for cy.task. When this command is run within the context of a cy.visit command, it gives me this error: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise. (outlined here: https://docs.cypress.io/guides/references/error-messages#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise). There are no promises being used anywhere, so I figure the mere usage of cy.task is a violation.
To me, this would indicate that there's actually no safe way to output to stdout from within the context of a command, which seems like a major shortcoming of the interface. But I'm sure I'm missing something.
Example code:
// plugins code
...
on('task', {
log(message) {
// eslint-disable-next-line no-console
console.log(message);
return null;
},
...
// func that logs to cy.task
function someFunc() {
cy.task('log', 'log to stdout');
}
// func that overwrites visit
Cypress.Commands.overwrite(
'visit',
(originalFn, url, options) => {
someFunc();
return originalFn(url, options);
}
);gray-kilobyte-89541
05/15/2023, 5:17 PMgorgeous-kitchen-56640
05/15/2023, 5:18 PMgorgeous-kitchen-56640
05/15/2023, 5:23 PMgray-kilobyte-89541
05/15/2023, 6:33 PMjs
Cypress.Commands.overwrite(
'visit',
(originalFn, url, options) => {
someFunc();
originalFn(url, options);
}
);gorgeous-kitchen-56640
05/15/2023, 6:55 PMgorgeous-kitchen-56640
05/15/2023, 6:59 PMgray-kilobyte-89541
05/15/2023, 11:28 PMcy.visit command before, but cannot find an example right nowgorgeous-kitchen-56640
05/16/2023, 3:49 PM