Skip to content

Commit e6799e6

Browse files
committed
add tests
1 parent ec72534 commit e6799e6

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ function configDotenv (options) {
266266
try {
267267
const relative = path.relative(process.cwd(), filePath)
268268
shortPaths.push(relative)
269-
} catch {}
269+
} catch (e) {
270+
if (debug) {
271+
_debug(`Failed to load ${filePath} ${e.message}`)
272+
}
273+
lastError = e
274+
}
270275
}
271276

272277
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')}`)

tests/test-config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,37 @@ t.test('logs any errors parsing when in debug and override mode', ct => {
250250

251251
logStub.restore()
252252
})
253+
254+
t.test('deals with file:// path', ct => {
255+
const logStub = sinon.stub(console, 'log')
256+
257+
const testPath = 'file:///tests/.env'
258+
const env = dotenv.config({ path: testPath })
259+
260+
ct.equal(env.parsed.BASIC, undefined)
261+
ct.equal(process.env.BASIC, undefined)
262+
ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'")
263+
264+
ct.ok(logStub.notCalled)
265+
266+
logStub.restore()
267+
268+
ct.end()
269+
})
270+
271+
t.test('deals with file:// path and debug true', ct => {
272+
const logStub = sinon.stub(console, 'log')
273+
274+
const testPath = 'file:///tests/.env'
275+
const env = dotenv.config({ path: testPath, debug: true })
276+
277+
ct.equal(env.parsed.BASIC, undefined)
278+
ct.equal(process.env.BASIC, undefined)
279+
ct.equal(env.error.message, "ENOENT: no such file or directory, open 'file:///tests/.env'")
280+
281+
ct.ok(logStub.called)
282+
283+
logStub.restore()
284+
285+
ct.end()
286+
})

0 commit comments

Comments
 (0)