From ef98635bd77cc5e64e13e67fcd1b597ab2914606 Mon Sep 17 00:00:00 2001 From: Priyansh Garg Date: Fri, 16 Feb 2024 16:11:58 +0530 Subject: [PATCH] Disable HTML reporter in Cucumber. (#4025) --- lib/reporter/global-reporter.js | 10 +++++++--- lib/runner/test-runners/cucumber.js | 20 +++++++++++++++++++ .../cucumber/_setup_cucumber_runner.js | 2 -- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/lib/reporter/global-reporter.js b/lib/reporter/global-reporter.js index 341d0cf0f5..a9f48c6f05 100644 --- a/lib/reporter/global-reporter.js +++ b/lib/reporter/global-reporter.js @@ -36,11 +36,15 @@ module.exports = class GlobalReporter { this.suiteResults = []; this.skippedSuites = 0; this.uncaughtErr = null; - this.reporterFile = reporter; this.reportFileName = reportFileName; - if (!Array.isArray(this.reporterFile) && typeof this.reporterFile == 'string') { - this.reporterFile = this.reporterFile.split(','); + this.reporterFile = []; + if (Array.isArray(reporter)) { + // Any subsequent changes in `this.reporterFile` shouldn't lead to changes in + // `argv.reporter` provided by the user, or `DefaultSettings.default_reporter`. + this.reporterFile = reporter.slice(0); + } else if (typeof reporter == 'string') { + this.reporterFile = reporter.split(','); } this.settings = settings; this.summary = new Summary(settings); diff --git a/lib/runner/test-runners/cucumber.js b/lib/runner/test-runners/cucumber.js index 342d8e1a0e..6a505a03f8 100644 --- a/lib/runner/test-runners/cucumber.js +++ b/lib/runner/test-runners/cucumber.js @@ -4,6 +4,7 @@ const TestSuite = require('../../testsuite'); const {Logger, isString, isDefined} = require('../../utils'); const {NightwatchEventHub} = require('../eventHub.js'); const {getTestSourceForRerunFailed} = require('../rerunUtil.js'); +const DefaultSettings = require('../../settings/defaults.js'); class CucumberSuite extends TestSuite { static isSessionCreateError(err) { @@ -252,6 +253,25 @@ class CucumberRunnner extends Runner { return 'cucumber'; } + constructor(settings, argv, addtOpts) { + super(settings, argv, addtOpts); + + // Disable HTML Reporter as it is not yet supported in Cucumber. + const reporterFile = this.globalReporter.reporterFile; + if (reporterFile && reporterFile.includes('html')) { + if (reporterFile.toString() !== DefaultSettings.default_reporter.toString()) { + // user has specifically asked for HTML report. + // eslint-disable-next-line no-console + console.warn(Logger.colors.yellow('HTML reporter is not supported with Cucumber runner.')); + } + + const index = reporterFile.indexOf('html'); + if (index > -1) { + reporterFile.splice(index, 1); + } + } + } + hasTestFailures(result) { return result && result.success === false; } diff --git a/lib/runner/test-runners/cucumber/_setup_cucumber_runner.js b/lib/runner/test-runners/cucumber/_setup_cucumber_runner.js index a0f2dcb7ec..3cba54a949 100644 --- a/lib/runner/test-runners/cucumber/_setup_cucumber_runner.js +++ b/lib/runner/test-runners/cucumber/_setup_cucumber_runner.js @@ -7,8 +7,6 @@ Before(function({pickle, testCaseStartedId}) { const webdriver = {}; process.env.CUCUMBER_TEST_CASE_STARTED_ID = testCaseStartedId; - // eslint-disable-next-line no-console - console.log('setup_cucumber_before', 'PID:', process.pid, 'testCaseStartedId:', testCaseStartedId); if (this.parameters['webdriver-host']) { webdriver.host = this.parameters['webdriver-host'];