cypress
cypress copied to clipboard
Before() is executed even if it's parent is filtered out
With this spec file:
describe('Cypress grep', {
tags: '@smoke'
}, () => {
before(() => {
expect(false).to.equal(true)
})
it('succeeds', () => {
expect(true).to.equal(true)
})
})
When executing cypress with --env grepTags=-@smoke, the test fails because the before() function is executed even though the whole describe is not supposed to be executed.
Not proper solution, but my hotfix
// Taken from https://github.com/mochajs/mocha/pull/4189/files#diff-37b88258822cb207e2caa1a88d4fbc057924da72c5580d1f39b78349214ab622R805
export function calculateNotSkippedTests(suite) {
const { tests } = suite;
let total = tests.filter((test) => !test.isPending()).length;
for (let i = 0; i < suite.suites.length; i += 1) {
const childSuite = suite.suites[i];
total += calculateNotSkippedTests(childSuite);
}
return total;
}
// ...
before(() => {
if (!calculateNotSkippedTests(global.mocha.suite)) return; // no test running in this suite, skip before
This issue is also reproductible for after() hook
In my case I have a describe block with an before() hook, followed by beforeEach(), then some it() blocks, and finally an after() hook. Strangely, grep runs before() and after() hook in some specs, while it does not in other specs
We also have this problem. I think the best solution for the moment is to just lock the version to cypress-grep 2.5.1, which does not have this issue.
In my case I have a describe block with an before() hook, followed by beforeEach(), then some it() blocks, and finally an after() hook. Strangely, grep runs before() and after() hook in some specs, while it does not in other specs
I got a workaround for this, by applying a check for the "grepTags" env variable has a value set in it at the start of before() and after() hook
We upgraded to the new version since grepOmitFiltered actually works to bypass this issue: https://github.com/cypress-io/cypress-grep/pull/84
Facing the same issue, both before and after block get executed even if the describe block is meant to filter out
describe("describe block 1", {tags:"@sanity"} ,function(){
it("it block 1 ", function(){
cy.log("dec block 1 it block")
})
})
describe("describe block 2 ",{tags:"@regression"},function(){
before("before block", function(){
cy.log("before")
cy.wait(10000)
})
it("it block 2",function(){
cy.log("it block 2")
})
it("it block 3",function(){
cy.log("it block 3")
})
after("After block", function(){
cy.log("after")
cy.wait(10000)
})
})
With --env grepTags=@sanity , expected only "it block 1" to be executed rest all it, before and after block to be filter out/skipped
My issue is when I'm using .skip in a test not tagged, cause it still runs the beforeAll and afterAll. I'm on version 2.10.2.
If I run with a tag --env grepTags=@grep to not include the specs below, spec 1 is not executed while the second one is and fails on the before(). Using grepFilterSpecs or grepOmitFiltered doesn't seem to make any difference.
Spec 1
describe('1-Test Untagged', function (){
before(() => {
expect(false).to.equal(true)
})
it('1-Test log', function () {
cy.log("block 1")
})
})
Spec 2
describe('2-Test Untagged With Skipped Test', function(){
before(() => {
expect(false).to.equal(true)
})
it.skip('1-Test log', function () {
cy.log("block 1")
})
})
Same issue, the latest version The grep filter is not working when there's a before() or beforeall() or after() block
We upgraded to the new version since grepOmitFiltered actually works to bypass this issue: cypress-io/cypress-grep#84
@nicolajv I'm assuming that doesn't work for negative filters... since grepOmitFiltered doesn't support it?
When I run below spec with this command: npx cypress run --env=grepTags=@smoke, 2nd test is getting passed as expected but the 1st test is FAILING instead of going into pending/skipped state. Need your help on this
describe('grand',{tags: '@ha-smoke'}, () => { before(() => { expect(true).to.be.false }) it('runs', () => {}) })
describe('top',{tags: '@smoke'}, () => { it('runs too', () => {}); })
With this spec file:
describe('Cypress grep', { tags: '@smoke' }, () => { before(() => { expect(false).to.equal(true) }) it('succeeds', () => { expect(true).to.equal(true) }) })When executing cypress with
--env grepTags=-@smoke, the test fails because thebefore()function is executed even though the whole describe is not supposed to be executed.
Even I'm facing the same, Have you fixed this? Any suggestions?
I have the same issue I believe, I pass something like --env grepTags=@login and it will run those tagged tests but it runs the before hook from a couple unrelated test suites no matter which tag I use.
Any updates on this? It is a very problematic issue
any updates on this ???
any updates on this ??? @nagash77 @jordanpowell88
any updates on this ?
@jordanpowell88 @nagash77
any update here? facing same issue
any update here? We can't use grep till this is resolved
Do we have any update here?
Any updates on this?
@cypress-github-team-services-sa I also have a problem with this in the latest Cypress v13.9.0 Instead of skipping tests that do not have a specific tag, the test runs afterAll for a given describe block.
For me, this greatly limits the possibility of using tags, Cypress recommends before/after blocks. Please make this a higher priority.
Any updates here? I can still repro this issue. Thanks!
This would be a great one for us to be fixed
Any updates here? facing same issue