-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
afterEach block in @cypress/code-coverage/support.js executing concurrently with beforeEach test spec #27021
Comments
Hi @mhyrka 👋, thanks for taking the time to log this issue. It does seem very strange that the |
Hi @mschile thanks for the prompt response. I believe I have been able to reproduce the error. Code can be found in this git repo. I basically just used the auth0 react sample so I could simulate the SSO that we use and then made similar config changes to those listed above. Just clone and then |
Any update on this? |
Hi @mhyrka , thank you for the reproduction repository. I was able to trigger a similar error there, but it may have ben because of a an auth misconfiguration. Can you supply a working test configuration? In your recording, it looks like there was an error creating the session in the beforeEach - there is an uncaught TypeError. When Cypress encounters an error in the beforeEach block, it still executes the afterEach block. If you resolve this uncaught exception, do you still see this behavior? |
The uncaught TypeError from the recording is because the afterEach block seems to execute before the action |
Thanks again, @mhyrka ! I think I have a workaround for you - can you try |
Updated to return |
I am glad to find this post because I also have the same issue. I can provide a bit more information on this. Unlike this example, I am using babel with istanbul for instrumentation. My .bablerc file is as follows:- {
"presets": ["next/babel"],
"plugins": ["istanbul"]
} My login custom command is also similar:- Cypress.Commands.add("login", () => {
cy.session(Cypress.env("username"), () => {
cy.visit("/");
cy.origin(Cypress.env("okta_domain"), () => {
cy.get("input[name='identifier']").type(Cypress.env("username"));
cy.get("input[value='Next']").click();
cy.get("input[name='credentials.passcode']").type(
Cypress.env("password"),
);
cy.get("input[value='Verify']").click();
cy.get("input[name='credentials.answer']").type(
Cypress.env("security_answer"),
);
cy.get('[type="submit"]').click();
});
cy.get("#page-header").should("have.text", "All Rates");
});
}); I am using Nextjs and Typescript so I also have this login method in Chainable interface declare namespace Cypress {
interface Chainable {
login(): void;
}
} As of today, the package versions are "@cypress/code-coverage": "^3.12.1" and "cypress": "^13.2.0" Here is the snapshot from cypress while running the login command:- The Cypress error from console is:-
Seems like it doesn't wait automatically for the .get() to return before chaining the .type() I was able to get it working by putting explicit .wait(2000) after each button click to let the page load but then this error happens at the end when the final assertion of cy.get("#page-header").should("have.text", "All Rates"); succeeds!
I know the session has created successfully because when I re-run the tests, it says "Session restored" and all tests pass. |
We seem to be having the same issue. Our test redirects to the Okta login page and before it can do anything, it errors out. Removing |
We were able to switch over to the programmatic login and that allowed us to work around the issue. https://docs.cypress.io/guides/end-to-end-testing/okta-authentication#Programmatic-Login |
We are facing the same issue as well unfortunately and it also happens during the session/origin/login step |
We are also facing the same issue, the first session creation is fine, without any issue, but as soon as I put require('@cypress/code-coverage/task')(on, config) in my setupNodeEvents, any new session in the current test will instant fail. Nuxt config (we use vite-plugin-instanbul for code instrumentation) : import istanbul from 'vite-plugin-istanbul'
export default defineNuxtConfig({
$development: {
vite: {
define: {
global: 'window'
},
plugins: [
istanbul({
exclude: ['node_modules', 'test/', 'coverage/', 'cypress/'],
extension: [ '.js', '.ts', '.vue' ],
cypress: true
}),
]
},
},
...
}) Cypress config : export default defineConfig({
defaultCommandTimeout: CypressTimeoutEnum.short,
viewportWidth: 1920,
viewportHeight: 1080,
e2e: {
baseUrl: 'http://localhost:3000',
testIsolation: false,
setupNodeEvents(on, config) {
require('@cypress/code-coverage/task')(on, config)
// include any other plugin code...
// It's IMPORTANT to return the config object
// with any changed environment variables
return config
},
},
}) |
I understand that this issue often happens with session creation, and completely understand how such a sensitive area of the application can be, and how difficult it can be to provide a full reproduction case. To help with this, I've made some updates to make sure that our To help with this, especially if you are using
Taking these steps will help us narrow down what the issue is, so we can help resolve it. Thank you! |
On this issue, I'd also like to add on the That happens in this block:
It's incorrect to assume that The correct way to do it would be using
For additional safety, the This error in Cypress makes it harder to debug the underlying issue that's resulting in the error. |
Current behavior
I am trying to implement code-coverage with cypress as outlined here. Using cypress version 12.13.0 and @cypress/code-coverage version 3.10.7 as well as @cypress/webpack-preprocessor version 5.17.1. Additionally I'm using nyc (via npx) to instrument the code. What makes this more confusing is the fact that everything was working properly until it wasn't and I'm unable to get back to a working state.
Desired behavior
Work as expected and generate code coverage statistics.
Test code to reproduce
import '@cypress/code-coverage/support'
from cypress/support/e2e.js eliminates the error (but doesn't write coverage stats).// package.json
Cypress Version
12.13.0
Node version
16.20.0
Operating System
macOS 13.4
Debug Logs
I can't paste the debug logs for risk of exposing a secret.
Other
No response
The text was updated successfully, but these errors were encountered: