Skip to content

Commit 9da53fe

Browse files
committed
Merge branch 'release/v2.9.0'
2 parents 5b2a933 + 849af31 commit 9da53fe

File tree

9 files changed

+77
-60
lines changed

9 files changed

+77
-60
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- "14"
34
- "12"
45
- "10"
56
- "8"

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.9.0 - 2020.09.30
4+
- Missing values in schema now default to empty strings for `errorOnRegex` (thanks @FokkeZB)
5+
- Minor modernization and refactoring of unit tests
6+
37
## 2.8.0 - 2020.03.25
48
- Update dependencies while retaining compatibility with Node 6
59
- Add ability to configure through environment variables (thanks @Levino)

package-lock.json

Lines changed: 46 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dotenv-extended",
3-
"version": "2.8.0",
3+
"version": "2.9.0",
44
"description": "A module for loading .env files and optionally loading defaults and a schema for validating all values are present.",
55
"repository": "[email protected]:keithmorris/node-dotenv-extended.git",
66
"main": "lib/index.js",
@@ -28,6 +28,8 @@
2828
"@babel/preset-env": "^7.9.0",
2929
"@types/chai": "^4.2.11",
3030
"@types/mocha": "^7.0.2",
31+
"@types/sinon": "^9.0.0",
32+
"@types/sinon-chai": "^3.2.4",
3133
"babel-eslint": "8.2.6",
3234
"chai": "^4.2.0",
3335
"coveralls": "^3.0.7",

src/bin/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {config} from '..';
10-
import {parseCommand} from '../utils/parse-command';
10+
import parseCommand from '../utils/parse-command';
1111
import {spawn} from 'cross-spawn';
1212

1313
function loadAndExecute(args) {

src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {config} from './index';
22

3-
function reduceArguments(prev, curr) {
3+
const reduceArguments = (prev, curr) => {
44
const matches = curr.match(/^dotenv_config_(.+)=(.+)/);
55
return hasMatches(matches)
66
? expandKeyValFromMatches(matches, prev)
77
: prev;
8-
}
8+
};
99

1010
const expandKeyValFromMatches = ([, key, value], prev) => ({
1111
...prev,

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const config = options => {
5555
if (options.errorOnRegex) {
5656
const regexMismatchKeys = schemaKeys.filter(function (key) {
5757
if (schema[key]) {
58-
return !new RegExp(schema[key]).test(config[key]);
58+
return !new RegExp(schema[key]).test(typeof config[key] === 'string' ? config[key] : '');
5959
}
6060
});
6161

test/.env.schema.regex-optional

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
TEST_VAR=^my test var$
2+
TEST_ONE=^overridden$
3+
4+
TEST_MISSING_OPTIONAL=^(optional)?$
5+
TEST_MISSING_REQUIRED=^optional$

test/test.spec.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import mockery from 'mockery';
44
import sinon from 'sinon';
55
import sinonChai from 'sinon-chai';
66

7+
import dotenvex from '../lib/index';
8+
import parseCommand from '../lib/utils/parse-command';
9+
import getConfigFromEnv from '../lib/utils/config-from-env';
10+
711
chai.use(sinonChai);
812

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

1215
before(() => {
1316
mockery.enable({
@@ -16,7 +19,6 @@ describe('dotenv-extended tests', () => {
1619
useCleanCache: true
1720
});
1821
sinon.stub(console, 'error');
19-
dotenvex = require('../');
2022
});
2123

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

168+
it('Should default missing values to empty string when errorOnRegex is true', () => {
169+
const runTest = () => {
170+
dotenvex.load({
171+
schema: '.env.schema.regex-optional',
172+
errorOnRegex: true,
173+
});
174+
};
175+
expect(runTest).to.throw('REGEX MISMATCH: TEST_MISSING_REQUIRED');
176+
});
177+
166178
it('Should log an error when silent is set to false and .env.defaults is missing', function () {
167179
dotenvex.load({silent: false});
168180
expect(console.error).to.have.been.calledOnce;
@@ -183,9 +195,6 @@ describe('Supporting libraries tests', () => {
183195
delete process.env.DOTENV_CONFIG_ASSIGN_TO_PROCESS_ENV;
184196
delete process.env.DOTENV_CONFIG_OVERRIDE_PROCESS_ENV;
185197
});
186-
187-
const parseCommand = require('../lib/utils/parse-command').parseCommand;
188-
const getConfigFromEnv = require('../lib/utils/config-from-env').getConfigFromEnv;
189198
const cliArgs = [
190199
'--encoding=utf8',
191200
'--silent=true',

0 commit comments

Comments
 (0)