Skip to content

Commit

Permalink
Merge branch 'release/v2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmorris committed Sep 30, 2020
2 parents 5b2a933 + 849af31 commit 9da53fe
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 60 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "14"
- "12"
- "10"
- "8"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.9.0 - 2020.09.30
- Missing values in schema now default to empty strings for `errorOnRegex` (thanks @FokkeZB)
- Minor modernization and refactoring of unit tests

## 2.8.0 - 2020.03.25
- Update dependencies while retaining compatibility with Node 6
- Add ability to configure through environment variables (thanks @Levino)
Expand Down
96 changes: 46 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dotenv-extended",
"version": "2.8.0",
"version": "2.9.0",
"description": "A module for loading .env files and optionally loading defaults and a schema for validating all values are present.",
"repository": "[email protected]:keithmorris/node-dotenv-extended.git",
"main": "lib/index.js",
Expand Down Expand Up @@ -28,6 +28,8 @@
"@babel/preset-env": "^7.9.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^7.0.2",
"@types/sinon": "^9.0.0",
"@types/sinon-chai": "^3.2.4",
"babel-eslint": "8.2.6",
"chai": "^4.2.0",
"coveralls": "^3.0.7",
Expand Down
2 changes: 1 addition & 1 deletion src/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {config} from '..';
import {parseCommand} from '../utils/parse-command';
import parseCommand from '../utils/parse-command';
import {spawn} from 'cross-spawn';

function loadAndExecute(args) {
Expand Down
4 changes: 2 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {config} from './index';

function reduceArguments(prev, curr) {
const reduceArguments = (prev, curr) => {
const matches = curr.match(/^dotenv_config_(.+)=(.+)/);
return hasMatches(matches)
? expandKeyValFromMatches(matches, prev)
: prev;
}
};

const expandKeyValFromMatches = ([, key, value], prev) => ({
...prev,
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const config = options => {
if (options.errorOnRegex) {
const regexMismatchKeys = schemaKeys.filter(function (key) {
if (schema[key]) {
return !new RegExp(schema[key]).test(config[key]);
return !new RegExp(schema[key]).test(typeof config[key] === 'string' ? config[key] : '');
}
});

Expand Down
5 changes: 5 additions & 0 deletions test/.env.schema.regex-optional
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TEST_VAR=^my test var$
TEST_ONE=^overridden$

TEST_MISSING_OPTIONAL=^(optional)?$
TEST_MISSING_REQUIRED=^optional$
19 changes: 14 additions & 5 deletions test/test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import mockery from 'mockery';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';

import dotenvex from '../lib/index';
import parseCommand from '../lib/utils/parse-command';
import getConfigFromEnv from '../lib/utils/config-from-env';

chai.use(sinonChai);

describe('dotenv-extended tests', () => {
let dotenvex;

before(() => {
mockery.enable({
Expand All @@ -16,7 +19,6 @@ describe('dotenv-extended tests', () => {
useCleanCache: true
});
sinon.stub(console, 'error');
dotenvex = require('../');
});

after(() => {
Expand Down Expand Up @@ -163,6 +165,16 @@ describe('dotenv-extended tests', () => {
expect(runTest).to.throw('REGEX MISMATCH: TEST_TWO, TEST_THREE');
});

it('Should default missing values to empty string when errorOnRegex is true', () => {
const runTest = () => {
dotenvex.load({
schema: '.env.schema.regex-optional',
errorOnRegex: true,
});
};
expect(runTest).to.throw('REGEX MISMATCH: TEST_MISSING_REQUIRED');
});

it('Should log an error when silent is set to false and .env.defaults is missing', function () {
dotenvex.load({silent: false});
expect(console.error).to.have.been.calledOnce;
Expand All @@ -183,9 +195,6 @@ describe('Supporting libraries tests', () => {
delete process.env.DOTENV_CONFIG_ASSIGN_TO_PROCESS_ENV;
delete process.env.DOTENV_CONFIG_OVERRIDE_PROCESS_ENV;
});

const parseCommand = require('../lib/utils/parse-command').parseCommand;
const getConfigFromEnv = require('../lib/utils/config-from-env').getConfigFromEnv;
const cliArgs = [
'--encoding=utf8',
'--silent=true',
Expand Down

0 comments on commit 9da53fe

Please sign in to comment.