Skip to content

Instantly share code, notes, and snippets.

@kumar303
Created January 24, 2017 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumar303/027e02bda6f18ffc60087174d54e4ab4 to your computer and use it in GitHub Desktop.
Save kumar303/027e02bda6f18ffc60087174d54e4ab4 to your computer and use it in GitHub Desktop.
diff --git a/src/config.js b/src/config.js
index 92cf9a9..08b839a 100644
--- a/src/config.js
+++ b/src/config.js
@@ -53,4 +53,4 @@ export function loadJSConfigFile(filePath: string) {
throw new UsageError
(`Cannot read config file: ${filePath}\nError: ${error.message}`);
}
-}
\ No newline at end of file
+}
diff --git a/tests/unit/test.config.js b/tests/unit/test.config.js
index 098abf3..3246353 100644
--- a/tests/unit/test.config.js
+++ b/tests/unit/test.config.js
@@ -15,7 +15,7 @@ import {
import {withTempDir} from '../../src/util/temp-dir';
import {UsageError} from '../../src/errors';
-function makeArgv({
+function setUpProgram({
userCmd = [],
command = 'fakecommand',
commandDesc = 'this is a fake command',
@@ -31,28 +31,29 @@ function makeArgv({
program.command(command, commandDesc, commandExecutor, commandOpt);
}
- return program.yargs.exitProcess(false).argv;
+ return {
+ argv: program.yargs.exitProcess(false).argv,
+ defaultValues: program.defaultValues,
+ };
}
describe('config', () => {
describe('applyConfigToArgv', () => {
it('overrides the default value with a configured value', () => {
- const argv = makeArgv({
+ const {argv, defaultValues} = setUpProgram({
globalOpt: {
'source-dir': {
requiresArg: true,
type: 'string',
demand: false,
+ default: 'default/source/dir',
},
},
});
const configObject = {
sourceDir: '/configured/source/dir',
};
- const defaultValues = {
- sourceDir: 'default/source/dir',
- };
const newArgv = applyConfigToArgv({argv, configObject, defaultValues});
assert.strictEqual(newArgv.sourceDir, configObject.sourceDir);
});
@@ -60,7 +61,7 @@ describe('config', () => {
it('preserves a string option value on the command line', () => {
const cmdLineSrcDir = '/user/specified/source/dir/';
- const argv = makeArgv({
+ const {argv} = setUpProgram({
userCmd: ['fakecommand', '--source-dir', cmdLineSrcDir],
globalOpt: {
'source-dir': {
@@ -92,7 +93,7 @@ describe('config', () => {
describe('parseConfig', () => {
it('parses the configuration file correctly', () => {
- const argv = makeArgv({
+ const {argv} = setUpProgram({
globalOpt: {
'source-dir': {
requiresArg: true,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment