Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit empty collection of vars in example file #7

Merged
merged 1 commit into from
Sep 7, 2020
Merged
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: 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