-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 Default config overrides (#394)
* ✅ Add configuration utiliy tests * fix: 🐛 Remove requirement for static snapshot and upload arg This arg is allowed to be specified via a config file. It seems it was always meant to be this way as there are defaults specified for these args. * fix: 🐛 Remove oclif defaults Percy defaults are handled seperately from oclif due to allowing specifying some flags and args within a configuration file.
- Loading branch information
Wil Wilsman
authored
Oct 7, 2019
1 parent
1bb72bd
commit ca4ecd1
Showing
8 changed files
with
163 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { expect } from 'chai' | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import { DEFAULT_CONFIGURATION } from '../../src/configuration/configuration' | ||
import config, { explorer } from '../../src/utils/configuration' | ||
|
||
function dedent(str: string) { | ||
const indent = str.match(/ +/g)![0].length | ||
return str.replace(new RegExp(`\n {${indent}}`, 'g'), '\n').trim() | ||
} | ||
|
||
describe('configuration', () => { | ||
let configfiles: string[] | ||
|
||
// helper to create a config files and cleanup on `afterEach` | ||
function mkconfig(filename: string, contents: string) { | ||
const filepath = path.join(process.cwd(), filename) | ||
fs.writeFileSync(filepath, dedent(contents)) | ||
configfiles.push(filepath) | ||
} | ||
|
||
beforeEach(() => { | ||
// clear caches for creating & removing files during testing | ||
explorer.clearCaches() | ||
configfiles = [] | ||
}) | ||
|
||
afterEach(() => { | ||
// clean up any created config files | ||
configfiles.forEach((file) => { | ||
fs.unlinkSync(file) | ||
}) | ||
}) | ||
|
||
it('returns the default configuration', () => { | ||
expect(config({})).to.deep.equal(DEFAULT_CONFIGURATION) | ||
}) | ||
|
||
it('automatically loads overrides from a `.percy.yml` config file', () => { | ||
mkconfig('.percy.yml', ` | ||
version: 1 | ||
snapshot: | ||
widths: [320, 1200] | ||
enable-javascript: true | ||
agent: | ||
asset-discovery: | ||
request-headers: | ||
Authorization: 'Basic abc123=' | ||
`) | ||
|
||
expect(config({})).to.deep.equal({ | ||
...DEFAULT_CONFIGURATION, | ||
snapshot: { | ||
...DEFAULT_CONFIGURATION.snapshot, | ||
'widths': [320, 1200], | ||
'enable-javascript': true, | ||
}, | ||
agent: { | ||
...DEFAULT_CONFIGURATION.agent, | ||
'asset-discovery': { | ||
...DEFAULT_CONFIGURATION.agent['asset-discovery'], | ||
'request-headers': { | ||
Authorization: 'Basic abc123=', | ||
}, | ||
}, | ||
}, | ||
}) | ||
}) | ||
|
||
it('overrides defaults and config file options with flags and args', () => { | ||
mkconfig('.percy.json', `{ | ||
"version": 1, | ||
"snapshot": { | ||
"widths": [800] | ||
}, | ||
"static-snapshots": { | ||
"path": "_wrong/", | ||
"ignore-files": "**/*.ignore.*" | ||
} | ||
}`) | ||
|
||
const flags = { 'snapshot-files': '**/*.snapshot.html' } | ||
const args = { snapshotDirectory: '_site/' } | ||
|
||
expect(config(flags, args)).to.deep.equal({ | ||
...DEFAULT_CONFIGURATION, | ||
'snapshot': { | ||
...DEFAULT_CONFIGURATION.snapshot, | ||
widths: [800], | ||
}, | ||
'static-snapshots': { | ||
...DEFAULT_CONFIGURATION['static-snapshots'], | ||
'path': '_site/', | ||
'ignore-files': '**/*.ignore.*', | ||
'snapshot-files': '**/*.snapshot.html', | ||
}, | ||
}) | ||
}) | ||
}) |