From 124fa3e612b5349a262f39846823d00c299ab3c9 Mon Sep 17 00:00:00 2001 From: amsterget Date: Thu, 27 Aug 2020 21:07:49 +0300 Subject: [PATCH] Enhancement on scenario name (closes #37 #40) --- modules/cucumber-reportportal-formatter.js | 42 +++++++++---------- modules/utils.js | 1 + tests/cucumber-reportportal-formatter.spec.js | 1 + 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/cucumber-reportportal-formatter.js b/modules/cucumber-reportportal-formatter.js index 4c0248b..e0982a5 100644 --- a/modules/cucumber-reportportal-formatter.js +++ b/modules/cucumber-reportportal-formatter.js @@ -162,31 +162,27 @@ const createRPFormatterClass = (config) => { [utils.getUri(event.sourceLocation.uri), event.sourceLocation.line].join(':'); const { featureId } = this.documentsStorage.featureData[event.sourceLocation.uri]; - if (this.contextState.context.lastScenarioDescription !== name) { - this.contextState.context.lastScenarioDescription = name; - this.contextState.context.outlineRow = 0; - } else if (event.attemptNumber < 2) { - this.contextState.context.outlineRow += 1; - name += ` [${this.contextState.context.outlineRow}]`; + if (!(name in this.contextState.context.scenarioNames)) { + this.contextState.context.scenarioNames[name] = 1; + } else { + this.contextState.context.scenarioNames[name] += 1; + name += ` [${this.contextState.context.scenarioNames[name]}]`; } - // BeforeScenario - if (this.isScenarioBasedStatistics || event.attemptNumber < 2) { - this.contextState.context.scenarioId = this.reportportal.startTestItem( - { - name, - startTime: this.reportportal.helpers.now(), - type: this.isScenarioBasedStatistics ? 'STEP' : 'TEST', - description, - codeRef: utils.formatCodeRef(event.sourceLocation.uri, name), - parameters: this.contextState.context.scenario.parameters, - attributes: itemAttributes, - retry: false, - }, - this.contextState.context.launchId, - featureId, - ).tempId; - } + this.contextState.context.scenarioId = this.reportportal.startTestItem( + { + name, + startTime: this.reportportal.helpers.now(), + type: this.isScenarioBasedStatistics ? 'STEP' : 'TEST', + description, + codeRef: utils.formatCodeRef(event.sourceLocation.uri, name), + parameters: this.contextState.context.scenario.parameters, + attributes: itemAttributes, + retry: false, + }, + this.contextState.context.launchId, + featureId, + ).tempId; } onTestStepStarted(event) { diff --git a/modules/utils.js b/modules/utils.js index 0a4e8d6..0b191aa 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -42,6 +42,7 @@ const cleanContext = () => ({ background: null, failedScenarios: {}, scenariosCount: {}, + scenarioNames: {}, lastScenarioDescription: null, scenario: null, step: null, diff --git a/tests/cucumber-reportportal-formatter.spec.js b/tests/cucumber-reportportal-formatter.spec.js index 28c3430..071354b 100644 --- a/tests/cucumber-reportportal-formatter.spec.js +++ b/tests/cucumber-reportportal-formatter.spec.js @@ -1,3 +1,4 @@ +/* These tests need to be rewritten to reflect the refactoring of the agent. Plans for version 5.0.1. */ const { createRPFormatterClass } = require('../modules'); const { ContextMock,