Reputation: 473
Problem Description: I wanted to hide the untagged test execution from the console output in jest-cucumber library?
Test: @smoke Scenario: Successful Login Given I am on the login page When I fill in "username" with "test" And I fill in "password" with "test" And I click on the "Login" button Then I should see the "Welcome" page
Scenario: Failed Login Given I am on the login page When I fill in "username" with "test" And I fill in "password" with "wrong password" And I click on the "Login" button Then I should see the "Error" page
I am running the tests with tag smoke. The jest-cucumber runner works as expected. I just want to hide the console logs for skipped tests.
Execution command:
user01@12343 my-e2e-tests % NODE_ENV=uat TAG_FILTER='@smoke' jest
Console Log:
PASS tests/featureFileLoader.ts Home Page ✓ Successful Login (1249 ms) ○ Failed Login
I would like to hide the execution of Failed Login tests in console logs.
custom-reporter.js
const { setDefaultTimeout } = require('@cucumber/cucumber');
const originalLog = console.log;
// Modify console.log to only print for tagged scenarios
console.log = (...args) => {
const currentTest = expect.getState().currentTestName;
// Check if the current test name contains a tag you want to show logs for
if (currentTest && (currentTest.includes('@smoke'))) {
originalLog(...args);
}
};
setDefaultTimeout(60000);
Tried to retrieves the name of the current test scenario using expect.getState().currentTestName.
It checks if the current test name contains the tag @smoke. If it does, it calls the original console.log to print the logs; otherwise, the logs are suppressed.
This isn't functioning as expected. I would appreciate any insights you might have on this.
Upvotes: 0
Views: 9