Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. See [standa
### Changed

* Simplify automatic loading: use `import 'dotenv/config'` or `dotenv run -- yourcommand` ([#1035](https://github.com/motdotla/dotenv/pull/1035))
* Injecting message sent to stderr rather than stdout ([#1037](https://github.com/motdotla/dotenv/pull/1037))

### Removed

Expand Down
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function run (argv) {
if (result.loadedPaths.length > 0) {
message += ` from ${result.loadedPaths.join(', ')}`
}
console.log(message)
console.error(message)
}
} catch (e) {
console.error(`dotenv: ${e.message}`)
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function _debug (message) {
}

function _log (message) {
console.log(`◇ ${message}`)
console.error(`◇ ${message}`)
}

function _resolveHome (envPath) {
Expand Down
28 changes: 14 additions & 14 deletions tests/test-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ t.test('dotenv run loads .env by default', ct => {
removeDir(cwd)

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (1) from .env\nbasic\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'basic\n')
ct.equal(result.stderr, '◇ injected env (1) from .env\n')
ct.end()
})

Expand All @@ -68,8 +68,8 @@ t.test('dotenv run continues when default .env is missing', ct => {
removeDir(cwd)

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (0)\nok\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'ok\n')
ct.equal(result.stderr, '◇ injected env (0)\n')
ct.end()
})

Expand All @@ -85,8 +85,8 @@ t.test('dotenv run supports -f path', ct => {
])

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (2) from ./tests/.env.local\nlocal_basic\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'local_basic\n')
ct.equal(result.stderr, '◇ injected env (2) from ./tests/.env.local\n')
ct.end()
})

Expand All @@ -101,8 +101,8 @@ t.test('dotenv run supports -f=path', ct => {
])

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (2) from ./tests/.env.local\nlocal_basic\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'local_basic\n')
ct.equal(result.stderr, '◇ injected env (2) from ./tests/.env.local\n')
ct.end()
})

Expand All @@ -120,8 +120,8 @@ t.test('dotenv run supports multiple -f paths without override', ct => {
])

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (41) from ./tests/.env.local, ./tests/.env\nlocal_basic\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'local_basic\n')
ct.equal(result.stderr, '◇ injected env (41) from ./tests/.env.local, ./tests/.env\n')
ct.end()
})

Expand All @@ -142,8 +142,8 @@ t.test('dotenv run does not override existing environment variables', ct => {
)

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (39) from ./tests/.env\nexisting\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, 'existing\n')
ct.equal(result.stderr, '◇ injected env (39) from ./tests/.env\n')
ct.end()
})

Expand All @@ -164,8 +164,8 @@ t.test('dotenv run does not expand variables', ct => {
removeDir(cwd)

ct.equal(result.status, 0)
ct.equal(result.stdout, '◇ injected env (2) from .env\n$BASIC\n')
ct.equal(result.stderr, '')
ct.equal(result.stdout, '$BASIC\n')
ct.equal(result.stderr, '◇ injected env (2) from .env\n')
ct.end()
})

Expand Down
39 changes: 21 additions & 18 deletions tests/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ const t = require('tap')
const dotenv = require('../lib/main')

let logStub
let errorStub

t.beforeEach(() => {
logStub = null
errorStub = null
delete process.env.BASIC // reset
})

t.afterEach(() => {
if (logStub) logStub.restore()
if (errorStub) errorStub.restore()
delete process.env.DOTENV_CONFIG_ENCODING
delete process.env.DOTENV_CONFIG_PATH
delete process.env.DOTENV_CONFIG_QUIET
Expand All @@ -27,12 +30,12 @@ t.test('uses DOTENV_CONFIG_* values as config defaults', ct => {
process.env.DOTENV_CONFIG_QUIET = 'true'
process.env.DOTENV_CONFIG_OVERRIDE = 'true'
const processEnv = { BASIC: 'existing' }
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ processEnv })

ct.equal(processEnv.BASIC, 'local_basic')
ct.ok(logStub.notCalled)
ct.ok(errorStub.notCalled)
ct.end()
})

Expand All @@ -41,12 +44,12 @@ t.test('config options override DOTENV_CONFIG_* defaults', ct => {
process.env.DOTENV_CONFIG_QUIET = 'true'
process.env.DOTENV_CONFIG_OVERRIDE = 'true'
const processEnv = { BASIC: 'existing' }
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ path: 'tests/.env', quiet: false, override: false, processEnv })

ct.equal(processEnv.BASIC, 'existing')
ct.ok(logStub.called)
ct.ok(errorStub.called)
ct.end()
})

Expand Down Expand Up @@ -287,7 +290,7 @@ t.test('logs any errors parsing when in debug and override mode', ct => {
})

t.test('deals with file:// path', ct => {
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

const testPath = 'file:///tests/.env'
const env = dotenv.config({ path: testPath })
Expand All @@ -296,7 +299,7 @@ t.test('deals with file:// path', ct => {
ct.equal(process.env.BASIC, undefined)
ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'")

ct.ok(logStub.called)
ct.ok(errorStub.called)

ct.end()
})
Expand Down Expand Up @@ -336,62 +339,62 @@ t.test('path.relative fails somehow', ct => {

t.test('displays the injected env message without tips', ct => {
ct.plan(1)
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')
const testPath = 'tests/.env'

dotenv.config({ path: testPath })

ct.match(logStub.firstCall.args[0], /^◇ injected env \(\d+\) from tests\/\.env$/)
ct.match(errorStub.firstCall.args[0], /^◇ injected env \(\d+\) from tests\/\.env$/)
ct.end()
})

t.test('logs when no path is set', ct => {
ct.plan(1)

logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config()
ct.ok(logStub.called)
ct.ok(errorStub.called)
})

t.test('does log by default', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ path: testPath })
ct.ok(logStub.called)
ct.ok(errorStub.called)
})

t.test('does not log if quiet flag passed true', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ path: testPath, quiet: true })
ct.ok(logStub.notCalled)
ct.ok(errorStub.notCalled)
})

t.test('does log if quiet flag false', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ path: testPath, quiet: false })
ct.ok(logStub.called)
ct.ok(errorStub.called)
})

t.test('does log if quiet flag present and undefined/null', ct => {
ct.plan(1)

const testPath = 'tests/.env'
logStub = sinon.stub(console, 'log')
errorStub = sinon.stub(console, 'error')

dotenv.config({ path: testPath, quiet: undefined })
ct.ok(logStub.called)
ct.ok(errorStub.called)
})

t.test('logs if debug set', ct => {
Expand Down
Loading