-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Babel Targets & Autoprefixer Config File Options (#107)
* swapping order of plugins * adding comment * intial addition of helper for working with config file * initial work * linter * moving plugins to top level * initial work, testing is broken * fix old tests * adding comment * adding tests to the config file helper * lint bug * test coverage upping
- Loading branch information
Showing
6 changed files
with
135 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const amphoraFs = require('amphora-fs'), | ||
CONFIG_FILENAME = 'claycli.config'; | ||
var CONFIG_FILE = getConfigFile(); | ||
|
||
/** | ||
* Grab the config file from the working directory | ||
* or return undefined | ||
* | ||
* @returns {Object|Undefined} | ||
*/ | ||
function getConfigFile() { | ||
return amphoraFs.tryRequire(`${process.cwd()}/${CONFIG_FILENAME}`); | ||
} | ||
|
||
/** | ||
* Return a value from the config file | ||
* | ||
* @param {String} key | ||
* @returns {Any} | ||
*/ | ||
function getConfigValue(key) { | ||
if (!CONFIG_FILE) { | ||
return undefined; | ||
} | ||
|
||
return CONFIG_FILE[key]; | ||
} | ||
|
||
module.exports.getConfigValue = getConfigValue; | ||
|
||
// For testing | ||
module.exports.getConfigFile = getConfigFile; | ||
module.exports.setConfigFile = val => CONFIG_FILE = val; |
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,50 @@ | ||
'use strict'; | ||
|
||
const lib = require('./config-file-helpers'), | ||
amphoraFs = require('amphora-fs'); | ||
|
||
// Mock tryRequire | ||
amphoraFs.tryRequire = jest.fn(); | ||
|
||
describe('project specific config file helpers', () => { | ||
describe('getConfigFile', () => { | ||
const fn = lib.getConfigFile; | ||
|
||
it('returns undefined if the file is not found', () => { | ||
expect(fn()).toBe(undefined); | ||
}); | ||
|
||
it('returns a file if one is found', () => { | ||
amphoraFs.tryRequire.mockReturnValue({}); | ||
|
||
expect(fn()).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('getConfigValue', () => { | ||
const fn = lib.getConfigValue, | ||
SAMPLE_CONFIG = { | ||
babelTargets: 'some value', | ||
autoprefixerOptions: { foo: true, bar: false } | ||
}; | ||
|
||
beforeEach(() => { | ||
lib.setConfigFile(SAMPLE_CONFIG); | ||
}); | ||
|
||
it('returns undefined if the config file is not present', () => { | ||
lib.setConfigFile(undefined); | ||
|
||
expect(fn('babelTargets')).toBe(undefined); | ||
}); | ||
|
||
it('returns a value from the config if it exists', () => { | ||
expect(fn('babelTargets')).toBe('some value'); | ||
expect(fn('autoprefixerOptions')).toEqual({ foo: true, bar: false}); | ||
}); | ||
|
||
it('returns undefined if the value does not exist', () => { | ||
expect(fn('fakeVal')).toBe(undefined); | ||
}); | ||
}); | ||
}); |