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

cli: use kebab-case for --retry-tag-filter arg #1293

Merged
merged 14 commits into from
Mar 17, 2020
Prev Previous commit
Next Next commit
issue warning when using camel case for --retry-tag-filter; make warn…
…ings testable
davidjgoss committed Feb 22, 2020
commit 4ab6d6f591c46c8725e966c69abb3b7f109b59d5
20 changes: 20 additions & 0 deletions features/retry.feature
Original file line number Diff line number Diff line change
@@ -12,6 +12,26 @@ Feature: Retry flaky tests
"""
And it fails

Scenario: running Cucumber JS with --retryTagFilter in camel case will result in a warning
Given a file named "features/a.feature" with:
"""
Feature:
Scenario:
Given a step
"""
Given a file named "features/step_definitions/cucumber_steps.js" with:
"""
const {Given} = require('cucumber')

Given(/^a step$/, function() {})
"""
When I run cucumber-js with `--retry 1 --retryTagFilter @flaky`
Then it issues the warning:
"""
the argument --retryTagFilter is deprecated and will be removed in a future release; please use --retry-tag-filter
"""
But it passes

Scenario: running Cucumber JS with negative --retry will fail
When I run cucumber-js with `--retry -1`
Then the error output contains the text:
5 changes: 5 additions & 0 deletions features/step_definitions/cli_steps.ts
Original file line number Diff line number Diff line change
@@ -57,6 +57,11 @@ Then(/^it fails$/, function(this: World) {
this.verifiedLastRunError = true
})

Then(/^it issues the warning:$/, function(this: World, text: string) {
const warnings: string[] = this.lastRun.warnings
expect(warnings).to.include(text)
})

Then(/^it outputs the text:$/, function(this: World, text) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
7 changes: 7 additions & 0 deletions features/support/world.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ interface ILastRun {
errorOutput: string
envelopes: messages.IEnvelope[]
output: string
warnings: string[]
}

interface IRunResult {
@@ -49,6 +50,10 @@ export class World {
return arg
})
const cwd = this.tmpDir
const warnings: string[] = []
const warn = (message: string): void => {
warnings.push(message)
}

let result: IRunResult

@@ -64,6 +69,7 @@ export class World {
argv: args,
cwd,
stdout,
warn,
})
let error: any, stderr: string
try {
@@ -105,6 +111,7 @@ export class World {
errorOutput: result.stderr,
envelopes,
output: colors.strip(result.stdout),
warnings,
}
this.verifiedLastRunError = false
expect(this.lastRun.output).to.not.include('Unhandled rejection')
2 changes: 1 addition & 1 deletion src/cli/argv_parser.ts
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ const ArgvParser = {
0
)
.option(
'--retry-tag-filter <EXPRESSION>',
'--retryTagFilter, --retry-tag-filter <EXPRESSION>',
`only retries the features or scenarios with tags matching the expression (repeatable).
This option requires '--retry' to be specified.`,
ArgvParser.mergeTags,
25 changes: 21 additions & 4 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -42,16 +42,33 @@ export default class Cli {
private readonly argv: string[]
private readonly cwd: string
private readonly stdout: IFormatterStream
private readonly warn: (message: string) => void

constructor({ argv, cwd, stdout }) {
constructor({ argv, cwd, stdout, warn = console.warn }) {
this.argv = argv
this.cwd = cwd
this.stdout = stdout
this.warn = warn
}

async getConfiguration(): Promise<IConfiguration> {
const fullArgv = await getExpandedArgv({ argv: this.argv, cwd: this.cwd })
return ConfigurationBuilder.build({ argv: fullArgv, cwd: this.cwd })
const fullArgv = await getExpandedArgv({
argv: this.argv,
cwd: this.cwd,
})
this.lintArgv(fullArgv)
return ConfigurationBuilder.build({
argv: fullArgv,
cwd: this.cwd,
})
}

private lintArgv(fullArgv: string[]): void {
if (fullArgv.includes('--retryTagFilter')) {
this.warn(
'the argument --retryTagFilter is deprecated and will be removed in a future release; please use --retry-tag-filter'
)
}
}

async initializeFormatters({
@@ -83,7 +100,7 @@ export default class Cli {
}
if (type === 'progress-bar' && !(stream as TtyWriteStream).isTTY) {
const outputToName = outputTo === '' ? 'stdout' : outputTo
console.warn(
this.warn(
`Cannot use 'progress-bar' formatter for output to '${outputToName}' as not a TTY. Switching to 'progress' formatter.`
)
type = 'progress'