Skip to content

Commit

Permalink
fix: Use lodash has to check config keys presence (#265)
Browse files Browse the repository at this point in the history
Closes #263
  • Loading branch information
okonet authored Sep 6, 2017
1 parent d07b237 commit c0287e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

const sgf = require('staged-git-files')
const Listr = require('listr')
const has = require('lodash/has')
const runScript = require('./runScript')
const generateTasks = require('./generateTasks')
const resolveGitDir = require('./resolveGitDir')

/**
* Executes all tasks and either resolves or rejects the promise
* @param packageJson
* @param config
* @param config {Object}
* @returns {Promise}
*/
module.exports = function runAll(packageJson, config) {
// Config validation
if (!config || !config.gitDir || !config.concurrent || !config.renderer) {
if (!config || !has(config, 'gitDir') || !has(config, 'concurrent') || !has(config, 'renderer')) {
throw new Error('Invalid config provided to runAll! Use getConfig instead.')
}

Expand Down
7 changes: 7 additions & 0 deletions test/runAll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ describe('runAll', () => {
expect(() => runAll(packageJson)).toThrowErrorMatchingSnapshot()
})

it('should not throw when a valid config is provided', () => {
const config = getConfig({
concurrent: false
})
expect(() => runAll(packageJson, config)).not.toThrow()
})

it('should return a promise', () => {
expect(runAll(packageJson, getConfig({}))).toBeInstanceOf(Promise)
})
Expand Down

0 comments on commit c0287e6

Please sign in to comment.