Comparing version 1.2.0 to 1.2.1
@@ -101,3 +101,3 @@ 'use strict' | ||
let val | ||
if (!originalVal) { | ||
if (originalVal === undefined) { | ||
if (cfg.optional === true) { | ||
@@ -104,0 +104,0 @@ continue |
@@ -11,14 +11,38 @@ /* global describe it */ | ||
describe('lawn', function () { | ||
describe('validate', function () { | ||
it('converters a number', function () { | ||
describe('.validate(spec)', function () { | ||
it('throws on missing key', function () { | ||
const spec = { | ||
SECRET: lawn.string, | ||
PORT: lawn.number | ||
} | ||
assert.throws(() => lawn.validate(spec, { | ||
SECRET: 'WHAT' | ||
}), /PORT is missing/) | ||
}) | ||
it('uses defaults when missing', function () { | ||
const spec = { | ||
PORT: lawn.number.default(8000) | ||
} | ||
const result = lawn.validate(spec, { | ||
SECRET: 'WHAT' | ||
}) | ||
assert.propertyVal(result, 'PORT', 8000) | ||
}) | ||
it('validates process.env if no properties are given', function () { | ||
process.env = { | ||
SECRET: 's3cr3t', | ||
PORT: '8000' | ||
}) | ||
} | ||
const spec = { | ||
SECRET: lawn.string, | ||
PORT: lawn.number | ||
} | ||
const result = lawn.validate(spec) | ||
assert.deepEqual(result, { | ||
@@ -29,14 +53,23 @@ SECRET: 's3cr3t', | ||
}) | ||
}) | ||
it('throws on NaN', function () { | ||
describe('.number', function () { | ||
it('converts a number', function () { | ||
const spec = { | ||
SECRET: lawn.string, | ||
PORT: lawn.number | ||
} | ||
assert.throws(() => lawn.validate(spec, { | ||
PORT: 'WHAT' | ||
}), /PORT is invalid: 'WHAT' is not a number/) | ||
const result = lawn.validate(spec, { | ||
SECRET: 's3cr3t', | ||
PORT: '8000' | ||
}) | ||
assert.deepEqual(result, { | ||
SECRET: 's3cr3t', | ||
PORT: 8000 | ||
}) | ||
}) | ||
it('throws on missing key', function () { | ||
it('throws on NaN', function () { | ||
const spec = { | ||
@@ -47,18 +80,8 @@ PORT: lawn.number | ||
assert.throws(() => lawn.validate(spec, { | ||
SECRET: 'WHAT' | ||
}), /PORT is missing/) | ||
PORT: 'WHAT' | ||
}), /PORT is invalid: 'WHAT' is not a number/) | ||
}) | ||
}) | ||
it('uses defaults when missing', function () { | ||
const spec = { | ||
PORT: lawn.number.default(8000) | ||
} | ||
const result = lawn.validate(spec, { | ||
SECRET: 'WHAT' | ||
}) | ||
assert.propertyVal(result, 'PORT', 8000) | ||
}) | ||
describe('.bool', function () { | ||
it('converts a boolean', function () { | ||
@@ -98,20 +121,13 @@ const spec = { | ||
}) | ||
}) | ||
it('validates process.env if no properties are given', function () { | ||
process.env = { | ||
SECRET: 's3cr3t', | ||
PORT: '8000' | ||
} | ||
describe('.string', function () { | ||
it('accepts the empty string as valid', function () { | ||
const spec = { | ||
SECRET: lawn.string, | ||
PORT: lawn.number | ||
PASSWORD: lawn.string | ||
} | ||
const result = lawn.validate(spec) | ||
assert.deepEqual(result, { | ||
SECRET: 's3cr3t', | ||
PORT: 8000 | ||
}) | ||
assert.doesNotThrow(() => lawn.validate(spec, { | ||
PASSWORD: '' | ||
})) | ||
}) | ||
@@ -184,3 +200,3 @@ }) | ||
describe('output', function () { | ||
describe('.output(spec)', function () { | ||
it('outputs some simple stuff', function () { | ||
@@ -187,0 +203,0 @@ const spec = { |
{ | ||
"name": "lawn", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "The environment is dangerous. Your lawn is nice. Stay in your lawn.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17417
339