You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use cypress-grep to filter my tests based on tags, but I'm running into some issues when passing constant tags into the describe block and trying to filter the tests at runtime.
Here’s what I’ve tried:
I have an array of tags that I want to use in my tests:
I want to dynamically pass these tags into the describe block. So, I’m trying something like this:
describe('Running test case with tags', { tags: ['cal', ...tags] }, () => {
it(Test case 1 -, { tags: tags }, () => {
// Test code for smoke
});
});
In the above code:
I’m using ...tags to spread the constant tags into the tags property of describe.
Inside each test case (it block), I’m passing the tags like tags: tags.
The Problem:
When I run the tests using the following command to filter by calc and Basic:
npx cypress run --env grepTags=cal+@basic
It ends up filtering all the .cy.js files rather than just the tests that match the filter. Here’s an example of some of the files being run:
Number of specs after filtering: 5
Specs after filtering:
Running with tags: cal+Basic
It seems like cypress-grep isn’t filtering by the tags as expected.
What I Need Help With:
I would greatly appreciate your assistance in understanding how to correctly pass constant tags into the describe block in a way that the cypress-grep filtering works as expected. I want to ensure that the filtering mechanism is properly applied at runtime.
Why the Filter Command Isn’t Working:
I am encountering an issue where the filter command --env grepTags=cal+Basic does not seem to filter out only the relevant tests, and instead, it ends up filtering more than expected. Could anyone kindly help me understand why this is happening and how I can resolve the issue to ensure the correct tests are filtered?
I’ve tried so far
describe('Running test case with tags', {
tags: ['@cal', ...tags]
}, () => {
// ...existing code...
});
describe('Running test case with tags', {
tags: ['@cal'].concat(Cypress.env('TEST_TAGS') || tags)
}, () => {
// ...existing code...
});
const dynamicTags = tags.map(tag => tag.startsWith('@') ? tag : @${tag});
describe('Running test case with tags', {
tags: ['@cal'].concat(dynamicTags)
}, () => {
// ...existing code...
});
describe('Running test case with tags', {
tags: ['@cal'].concat(
Cypress.env('grepTags') ?
Cypress.env('grepTags').split('+') :
tags
)
}, () => {
// ...existing code...
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm trying to use cypress-grep to filter my tests based on tags, but I'm running into some issues when passing constant tags into the describe block and trying to filter the tests at runtime.
Here’s what I’ve tried:
I have an array of tags that I want to use in my tests:
const tags = [
'@smoke',
'@regression',
'@basic',
'@ttp',
'@ws',
'@ruby',
];
I want to dynamically pass these tags into the describe block. So, I’m trying something like this:
describe('Running test case with tags', { tags: ['cal', ...tags] }, () => {
it(
Test case 1 -
, { tags: tags }, () => {// Test code for smoke
});
});
In the above code:
I’m using ...tags to spread the constant tags into the tags property of describe.
Inside each test case (it block), I’m passing the tags like tags: tags.
The Problem:
When I run the tests using the following command to filter by calc and Basic:
npx cypress run --env grepTags=cal+@basic
It ends up filtering all the .cy.js files rather than just the tests that match the filter. Here’s an example of some of the files being run:
Number of specs after filtering: 5
Specs after filtering:
Running with tags: cal+Basic
cypress/../../spec1.cy.js
cypress/../../spec2.cy.js
cypress/../../spec3.cy.js
cypress/../../spec4.cy.js
cypress/../../spec5.cy.js
It seems like cypress-grep isn’t filtering by the tags as expected.
What I Need Help With:
I would greatly appreciate your assistance in understanding how to correctly pass constant tags into the describe block in a way that the cypress-grep filtering works as expected. I want to ensure that the filtering mechanism is properly applied at runtime.
Why the Filter Command Isn’t Working:
I am encountering an issue where the filter command --env grepTags=cal+Basic does not seem to filter out only the relevant tests, and instead, it ends up filtering more than expected. Could anyone kindly help me understand why this is happening and how I can resolve the issue to ensure the correct tests are filtered?
I’ve tried so far
describe('Running test case with tags', {
tags: ['@cal', ...tags]
}, () => {
// ...existing code...
});
describe('Running test case with tags', {
tags: ['@cal'].concat(Cypress.env('TEST_TAGS') || tags)
}, () => {
// ...existing code...
});
const dynamicTags = tags.map(tag => tag.startsWith('@') ? tag :
@${tag}
);describe('Running test case with tags', {
tags: ['@cal'].concat(dynamicTags)
}, () => {
// ...existing code...
});
describe('Running test case with tags', {
tags: ['@cal'].concat(
Cypress.env('grepTags') ?
Cypress.env('grepTags').split('+') :
tags
)
}, () => {
// ...existing code...
});
Beta Was this translation helpful? Give feedback.
All reactions