Skip to content

Commit

Permalink
update default formatters' colors enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
charlierudolph committed Oct 4, 2018
1 parent 0c76b0c commit 0415dde
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO

#### Bug Fixes

* Update default of formatters' colors enabled to be true only if the stream is a TTY
* Allow writing to stdout when running in parallel

### [5.0.1](https://github.com/cucumber/cucumber-js/compare/v5.0.0...v5.0.1) (2018-04-09)
Expand Down
5 changes: 1 addition & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ cache:
environment:
matrix:
- nodejs_version: '10'
test_script: 'test'
- nodejs_version: '8'
test_script: 'test'
- nodejs_version: '6'
test_script: 'test'

install:
- ps: Install-Product node $env:nodejs_version
Expand All @@ -19,4 +16,4 @@ install:
test_script:
- node --version
- yarn --version
- yarn run %test_script%
- yarn run test
4 changes: 3 additions & 1 deletion cucumber.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var common = [
'--require-module babel-register',
`--format ${process.env.CI ? 'progress' : 'progress-bar'}`,
`--format ${
process.env.CI || !process.stdout.isTTY ? 'progress' : 'progress-bar'
}`,
'--format rerun:@rerun.txt',
'--format usage:usage.txt',
].join(' ')
Expand Down
5 changes: 1 addition & 4 deletions src/cli/configuration_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ export default class ConfigurationBuilder {
}

getFormatOptions() {
const formatOptions = _.clone(this.options.formatOptions)
formatOptions.cwd = this.cwd
_.defaults(formatOptions, { colorsEnabled: true })
return formatOptions
return _.assign({}, this.options.formatOptions, { cwd: this.cwd })
}

getFormats() {
Expand Down
16 changes: 12 additions & 4 deletions src/cli/configuration_builder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ describe('Configuration', () => {
expect(this.result).to.eql({
featureDefaultLanguage: '',
featurePaths: [],
formatOptions: {
colorsEnabled: true,
cwd: this.tmpDir,
},
formatOptions: { cwd: this.tmpDir },
formats: [{ outputTo: '', type: 'progress' }],
listI18nKeywordsFor: '',
listI18nLanguages: false,
Expand Down Expand Up @@ -156,4 +153,15 @@ describe('Configuration', () => {
return result.formats
}
})

describe('formatOptions', () => {
it('returns the format options passed in with cwd added', async function() {
this.argv.push('--format-options', '{"snippetSyntax": "promise"}')
const result = await ConfigurationBuilder.build(this.configurationOptions)
expect(result.formatOptions).to.eql({
snippetSyntax: 'promise',
cwd: this.tmpDir,
})
})
})
})
10 changes: 10 additions & 0 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export default class Cli {
supportCodeLibrary,
...formatOptions,
}
if (!formatOptions.hasOwnProperty('colorsEnabled')) {
typeOptions.colorsEnabled = !!stream.isTTY
}
if (type === 'progress-bar' && !stream.isTTY) {
console.warn(
`Cannot use 'progress-bar' formatter for output to '${outputTo ||
'stdout'}' as not a TTY. Switching to 'progress' formatter.`
)
type = 'progress'
}
return FormatterBuilder.build(type, typeOptions)
})
return function() {
Expand Down
48 changes: 36 additions & 12 deletions src/formatter/get_color_fns.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
import _ from 'lodash'
import colors from 'colors/safe'
import Status from '../status'

export default function getColorFns(enabled) {
colors.enabled = enabled
colors.setTheme({
[Status.AMBIGUOUS]: 'red',
[Status.FAILED]: 'red',
[Status.PASSED]: 'green',
[Status.PENDING]: 'yellow',
[Status.SKIPPED]: 'cyan',
[Status.UNDEFINED]: 'yellow',
location: 'grey',
tag: 'cyan',
})
return colors
if (enabled) {
return {
[Status.AMBIGUOUS]: ::colors.red,
[Status.FAILED]: ::colors.red,
[Status.PASSED]: ::colors.green,
[Status.PENDING]: ::colors.yellow,
[Status.SKIPPED]: ::colors.cyan,
[Status.UNDEFINED]: ::colors.yellow,
location: ::colors.gray,
tag: ::colors.cyan,

// For assertion-error-formatter
diffAdded: ::colors.green,
diffRemoved: ::colors.red,
errorMessage: ::colors.red,
errorStack: ::colors.gray,
}
} else {
return {
[Status.AMBIGUOUS]: _.identity,
[Status.FAILED]: _.identity,
[Status.PASSED]: _.identity,
[Status.PENDING]: _.identity,
[Status.SKIPPED]: _.identity,
[Status.UNDEFINED]: _.identity,
location: _.identity,
tag: _.identity,

// For assertion-error-formatter
diffAdded: _.identity,
diffRemoved: _.identity,
errorMessage: _.identity,
errorStack: _.identity,
}
}
}
9 changes: 1 addition & 8 deletions src/formatter/helpers/error_helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { format } from 'assertion-error-formatter'

export function formatError(error, colorFns) {
return format(error, {
colorFns: {
diffAdded: colorFns.red,
diffRemoved: colorFns.green,
errorMessage: colorFns.red,
errorStack: colorFns.gray,
},
})
return format(error, { colorFns })
}

0 comments on commit 0415dde

Please sign in to comment.