Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config/project/plugins/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = function setEnvPlugins (params, project) {
let errType = `plugin: ${fn.plugin}, method: set.env`
try {
let result = fn({ arc: inv._project.arc, inventory: { inv } })
if (!is.object(result) || !Object.keys(result).length) {
return errors.push(`Env plugin returned invalid data, must return an Object with one or more keys + values: ${errType}`)
if (!is.object(result)) {
return errors.push(`Env plugin returned invalid data, must return an Object: ${errType}`)
}
// Populate env vars based on environment
// If any keys are environment names, disregard all keys except environment names
Expand Down
20 changes: 10 additions & 10 deletions test/unit/src/config/project/plugins/env-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('Do nothing if no env setter plugins are present', t => {
})

test('Env setter plugin runs', t => {
t.plan(54)
t.plan(58)
let errors, inventory, plugins, pluginOne, pluginTwo

// Stringify env obj values
Expand All @@ -67,6 +67,14 @@ test('Env setter plugin runs', t => {
inventory = newInv([ pluginOne ])
plugins = setEnvPlugins({ inventory, errors }, { arc: {}, env: noEnv })

// Empty object
errors = []
pluginOne = () => ({})
inventory = newInv([ pluginOne ])
setEnvPlugins({ inventory, errors }, emptyProj)
t.notOk(errors.length, 'Did not return errors')
check(plugins, varStr)

// String
errors = []
pluginOne = () => varStr
Expand Down Expand Up @@ -176,7 +184,7 @@ test('Env setter plugin runs', t => {
})

test('Env setter plugin errors', t => {
t.plan(18)
t.plan(16)
let errors, inventory, pluginOne, pluginTwo

// No return
Expand Down Expand Up @@ -221,14 +229,6 @@ test('Env setter plugin errors', t => {
t.equal(errors.length, 1, 'Returned an error')
t.match(errors[0], /Runtime plugin/, 'Got correct error')

// Empty object
errors = []
pluginOne = () => ({})
inventory = newInv([ pluginOne ])
setEnvPlugins({ inventory, errors }, emptyProj)
t.equal(errors.length, 1, 'Returned an error')
t.match(errors[0], /must return an Object/, 'Got correct error')

// Multiple plugins
errors = []
pluginOne = () => varStr
Expand Down