Skip to content

Commit

Permalink
cli: don't split formatter output on Windows drive letters (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrinholst authored and charlierudolph committed Oct 18, 2017
1 parent 880c82d commit 7d8784f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/cli/configuration_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ export default class ConfigurationBuilder {
getFormats() {
const mapping = { '': 'progress' }
this.options.format.forEach(function(format) {
const parts = format.split(':')
const type = parts[0]
const outputTo = parts.slice(1).join(':')
let type = format
let outputTo = ''
const parts = format.split(/([^A-Z]):([^\\])/)

if (parts.length > 1) {
type = parts.slice(0, 2).join('')
outputTo = parts.slice(2).join('')
}

mapping[outputTo] = type
})
return _.map(mapping, function(type, outputTo) {
Expand Down
49 changes: 49 additions & 0 deletions src/cli/configuration_builder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,53 @@ describe('Configuration', function() {
expect(supportCodePaths).to.eql([this.supportCodePath])
})
})

describe('formatters', function() {
it('adds a default', async function() {
const formats = await getFormats(this.configurationOptions)
expect(formats).to.eql([{ outputTo: '', type: 'progress' }])
})

it('splits relative unix paths', async function() {
this.argv.push('-f', '../custom/formatter:../formatter/output.txt')
const formats = await getFormats(this.configurationOptions)

expect(formats).to.eql([
{ outputTo: '', type: 'progress' },
{ outputTo: '../formatter/output.txt', type: '../custom/formatter' }
])
})

it('splits absolute unix paths', async function() {
this.argv.push('-f', '/custom/formatter:/formatter/output.txt')
const formats = await getFormats(this.configurationOptions)

expect(formats).to.eql([
{ outputTo: '', type: 'progress' },
{ outputTo: '/formatter/output.txt', type: '/custom/formatter' }
])
})

it('splits absolute windows paths', async function() {
this.argv.push('-f', 'C:\\custom\\formatter:D:\\formatter\\output.txt')
const formats = await getFormats(this.configurationOptions)

expect(formats).to.eql([
{ outputTo: '', type: 'progress' },
{ outputTo: 'D:\\formatter\\output.txt', type: 'C:\\custom\\formatter' }
])
})

it('does not split absolute windows paths without an output', async function() {
this.argv.push('-f', 'C:\\custom\\formatter')
const formats = await getFormats(this.configurationOptions)

expect(formats).to.eql([{ outputTo: '', type: 'C:\\custom\\formatter' }])
})

async function getFormats(options) {
const result = await ConfigurationBuilder.build(options)
return result.formats
}
})
})

0 comments on commit 7d8784f

Please sign in to comment.