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

Global afterEach in e2e.js doesn't work #30208

Closed
xavigimenezsanchez opened this issue Sep 9, 2024 · 1 comment
Closed

Global afterEach in e2e.js doesn't work #30208

xavigimenezsanchez opened this issue Sep 9, 2024 · 1 comment

Comments

@xavigimenezsanchez
Copy link

Current behavior

Global afterEach in e2e.js doesn't work when I run cypress headless (cypress run) but it works when I run cypress with the UI (cypress open).
However, it does work with global beforeEach

Desired behavior

Global afterEach in e2e.js works

Test code to reproduce

https://github.com/xavigimenezsanchez/cypress-cancel-request

Cypress Version

12.8.1

Node version

18.15.0

Operating System

Windows 11 Enterprise, Version: 23H2, OS build: 22631.4037, Experience: Windows Feature Experience Pack 1000.22700.1027.0

Debug Logs

empty spec
          cy:log i  I run before every test in this file
      cy:command +  visit       https://example.cypress.io
      cy:command +  get :nth-child(2) > ul > :nth-child(5)


    √ first test (603ms)
          cy:log i  I run before every test in this file
      cy:command +  visit       https://example.cypress.io
      cy:command +  get :nth-child(2) > ul > :nth-child(5)


    √ second test (249ms)

Other

No response

@jennifer-shehane
Copy link
Member

This looks to be an issue with cypress-terminal-reporter and not cypress itself. If I replace the terminal-reporter code from printing with cy.task to log in the console, it does log before each test.

Screenshot 2024-09-10 at 1 28 35 PM

cypress.config.js

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  // setupNodeEvents can be defined in either
  // the e2e or component configuration
  e2e: {
    setupNodeEvents(on, config) {
      on('task', {
        log(message) {
          console.log(message)

          return null
        },
      })
    },
  },
})

cypress/support/e2e/js

import "./commands";

beforeEach(() => {
  cy.task("log", "I run before every test in this file");
});

afterEach(() => {
  cy.task("log", "I run after every test in this file");
});

@jennifer-shehane jennifer-shehane closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants