UPDATE testing

This commit is contained in:
serapath 2017-02-21 10:30:10 +01:00
parent fa24b79ca8
commit 956b0efa8e
3 changed files with 14 additions and 7 deletions

View File

@ -5,7 +5,7 @@ const path = require('path')
const fs = require('fs')
const rcFileLocation = path.join(process.cwd(), '.env-cmdrc')
const envFilePathDefault = path.join(process.cwd(), '.env')
function EnvCmd (args) {
// First Parse the args from the command line
const parsedArgs = ParseArgs(args)
@ -99,7 +99,7 @@ function ParseEnvVars (envString) {
// Parse out all env vars from a given env file string and return an object
function ParseEnvString (envFileString) {
// First thing we do is stripe out all comments
envFileString = StripComments(envFileString)
envFileString = StripComments(envFileString.toString())
// Next we stripe out all the empty lines
envFileString = StripEmptyLines(envFileString)
@ -135,7 +135,12 @@ function UseCmdLine (parsedArgs) {
try {
file = fs.readFileSync(envFilePath, { encoding: 'utf8' })
} catch (err) {
console.error(`Error! Could not find or read file at ${envFilePath}`)
console.error(`WARNING:
Could not find or read file at:
${envFilePath}
Trying to fallback to read:
${envFilePathDefault}
`)
try {
file = fs.readFileSync(envFilePathDefault)
} catch (e) {

View File

@ -28,7 +28,8 @@
"author": "Todd Bluhm",
"contributors": [
"Eric Lanehart <eric@pushred.co>",
"Jon Scheiding <jonscheiding@gmail.com>"
"Jon Scheiding <jonscheiding@gmail.com>",
"serapath (Alexander Praetorius) <dev@serapath.de>"
],
"license": "MIT",
"bugs": {

View File

@ -250,13 +250,14 @@ describe('env-cmd', function () {
assert(spawnStub.args[0][2].env.ANSWER === '42')
})
it('should throw error if file does not exist', function () {
it('should throw error if file and fallback does not exist', function () {
this.readFileStub.restore()
try {
EnvCmd(['./test/.non-existent-file', 'echo', '$BOB'])
} catch (e) {
const resolvedPath = path.join(process.cwd(), 'test/.non-existent-file')
assert(e.message === `Error! Could not find or read file at ${resolvedPath}`)
const resolvedPath = path.join(process.cwd(), '.env')
assert(e.message ===`Error! Could not fallback to find or read file at ${resolvedPath}`)
return
}
assert(!'No exception thrown')