Skip to content

Commit

Permalink
Permit empty collection of vars (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy authored Sep 7, 2020
1 parent 345ebf0 commit 6fda3fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 !== '';
});
Expand Down
12 changes: 4 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6fda3fc

Please sign in to comment.