From 9daa87e825497403e22459bd0dc51be064efca34 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Sep 2021 18:57:28 +0300 Subject: [PATCH 01/24] feature/list-formatters-in-help-command adding documentation field to Formatter class --- src/formatter/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/formatter/index.ts b/src/formatter/index.ts index 91f77a27c..5156c7344 100644 --- a/src/formatter/index.ts +++ b/src/formatter/index.ts @@ -39,6 +39,7 @@ export default class Formatter { protected stream: WritableStream protected supportCodeLibrary: ISupportCodeLibrary private readonly cleanup: IFormatterCleanupFn + protected readonly documentation: string constructor(options: IFormatterOptions) { this.colorFns = options.colorFns From 96e30e54c53744af7b673f42eeff6a92846b3c56 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2021 00:06:22 +0300 Subject: [PATCH 02/24] feature/list-formatters-in-help-command refactoring getConstructorByType method to hold a Record --- src/formatter/builder.ts | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 27da244eb..e3e3deaf4 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -61,30 +61,22 @@ const FormatterBuilder = { }, getConstructorByType(type: string, cwd: string): typeof Formatter { - switch (type) { - case 'json': - return JsonFormatter - case 'message': - return MessageFormatter - case 'html': - return HtmlFormatter - case 'progress': - return ProgressFormatter - case 'progress-bar': - return ProgressBarFormatter - case 'rerun': - return RerunFormatter - case 'snippets': - return SnippetsFormatter - case 'summary': - return SummaryFormatter - case 'usage': - return UsageFormatter - case 'usage-json': - return UsageJsonFormatter - default: - return FormatterBuilder.loadCustomFormatter(type, cwd) + + const formatters: Record = { + 'json': JsonFormatter, + 'message': MessageFormatter, + 'html': HtmlFormatter, + 'progress': ProgressFormatter, + 'progress-bar': ProgressBarFormatter, + 'rerun': RerunFormatter, + 'snippets': SnippetsFormatter, + 'summary': SummaryFormatter, + 'usage': UsageFormatter, + 'usage-json': UsageJsonFormatter, + 'default': FormatterBuilder.loadCustomFormatter(type, cwd) } + + return formatters.type }, getStepDefinitionSnippetBuilder({ From a76f2319de1ae4f04b5dbb2d22085d8a26fda51b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2021 00:14:26 +0300 Subject: [PATCH 03/24] feature/list-formatters-in-help-command improving return statement to deal with cases where the default formatter should be returned --- src/formatter/builder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index e3e3deaf4..e5a439867 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -76,7 +76,7 @@ const FormatterBuilder = { 'default': FormatterBuilder.loadCustomFormatter(type, cwd) } - return formatters.type + return formatters[type] ? formatters[type] : formatters.default }, getStepDefinitionSnippetBuilder({ From ced6ecc3dade5a595e05785c56c5c469f69c4460 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2021 12:24:35 +0300 Subject: [PATCH 04/24] feature/list-formatters-in-help-command after running lint fix --- src/formatter/builder.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index e5a439867..515078ce5 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -61,19 +61,18 @@ const FormatterBuilder = { }, getConstructorByType(type: string, cwd: string): typeof Formatter { - const formatters: Record = { - 'json': JsonFormatter, - 'message': MessageFormatter, - 'html': HtmlFormatter, - 'progress': ProgressFormatter, + json: JsonFormatter, + message: MessageFormatter, + html: HtmlFormatter, + progress: ProgressFormatter, 'progress-bar': ProgressBarFormatter, - 'rerun': RerunFormatter, - 'snippets': SnippetsFormatter, - 'summary': SummaryFormatter, - 'usage': UsageFormatter, + rerun: RerunFormatter, + snippets: SnippetsFormatter, + summary: SummaryFormatter, + usage: UsageFormatter, 'usage-json': UsageJsonFormatter, - 'default': FormatterBuilder.loadCustomFormatter(type, cwd) + default: FormatterBuilder.loadCustomFormatter(type, cwd), } return formatters[type] ? formatters[type] : formatters.default From 4c89feafca7384eb9e66fedd614d77f8d8fc8f67 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Sep 2021 13:04:16 +0300 Subject: [PATCH 05/24] feature/list-formatters-in-help-command fixing ternary so logic does not invoke load customFormatter --- src/formatter/builder.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 515078ce5..294d51fc8 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -72,10 +72,11 @@ const FormatterBuilder = { summary: SummaryFormatter, usage: UsageFormatter, 'usage-json': UsageJsonFormatter, - default: FormatterBuilder.loadCustomFormatter(type, cwd), } - return formatters[type] ? formatters[type] : formatters.default + return formatters[type] + ? formatters[type] + : FormatterBuilder.loadCustomFormatter(type, cwd) }, getStepDefinitionSnippetBuilder({ From 7e4a398fc57bda53de3979233be9042683a90cf5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 25 Sep 2021 12:58:20 +0300 Subject: [PATCH 06/24] feature/list-formatters-in-help-command creating class that will hold the description of the formatters --- src/formatter/formatterDocumentationHelper.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/formatter/formatterDocumentationHelper.ts diff --git a/src/formatter/formatterDocumentationHelper.ts b/src/formatter/formatterDocumentationHelper.ts new file mode 100644 index 000000000..ad214c43f --- /dev/null +++ b/src/formatter/formatterDocumentationHelper.ts @@ -0,0 +1,21 @@ +const FormatterDocumentation = { + getFormatterDocumentationByType(type: string): string { + const formatterDocumentationText: Record = { + json: 'Prints the feature as JSON. The JSON format is in maintenance mode. Please consider using the message formatter with the standalone json-formatter (https://github.com/cucumber/cucumber/tree/master/json-formatter).', + message: 'Outputs protobuf messages', + html: 'Outputs HTML report', + progress: 'Prints one character per scenario.', + 'progress-bar': '', + rerun: 'Prints failing files with line numbers.', + snippets: '', + summary: 'Summary output of feature and scenarios', + usage: + 'Prints where step definitions are used. The slowest step definitions (with duration) are listed first. If --dry-run is used the duration is not shown, and step definitions are sorted by filename instead.', + 'usage-json': '', + } + + return formatterDocumentationText[type] + }, +} + +export default FormatterDocumentation From 0b9e4cdd9f44d6f58e566bb872bf11bc0538000e Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 25 Sep 2021 15:14:08 +0300 Subject: [PATCH 07/24] feature/list-formatters-in-help-command adding logic to extract the correct documentation for each formatter and altering the IFormatter type to have this field --- src/formatter/builder.ts | 4 ++++ src/formatter/index.ts | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 294d51fc8..2c2582e90 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -21,6 +21,7 @@ import { IParsedArgvFormatOptions } from '../cli/argv_parser' import { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax' import HtmlFormatter from './html_formatter' import createRequire from 'create-require' +import FormatterDocumentationHelper from './formatterDocumentationHelper' interface IGetStepDefinitionSnippetBuilderOptions { cwd: string @@ -53,9 +54,12 @@ const FormatterBuilder = { snippetSyntax: options.parsedArgvOptions.snippetSyntax, supportCodeLibrary: options.supportCodeLibrary, }) + const documentation: string = + FormatterDocumentationHelper.getFormatterDocumentationByType(type) return new FormatterConstructor({ colorFns, snippetBuilder, + documentation, ...options, }) }, diff --git a/src/formatter/index.ts b/src/formatter/index.ts index 5156c7344..30510af0f 100644 --- a/src/formatter/index.ts +++ b/src/formatter/index.ts @@ -28,6 +28,7 @@ export interface IFormatterOptions { stream: WritableStream cleanup: IFormatterCleanupFn supportCodeLibrary: ISupportCodeLibrary + documentation: string } export default class Formatter { @@ -50,6 +51,7 @@ export default class Formatter { this.stream = options.stream this.supportCodeLibrary = options.supportCodeLibrary this.cleanup = options.cleanup + this.documentation = options.documentation } async finished(): Promise { From ba24272a13c88804a6717d32ad411a74cc10851f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Sep 2021 22:40:37 +0300 Subject: [PATCH 08/24] feature/list-formatters-in-help-command reverting changes made by adding the documentation field to the formatter object --- src/formatter/builder.ts | 4 ---- src/formatter/index.ts | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 2c2582e90..294d51fc8 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -21,7 +21,6 @@ import { IParsedArgvFormatOptions } from '../cli/argv_parser' import { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax' import HtmlFormatter from './html_formatter' import createRequire from 'create-require' -import FormatterDocumentationHelper from './formatterDocumentationHelper' interface IGetStepDefinitionSnippetBuilderOptions { cwd: string @@ -54,12 +53,9 @@ const FormatterBuilder = { snippetSyntax: options.parsedArgvOptions.snippetSyntax, supportCodeLibrary: options.supportCodeLibrary, }) - const documentation: string = - FormatterDocumentationHelper.getFormatterDocumentationByType(type) return new FormatterConstructor({ colorFns, snippetBuilder, - documentation, ...options, }) }, diff --git a/src/formatter/index.ts b/src/formatter/index.ts index 30510af0f..5156c7344 100644 --- a/src/formatter/index.ts +++ b/src/formatter/index.ts @@ -28,7 +28,6 @@ export interface IFormatterOptions { stream: WritableStream cleanup: IFormatterCleanupFn supportCodeLibrary: ISupportCodeLibrary - documentation: string } export default class Formatter { @@ -51,7 +50,6 @@ export default class Formatter { this.stream = options.stream this.supportCodeLibrary = options.supportCodeLibrary this.cleanup = options.cleanup - this.documentation = options.documentation } async finished(): Promise { From e322a2021cd2eb8e704ee2283b4317a2791b432c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Sep 2021 22:41:43 +0300 Subject: [PATCH 09/24] feature/list-formatters-in-help-command adding documentation field to html formatter --- src/formatter/html_formatter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/formatter/html_formatter.ts b/src/formatter/html_formatter.ts index fc43c22e2..458e76fae 100644 --- a/src/formatter/html_formatter.ts +++ b/src/formatter/html_formatter.ts @@ -8,6 +8,7 @@ import { promisify } from 'util' export default class HtmlFormatter extends Formatter { private readonly _finished: Promise + public static readonly documentation: string = 'Outputs HTML report' constructor(options: IFormatterOptions) { super(options) From 36f58562dae45f9e52cc2598dad5f36a5766d9da Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Sep 2021 23:38:25 +0300 Subject: [PATCH 10/24] feature/list-formatters-in-help-command adding documentation member to json/message/progress/rerun/summary/usage formatters --- src/formatter/json_formatter.ts | 3 +++ src/formatter/message_formatter.ts | 1 + src/formatter/progress_formatter.ts | 3 +++ src/formatter/rerun_formatter.ts | 2 +- src/formatter/summary_formatter.ts | 3 +++ src/formatter/usage_formatter.ts | 3 +++ 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/formatter/json_formatter.ts b/src/formatter/json_formatter.ts index 2b2c21c33..cb1396f1a 100644 --- a/src/formatter/json_formatter.ts +++ b/src/formatter/json_formatter.ts @@ -81,6 +81,9 @@ interface UriToTestCaseAttemptsMap { } export default class JsonFormatter extends Formatter { + public static readonly documentation: string = + 'Prints the feature as JSON. The JSON format is in maintenance mode. Please consider using the message formatter with the standalone json-formatter (https://github.com/cucumber/cucumber/tree/master/json-formatter).' + constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: messages.Envelope) => { diff --git a/src/formatter/message_formatter.ts b/src/formatter/message_formatter.ts index d464d1704..15f47b0e0 100644 --- a/src/formatter/message_formatter.ts +++ b/src/formatter/message_formatter.ts @@ -2,6 +2,7 @@ import Formatter, { IFormatterOptions } from '.' import * as messages from '@cucumber/messages' export default class MessageFormatter extends Formatter { + public static readonly documentation: string = 'Outputs protobuf messages' constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: messages.Envelope) => diff --git a/src/formatter/progress_formatter.ts b/src/formatter/progress_formatter.ts index 2bd058505..cc6198c6c 100644 --- a/src/formatter/progress_formatter.ts +++ b/src/formatter/progress_formatter.ts @@ -16,6 +16,9 @@ const STATUS_CHARACTER_MAPPING: Map = ]) export default class ProgressFormatter extends SummaryFormatter { + public static readonly documentation: string = + 'Prints one character per scenario.' + constructor(options: IFormatterOptions) { options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { if (doesHaveValue(envelope.testRunFinished)) { diff --git a/src/formatter/rerun_formatter.ts b/src/formatter/rerun_formatter.ts index da5158faa..b28c0c488 100644 --- a/src/formatter/rerun_formatter.ts +++ b/src/formatter/rerun_formatter.ts @@ -14,7 +14,7 @@ interface UriToLinesMap { } export default class RerunFormatter extends Formatter { - private readonly separator: string + private readonly separator: string = 'Prints failing files with line numbers.' constructor(options: IFormatterOptions) { super(options) diff --git a/src/formatter/summary_formatter.ts b/src/formatter/summary_formatter.ts index e49e342a7..f91034a3d 100644 --- a/src/formatter/summary_formatter.ts +++ b/src/formatter/summary_formatter.ts @@ -12,6 +12,9 @@ interface ILogIssuesRequest { } export default class SummaryFormatter extends Formatter { + public static readonly documentation: string = + 'Summary output of feature and scenarios' + constructor(options: IFormatterOptions) { super(options) let testRunStartedTimestamp: messages.Timestamp diff --git a/src/formatter/usage_formatter.ts b/src/formatter/usage_formatter.ts index ff6afe142..0776d3656 100644 --- a/src/formatter/usage_formatter.ts +++ b/src/formatter/usage_formatter.ts @@ -6,6 +6,9 @@ import * as messages from '@cucumber/messages' import IEnvelope = messages.Envelope export default class UsageFormatter extends Formatter { + public static readonly documentation: string = + 'Prints where step definitions are used. The slowest step definitions (with duration) are listed first. If --dry-run is used the duration is not shown, and step definitions are sorted by filename instead.' + constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { From 22d8d6d0292884dcb504da8b8e75f135db168ad2 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 27 Sep 2021 23:39:44 +0300 Subject: [PATCH 11/24] feature/list-formatters-in-help-command removing formatterDocumentationHelper class as it is no longer needed --- src/formatter/formatterDocumentationHelper.ts | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/formatter/formatterDocumentationHelper.ts diff --git a/src/formatter/formatterDocumentationHelper.ts b/src/formatter/formatterDocumentationHelper.ts deleted file mode 100644 index ad214c43f..000000000 --- a/src/formatter/formatterDocumentationHelper.ts +++ /dev/null @@ -1,21 +0,0 @@ -const FormatterDocumentation = { - getFormatterDocumentationByType(type: string): string { - const formatterDocumentationText: Record = { - json: 'Prints the feature as JSON. The JSON format is in maintenance mode. Please consider using the message formatter with the standalone json-formatter (https://github.com/cucumber/cucumber/tree/master/json-formatter).', - message: 'Outputs protobuf messages', - html: 'Outputs HTML report', - progress: 'Prints one character per scenario.', - 'progress-bar': '', - rerun: 'Prints failing files with line numbers.', - snippets: '', - summary: 'Summary output of feature and scenarios', - usage: - 'Prints where step definitions are used. The slowest step definitions (with duration) are listed first. If --dry-run is used the duration is not shown, and step definitions are sorted by filename instead.', - 'usage-json': '', - } - - return formatterDocumentationText[type] - }, -} - -export default FormatterDocumentation From fb84765335d241e187a3221353c282bf714f820e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Sep 2021 09:07:00 +0300 Subject: [PATCH 12/24] feature/list-formatters-in-help-command adding documentation field to rerun formatter --- src/formatter/rerun_formatter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/formatter/rerun_formatter.ts b/src/formatter/rerun_formatter.ts index b28c0c488..ad840e14d 100644 --- a/src/formatter/rerun_formatter.ts +++ b/src/formatter/rerun_formatter.ts @@ -14,7 +14,9 @@ interface UriToLinesMap { } export default class RerunFormatter extends Formatter { - private readonly separator: string = 'Prints failing files with line numbers.' + private readonly separator: string + public static readonly documentation: string = + 'Prints failing files with line numbers.' constructor(options: IFormatterOptions) { super(options) From 1d7b3a50b3536ad85ac28ae35963864b78fc8737 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Sep 2021 17:01:19 +0300 Subject: [PATCH 13/24] feature/list-formatters-in-help-command fixing return type of getConstructorByType method and running linter --- src/formatter/builder.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index e0d852253..4ef9602c9 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -63,7 +63,10 @@ const FormatterBuilder = { }) }, - async getConstructorByType(type: string, cwd: string): typeof Formatter { + async getConstructorByType( + type: string, + cwd: string + ): Promise { const formatters: Record = { json: JsonFormatter, message: MessageFormatter, @@ -77,9 +80,9 @@ const FormatterBuilder = { 'usage-json': UsageJsonFormatter, } - return await formatters[type] + return (await formatters[type]) ? formatters[type] - : FormatterBuilder.loadCustomFormatter(type, cwd) + : await FormatterBuilder.loadCustomFormatter(type, cwd) }, async getStepDefinitionSnippetBuilder({ From 1fd14a19f6dc358d77b66c380433c5ce7c1ebe41 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Oct 2021 09:39:29 +0300 Subject: [PATCH 14/24] feature/list-formatters-in-help-command removing unnecessary await --- src/formatter/builder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 4ef9602c9..556a0fc19 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -80,7 +80,7 @@ const FormatterBuilder = { 'usage-json': UsageJsonFormatter, } - return (await formatters[type]) + return formatters[type] ? formatters[type] : await FormatterBuilder.loadCustomFormatter(type, cwd) }, From 2d2c89cff8fc8ff3c1d03de9a578d9cd7aa8a304 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 1 Oct 2021 11:59:51 +0300 Subject: [PATCH 15/24] feature/list-formatters-in-help-command creating Formatters class to hold different formatters and extracting them from the builder class --- src/formatter/builder.ts | 25 +++--------------------- src/formatter/helpers/formatters.ts | 30 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 22 deletions(-) create mode 100644 src/formatter/helpers/formatters.ts diff --git a/src/formatter/builder.ts b/src/formatter/builder.ts index 556a0fc19..daf9a15e8 100644 --- a/src/formatter/builder.ts +++ b/src/formatter/builder.ts @@ -1,16 +1,7 @@ import getColorFns from './get_color_fns' import JavascriptSnippetSyntax from './step_definition_snippet_builder/javascript_snippet_syntax' -import JsonFormatter from './json_formatter' -import MessageFormatter from './message_formatter' import path from 'path' -import ProgressBarFormatter from './progress_bar_formatter' -import ProgressFormatter from './progress_formatter' -import RerunFormatter from './rerun_formatter' -import SnippetsFormatter from './snippets_formatter' import StepDefinitionSnippetBuilder from './step_definition_snippet_builder' -import SummaryFormatter from './summary_formatter' -import UsageFormatter from './usage_formatter' -import UsageJsonFormatter from './usage_json_formatter' import { ISupportCodeLibrary } from '../support_code_library_builder/types' import Formatter, { IFormatterCleanupFn, IFormatterLogFn } from '.' import { doesHaveValue, doesNotHaveValue } from '../value_checker' @@ -19,8 +10,8 @@ import EventDataCollector from './helpers/event_data_collector' import { Writable as WritableStream } from 'stream' import { IParsedArgvFormatOptions } from '../cli/argv_parser' import { SnippetInterface } from './step_definition_snippet_builder/snippet_syntax' -import HtmlFormatter from './html_formatter' import { pathToFileURL } from 'url' +import Formatters from './helpers/formatters' // eslint-disable-next-line @typescript-eslint/no-var-requires const { importer } = require('../importer') @@ -67,18 +58,8 @@ const FormatterBuilder = { type: string, cwd: string ): Promise { - const formatters: Record = { - json: JsonFormatter, - message: MessageFormatter, - html: HtmlFormatter, - progress: ProgressFormatter, - 'progress-bar': ProgressBarFormatter, - rerun: RerunFormatter, - snippets: SnippetsFormatter, - summary: SummaryFormatter, - usage: UsageFormatter, - 'usage-json': UsageJsonFormatter, - } + const formatters: Record = + Formatters.getFormatters() return formatters[type] ? formatters[type] diff --git a/src/formatter/helpers/formatters.ts b/src/formatter/helpers/formatters.ts new file mode 100644 index 000000000..8d022f7c3 --- /dev/null +++ b/src/formatter/helpers/formatters.ts @@ -0,0 +1,30 @@ +import Formatter from '../.' +import JsonFormatter from '../json_formatter' +import MessageFormatter from '../message_formatter' +import ProgressBarFormatter from '../progress_bar_formatter' +import ProgressFormatter from '../progress_formatter' +import RerunFormatter from '../rerun_formatter' +import SnippetsFormatter from '../snippets_formatter' +import SummaryFormatter from '../summary_formatter' +import UsageFormatter from '../usage_formatter' +import UsageJsonFormatter from '../usage_json_formatter' +import HtmlFormatter from '../html_formatter' + +const Formatters = { + getFormatters(): Record { + return { + json: JsonFormatter, + message: MessageFormatter, + html: HtmlFormatter, + progress: ProgressFormatter, + 'progress-bar': ProgressBarFormatter, + rerun: RerunFormatter, + snippets: SnippetsFormatter, + summary: SummaryFormatter, + usage: UsageFormatter, + 'usage-json': UsageJsonFormatter, + } + }, +} + +export default Formatters From c37537cc672095a457ba551afd7697e34f46c9f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Oct 2021 23:24:18 +0300 Subject: [PATCH 16/24] feature/list-formatters-in-help-command adding documentation field to progress-bar/snippets/usage-json formatters --- src/formatter/progress_bar_formatter.ts | 1 + src/formatter/snippets_formatter.ts | 1 + src/formatter/usage_json_formatter.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/formatter/progress_bar_formatter.ts b/src/formatter/progress_bar_formatter.ts index ed6fc812d..7fdfbe4d4 100644 --- a/src/formatter/progress_bar_formatter.ts +++ b/src/formatter/progress_bar_formatter.ts @@ -13,6 +13,7 @@ export default class ProgressBarFormatter extends Formatter { private testRunStarted: messages.TestRunStarted private issueCount: number public progressBar: ProgressBar + public static readonly documentation: string = '' constructor(options: IFormatterOptions) { super(options) diff --git a/src/formatter/snippets_formatter.ts b/src/formatter/snippets_formatter.ts index 1dd2720d4..3ff8c0ea0 100644 --- a/src/formatter/snippets_formatter.ts +++ b/src/formatter/snippets_formatter.ts @@ -5,6 +5,7 @@ import * as messages from '@cucumber/messages' import IEnvelope = messages.Envelope export default class SnippetsFormatter extends Formatter { + public static readonly documentation: string = '' constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { diff --git a/src/formatter/usage_json_formatter.ts b/src/formatter/usage_json_formatter.ts index 863b8768c..9004650f9 100644 --- a/src/formatter/usage_json_formatter.ts +++ b/src/formatter/usage_json_formatter.ts @@ -5,6 +5,7 @@ import * as messages from '@cucumber/messages' import IEnvelope = messages.Envelope export default class UsageJsonFormatter extends Formatter { + public static readonly documentation: string = '' constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { From c60083718db877562925e05e9c7ea5c246bb83ac Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Oct 2021 23:25:16 +0300 Subject: [PATCH 17/24] feature/list-formatters-in-help-command added method in formatters class to help build the documentation string --- src/formatter/helpers/formatters.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/formatter/helpers/formatters.ts b/src/formatter/helpers/formatters.ts index 8d022f7c3..898a36852 100644 --- a/src/formatter/helpers/formatters.ts +++ b/src/formatter/helpers/formatters.ts @@ -25,6 +25,28 @@ const Formatters = { 'usage-json': UsageJsonFormatter, } }, + buildFormattersDocumentationString(): string { + let concatanatedFormattersDocumentation: string = '' + const formattersDocumentation: Record = { + json: JsonFormatter.documentation, + message: MessageFormatter.documentation, + html: HtmlFormatter.documentation, + progress: ProgressFormatter.documentation, + 'progress-bar': ProgressBarFormatter.documentation, + rerun: RerunFormatter.documentation, + snippets: SnippetsFormatter.documentation, + summary: SummaryFormatter.documentation, + usage: UsageFormatter.documentation, + 'usage-json': UsageJsonFormatter.documentation, + } + + for (const formatter in formattersDocumentation) { + concatanatedFormattersDocumentation += + formatter + ' : ' + formattersDocumentation[formatter] + '\n' + } + + return concatanatedFormattersDocumentation + }, } export default Formatters From f8985749d6db169b2f40cec75959fde91b000af4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Oct 2021 23:25:46 +0300 Subject: [PATCH 18/24] feature/list-formatters-in-help-command used recently added method to list all available formatters --- src/cli/argv_parser.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cli/argv_parser.ts b/src/cli/argv_parser.ts index 0694a5f91..237d77af5 100644 --- a/src/cli/argv_parser.ts +++ b/src/cli/argv_parser.ts @@ -2,6 +2,7 @@ import { Command } from 'commander' import path from 'path' import { dialects } from '@cucumber/gherkin' import { SnippetInterface } from '../formatter/step_definition_snippet_builder/snippet_syntax' +import Formatters from '../formatter/helpers/formatters' // Using require instead of import so compiled typescript will have the desired folder structure const { version } = require('../../package.json') // eslint-disable-line @typescript-eslint/no-var-requires @@ -120,7 +121,8 @@ const ArgvParser = { .option('--fail-fast', 'abort the run on first failure', false) .option( '-f, --format ', - 'specify the output format, optionally supply PATH to redirect formatter output (repeatable)', + 'specify the output format, optionally supply PATH to redirect formatter output (repeatable). Available formats: ' + + Formatters.buildFormattersDocumentationString(), ArgvParser.collect, [] ) From c42c2d26a862b265d608679cf7dfa60c6c17d532 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2021 12:26:27 +0300 Subject: [PATCH 19/24] feature/list-formatters-in-help-command adding documentation to snippets/progress-bar/usage-json formatters --- src/formatter/progress_bar_formatter.ts | 3 ++- src/formatter/snippets_formatter.ts | 4 +++- src/formatter/usage_json_formatter.ts | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/formatter/progress_bar_formatter.ts b/src/formatter/progress_bar_formatter.ts index 7fdfbe4d4..660b3994f 100644 --- a/src/formatter/progress_bar_formatter.ts +++ b/src/formatter/progress_bar_formatter.ts @@ -13,7 +13,8 @@ export default class ProgressBarFormatter extends Formatter { private testRunStarted: messages.TestRunStarted private issueCount: number public progressBar: ProgressBar - public static readonly documentation: string = '' + public static readonly documentation: string = + 'Similar to the Progress Formatter, but provides a real-time updating progress bar based on the total number of steps to be executed in the test run' constructor(options: IFormatterOptions) { super(options) diff --git a/src/formatter/snippets_formatter.ts b/src/formatter/snippets_formatter.ts index 3ff8c0ea0..bbc936d37 100644 --- a/src/formatter/snippets_formatter.ts +++ b/src/formatter/snippets_formatter.ts @@ -5,7 +5,9 @@ import * as messages from '@cucumber/messages' import IEnvelope = messages.Envelope export default class SnippetsFormatter extends Formatter { - public static readonly documentation: string = '' + public static readonly documentation: string = + "The Snippets Formatter doesn't output anything regarding the test run; it just prints snippets to implement any undefined steps" + constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { diff --git a/src/formatter/usage_json_formatter.ts b/src/formatter/usage_json_formatter.ts index 9004650f9..c2b522429 100644 --- a/src/formatter/usage_json_formatter.ts +++ b/src/formatter/usage_json_formatter.ts @@ -5,7 +5,9 @@ import * as messages from '@cucumber/messages' import IEnvelope = messages.Envelope export default class UsageJsonFormatter extends Formatter { - public static readonly documentation: string = '' + public static readonly documentation: string = + 'Does what the Usage Formatter does, but outputs JSON, which can be output to a file and then consumed by other tools.' + constructor(options: IFormatterOptions) { super(options) options.eventBroadcaster.on('envelope', (envelope: IEnvelope) => { From 2bdb91a960558b67e2dd4c17f340cbc64fc41017 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2021 12:28:30 +0300 Subject: [PATCH 20/24] feature/list-formatters-in-help-command adding new line to format option so that formatters will appear on new line --- src/cli/argv_parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/argv_parser.ts b/src/cli/argv_parser.ts index 237d77af5..0519a7a1d 100644 --- a/src/cli/argv_parser.ts +++ b/src/cli/argv_parser.ts @@ -121,7 +121,7 @@ const ArgvParser = { .option('--fail-fast', 'abort the run on first failure', false) .option( '-f, --format ', - 'specify the output format, optionally supply PATH to redirect formatter output (repeatable). Available formats: ' + + 'specify the output format, optionally supply PATH to redirect formatter output (repeatable). Available formats:\n' + Formatters.buildFormattersDocumentationString(), ArgvParser.collect, [] From b422359174df3c9c101f7052bc2c05529c99de94 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2021 18:17:37 +0300 Subject: [PATCH 21/24] feature/list/formatters-in-help-command converting documentation field inside formatter to be public and static. Refactoring buildFormatterDocumentationString --- src/formatter/helpers/formatters.ts | 18 +++--------------- src/formatter/index.ts | 2 +- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/formatter/helpers/formatters.ts b/src/formatter/helpers/formatters.ts index 898a36852..d7781fccb 100644 --- a/src/formatter/helpers/formatters.ts +++ b/src/formatter/helpers/formatters.ts @@ -27,22 +27,10 @@ const Formatters = { }, buildFormattersDocumentationString(): string { let concatanatedFormattersDocumentation: string = '' - const formattersDocumentation: Record = { - json: JsonFormatter.documentation, - message: MessageFormatter.documentation, - html: HtmlFormatter.documentation, - progress: ProgressFormatter.documentation, - 'progress-bar': ProgressBarFormatter.documentation, - rerun: RerunFormatter.documentation, - snippets: SnippetsFormatter.documentation, - summary: SummaryFormatter.documentation, - usage: UsageFormatter.documentation, - 'usage-json': UsageJsonFormatter.documentation, - } - - for (const formatter in formattersDocumentation) { + const formatters = this.getFormatters() + for (const formatterName in formatters) { concatanatedFormattersDocumentation += - formatter + ' : ' + formattersDocumentation[formatter] + '\n' + formatterName + ' : ' + formatters[formatterName].documentation + '\n' } return concatanatedFormattersDocumentation diff --git a/src/formatter/index.ts b/src/formatter/index.ts index 5156c7344..16ff0ad28 100644 --- a/src/formatter/index.ts +++ b/src/formatter/index.ts @@ -39,7 +39,7 @@ export default class Formatter { protected stream: WritableStream protected supportCodeLibrary: ISupportCodeLibrary private readonly cleanup: IFormatterCleanupFn - protected readonly documentation: string + static readonly documentation: string constructor(options: IFormatterOptions) { this.colorFns = options.colorFns From 93ae5e585684388bc869c37010cdf8ca870c7bbd Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Oct 2021 21:09:18 +0300 Subject: [PATCH 22/24] feature/list/formatters-in-help-command indenting formatters and removing extra space --- src/formatter/helpers/formatters.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/formatter/helpers/formatters.ts b/src/formatter/helpers/formatters.ts index d7781fccb..003837b37 100644 --- a/src/formatter/helpers/formatters.ts +++ b/src/formatter/helpers/formatters.ts @@ -30,7 +30,11 @@ const Formatters = { const formatters = this.getFormatters() for (const formatterName in formatters) { concatanatedFormattersDocumentation += - formatterName + ' : ' + formatters[formatterName].documentation + '\n' + ' ' + + formatterName + + ': ' + + formatters[formatterName].documentation + + '\n' } return concatanatedFormattersDocumentation From 3e9a62bc4d7ade20e08a6c25a00327f9251b05ce Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Oct 2021 10:37:49 +0300 Subject: [PATCH 23/24] feature/list-formatters-in-help-command refactoring building the documentation string --- src/formatter/helpers/formatters.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/formatter/helpers/formatters.ts b/src/formatter/helpers/formatters.ts index 003837b37..d5a2698f5 100644 --- a/src/formatter/helpers/formatters.ts +++ b/src/formatter/helpers/formatters.ts @@ -29,12 +29,7 @@ const Formatters = { let concatanatedFormattersDocumentation: string = '' const formatters = this.getFormatters() for (const formatterName in formatters) { - concatanatedFormattersDocumentation += - ' ' + - formatterName + - ': ' + - formatters[formatterName].documentation + - '\n' + concatanatedFormattersDocumentation += ` ${formatterName}: ${formatters[formatterName].documentation}\n` } return concatanatedFormattersDocumentation From 58dc26f014a975361f72ab102c2162a5315f2350 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Oct 2021 20:19:06 +0300 Subject: [PATCH 24/24] feature/list-formatters-in-help-command adding feature to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ede556f0d..96082618a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ### Removed ### Fixed +* When running the help command, it now shows all available formatters under the --format option. + [#1798](https://github.com/cucumber/cucumber-js/pull/1798) ## [7.3.1] (2021-07-20)