mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
UPDATE testing
This commit is contained in:
parent
fa24b79ca8
commit
956b0efa8e
11
lib/index.js
11
lib/index.js
@ -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) {
|
||||
|
||||
@ -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": {
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user