From e1dabf635d996df34955caab0ce4c186451009d7 Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Sat, 12 Apr 2025 22:19:13 -0400 Subject: [PATCH] Allow set.env plugin to return an empty object --- src/config/project/plugins/env.js | 4 ++-- .../src/config/project/plugins/env-test.js | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/config/project/plugins/env.js b/src/config/project/plugins/env.js index 0392725e..f0f083be 100644 --- a/src/config/project/plugins/env.js +++ b/src/config/project/plugins/env.js @@ -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 diff --git a/test/unit/src/config/project/plugins/env-test.js b/test/unit/src/config/project/plugins/env-test.js index c4b1ba7c..4d7b6e01 100644 --- a/test/unit/src/config/project/plugins/env-test.js +++ b/test/unit/src/config/project/plugins/env-test.js @@ -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 @@ -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 @@ -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 @@ -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