From 6dadc7cd5916c6522c254775805d8eb00ef6a14b Mon Sep 17 00:00:00 2001 From: Devin Ivy Date: Fri, 21 Aug 2020 01:14:13 -0400 Subject: [PATCH] Permit empty collection of vars --- index.js | 4 ---- test.js | 12 ++++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 073ed0f..91d12eb 100644 --- a/index.js +++ b/index.js @@ -54,7 +54,6 @@ const isWindows = () => { return isWsl || process.platform === 'win32'; }; -// eslint-disable-next-line max-statements const envy = (input) => { const envPath = input || '.env'; const examplePath = envPath + '.example'; @@ -69,9 +68,6 @@ const envy = (input) => { const exampleEnvKeys = Object.keys(exampleEnv); const camelizedExampleEnvKeys = Object.keys(camelcaseKeys(exampleEnv)); - if (exampleEnvKeys.length === 0) { - throw new Error(`At least one entry is required in ${examplePath}`); - } const exampleHasValues = Object.values(exampleEnv).some((val) => { return val !== ''; }); diff --git a/test.js b/test.js index c4f50d3..8719238 100644 --- a/test.js +++ b/test.js @@ -39,6 +39,10 @@ test('returns excess vars in .env', (t) => { }); }); +test('returns empty collection of vars', (t) => { + t.deepEqual(fixture('empty-example'), {}); +}); + test('can parse complex values', (t) => { // Complex values are those which have a high risk of confusing the parser, // such as those using reserved characters. @@ -98,14 +102,6 @@ test('requires secure file permissions on .env.example', (t) => { t.is(err.message, `File must not be writable by others. Fix: chmod o-w '${filepath}'`); }); -test('requires at least one entry in .env.example', (t) => { - const err = t.throws(() => { - fixture('empty-example'); - }, Error); - const filepath = path.join('fixture', 'empty-example', '.env.example'); - t.is(err.message, `At least one entry is required in ${filepath}`); -}); - test('does not modify process.env', (t) => { const oldEnvDescriptor = Object.getOwnPropertyDescriptor(process, 'env'); const oldEnv = process.env;