Skip to content

Commit

Permalink
fix: Concat hostname option from CLI & config file (#348)
Browse files Browse the repository at this point in the history
* fix: Concat hostname option from CLI & config file

This is so you can pass a `-h` flag, and that'll get applied _along_ with the
hostnames specified in the `.percy.yml`.

* Add test for applying CLI flags without a config file
  • Loading branch information
Robdel12 committed Sep 19, 2019
1 parent 3058905 commit 7090bfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/services/configuration-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default class ConfigurationService {
}

if (flags['allowed-hostname']) {
this.configuration.agent['asset-discovery']['allowed-hostnames'] = flags['allowed-hostname']
this.configuration.agent['asset-discovery']['allowed-hostnames'] =
flags['allowed-hostname'].concat(this.configuration.agent['asset-discovery']['allowed-hostnames'])
}

if (flags['network-idle-timeout']) {
Expand Down
24 changes: 20 additions & 4 deletions test/services/configuration-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ConfigurationService', () => {
})

describe('#applyFlags', () => {
it('applies flags', () => {
it('applies flags with a .percy.yml', () => {
const flags = {
'network-idle-timeout': 51,
'base-url': '/flag/',
Expand All @@ -52,9 +52,25 @@ describe('ConfigurationService', () => {
expect(subject['static-snapshots']['snapshot-files']).to.eql('flags/*.html')
expect(subject['static-snapshots']['ignore-files']).to.eql('ignore-flags/*.html')
expect(subject.agent['asset-discovery']['network-idle-timeout']).to.eql(51)
expect(subject.agent['asset-discovery']['allowed-hostnames']).to.eql(
['additional-hostname.local'],
)
expect(subject.agent['asset-discovery']['allowed-hostnames'][1]).to.eql('localassets.dev')
expect(subject.agent['asset-discovery']['allowed-hostnames'][0]).to.eql('additional-hostname.local')
})

it('applies flags without a .percy.yml', () => {
const flags = {
'network-idle-timeout': 51,
'base-url': '/flag/',
'snapshot-files': 'flags/*.html',
'ignore-files': 'ignore-flags/*.html',
'allowed-hostname': ['additional-hostname.local'],
}
const subject = new ConfigurationService('test/support/doesnt-exist/.percy.yml').applyFlags(flags)

expect(subject['static-snapshots']['base-url']).to.eql('/flag/')
expect(subject['static-snapshots']['snapshot-files']).to.eql('flags/*.html')
expect(subject['static-snapshots']['ignore-files']).to.eql('ignore-flags/*.html')
expect(subject.agent['asset-discovery']['network-idle-timeout']).to.eql(51)
expect(subject.agent['asset-discovery']['allowed-hostnames'][0]).to.eql('additional-hostname.local')
})
})

Expand Down

0 comments on commit 7090bfd

Please sign in to comment.