Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List formatters in help command #1798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9daa87e
feature/list-formatters-in-help-command adding documentation field to…
TomerPacific Sep 16, 2021
96e30e5
feature/list-formatters-in-help-command refactoring getConstructorByT…
TomerPacific Sep 16, 2021
a76f231
feature/list-formatters-in-help-command improving return statement to…
TomerPacific Sep 16, 2021
ced6ecc
feature/list-formatters-in-help-command after running lint fix
TomerPacific Sep 17, 2021
4c89fea
feature/list-formatters-in-help-command fixing ternary so logic does …
TomerPacific Sep 17, 2021
7e4a398
feature/list-formatters-in-help-command creating class that will hold…
TomerPacific Sep 25, 2021
0b9e4cd
feature/list-formatters-in-help-command adding logic to extract the c…
TomerPacific Sep 25, 2021
ba24272
feature/list-formatters-in-help-command reverting changes made by add…
TomerPacific Sep 27, 2021
e322a20
feature/list-formatters-in-help-command adding documentation field to…
TomerPacific Sep 27, 2021
36f5856
feature/list-formatters-in-help-command adding documentation member t…
TomerPacific Sep 27, 2021
22d8d6d
feature/list-formatters-in-help-command removing formatterDocumentati…
TomerPacific Sep 27, 2021
fb84765
feature/list-formatters-in-help-command adding documentation field to…
TomerPacific Sep 30, 2021
1a6b554
Merge branch 'main' into feature/list-formatters-in-help-command-1700
TomerPacific Sep 30, 2021
1d7b3a5
feature/list-formatters-in-help-command fixing return type of getCons…
TomerPacific Sep 30, 2021
1fd14a1
feature/list-formatters-in-help-command removing unnecessary await
TomerPacific Oct 1, 2021
441fd56
Merge branch 'main' into feature/list-formatters-in-help-command-1700
TomerPacific Oct 1, 2021
2d2c89c
feature/list-formatters-in-help-command creating Formatters class to …
TomerPacific Oct 1, 2021
e3baeb7
Merge branch 'main' into feature/list-formatters-in-help-command-1700
TomerPacific Oct 1, 2021
fac6492
Merge branch 'main' into feature/list-formatters-in-help-command-1700
TomerPacific Oct 2, 2021
c37537c
feature/list-formatters-in-help-command adding documentation field to…
TomerPacific Oct 2, 2021
d612918
Merge branch 'feature/list-formatters-in-help-command-1700' of https:…
TomerPacific Oct 2, 2021
c600837
feature/list-formatters-in-help-command added method in formatters cl…
TomerPacific Oct 2, 2021
f898574
feature/list-formatters-in-help-command used recently added method to…
TomerPacific Oct 2, 2021
1acabd4
Merge branch 'main' into feature/list-formatters-in-help-command-1700
TomerPacific Oct 5, 2021
c42c2d2
feature/list-formatters-in-help-command adding documentation to snipp…
TomerPacific Oct 5, 2021
2bdb91a
feature/list-formatters-in-help-command adding new line to format opt…
TomerPacific Oct 5, 2021
b422359
feature/list/formatters-in-help-command converting documentation fiel…
TomerPacific Oct 5, 2021
93ae5e5
feature/list/formatters-in-help-command indenting formatters and remo…
TomerPacific Oct 5, 2021
3e9a62b
feature/list-formatters-in-help-command refactoring building the docu…
TomerPacific Oct 6, 2021
58dc26f
feature/list-formatters-in-help-command adding feature to changelog
TomerPacific Oct 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion src/cli/argv_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,7 +121,8 @@ const ArgvParser = {
.option('--fail-fast', 'abort the run on first failure', false)
.option(
'-f, --format <TYPE[:PATH]>',
'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:\n' +
Formatters.buildFormattersDocumentationString(),
ArgvParser.collect,
[]
)
Expand Down
41 changes: 7 additions & 34 deletions src/formatter/builder.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')

Expand Down Expand Up @@ -67,30 +58,12 @@ const FormatterBuilder = {
type: string,
cwd: string
): Promise<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 await FormatterBuilder.loadCustomFormatter(type, cwd)
}
const formatters: Record<string, typeof Formatter> =
Formatters.getFormatters()

return formatters[type]
? formatters[type]
: await FormatterBuilder.loadCustomFormatter(type, cwd)
},

async getStepDefinitionSnippetBuilder({
Expand Down
39 changes: 39 additions & 0 deletions src/formatter/helpers/formatters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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<string, typeof Formatter> {
return {
json: JsonFormatter,
message: MessageFormatter,
html: HtmlFormatter,
progress: ProgressFormatter,
'progress-bar': ProgressBarFormatter,
rerun: RerunFormatter,
snippets: SnippetsFormatter,
summary: SummaryFormatter,
usage: UsageFormatter,
'usage-json': UsageJsonFormatter,
}
},
buildFormattersDocumentationString(): string {
let concatanatedFormattersDocumentation: string = ''
const formatters = this.getFormatters()
for (const formatterName in formatters) {
concatanatedFormattersDocumentation += ` ${formatterName}: ${formatters[formatterName].documentation}\n`
}

return concatanatedFormattersDocumentation
},
}

export default Formatters
1 change: 1 addition & 0 deletions src/formatter/html_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { promisify } from 'util'

export default class HtmlFormatter extends Formatter {
private readonly _finished: Promise<void>
public static readonly documentation: string = 'Outputs HTML report'

constructor(options: IFormatterOptions) {
super(options)
Expand Down
1 change: 1 addition & 0 deletions src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class Formatter {
protected stream: WritableStream
protected supportCodeLibrary: ISupportCodeLibrary
private readonly cleanup: IFormatterCleanupFn
static readonly documentation: string

constructor(options: IFormatterOptions) {
this.colorFns = options.colorFns
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/json_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/formatter/message_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 2 additions & 0 deletions src/formatter/progress_bar_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export default class ProgressBarFormatter extends Formatter {
private testRunStarted: messages.TestRunStarted
private issueCount: number
public progressBar: ProgressBar
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)
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/progress_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const STATUS_CHARACTER_MAPPING: Map<messages.TestStepResultStatus, string> =
])

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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/formatter/rerun_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface UriToLinesMap {

export default class RerunFormatter extends Formatter {
private readonly separator: string
public static readonly documentation: string =
'Prints failing files with line numbers.'

constructor(options: IFormatterOptions) {
super(options)
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/snippets_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import * as messages from '@cucumber/messages'
import IEnvelope = messages.Envelope

export default class SnippetsFormatter extends Formatter {
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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/summary_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/usage_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/formatter/usage_json_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import * as messages from '@cucumber/messages'
import IEnvelope = messages.Envelope

export default class UsageJsonFormatter extends Formatter {
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) => {
Expand Down