Skip to content

Commit c683c24

Browse files
author
v1rtl
committed
Start writing dotenv tests
1 parent 179ef63 commit c683c24

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ node_modules
22
dist
33
log.txt
44
coverage
5-
.env
5+
examples/*/.env
66
pnpm-lock.yaml
77
.next

__tests__/fixtures/.env

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
BASIC=basic
2+
3+
# previous line intentionally left blank
4+
AFTER_LINE=after_line
5+
EMPTY=
6+
SINGLE_QUOTES='single_quotes'
7+
SINGLE_QUOTES_SPACED=' single quotes '
8+
DOUBLE_QUOTES="double_quotes"
9+
DOUBLE_QUOTES_SPACED=" double quotes "
10+
EXPAND_NEWLINES="expand\nnew\nlines"
11+
DONT_EXPAND_UNQUOTED=dontexpand\nnewlines
12+
DONT_EXPAND_SQUOTED='dontexpand\nnewlines'
13+
# COMMENTS=work
14+
EQUAL_SIGNS=equals==
15+
RETAIN_INNER_QUOTES={"foo": "bar"}
16+
RETAIN_LEADING_DQUOTE="retained
17+
RETAIN_LEADING_SQUOTE='retained
18+
RETAIN_TRAILING_DQUOTE=retained"
19+
RETAIN_TRAILING_SQUOTE=retained'
20+
RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}'
21+
TRIM_SPACE_FROM_UNQUOTED= some spaced out string
22+
USERNAME=therealnerdybeast@example.tld
23+
SPACED_KEY = parsed

__tests__/mw/dotenv.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
import * as dotenv from '../../packages/dotenv/src'
4+
5+
const parsed = dotenv.parse(fs.readFileSync(path.join(__dirname, '../fixtures/.env'), { encoding: 'utf8' }))
6+
7+
describe('Dotenv parsing', () => {
8+
it('sets basic environment variable', () => {
9+
expect(parsed.BASIC).toBe('basic')
10+
})
11+
it('reads after a skipped line', () => {
12+
expect(parsed.AFTER_LINE).toBe('after_line')
13+
})
14+
it('defaults empty values to empty string', () => {
15+
expect(parsed.EMPTY).toBe('')
16+
})
17+
it('escapes single quoted values', () => {
18+
expect(parsed.SINGLE_QUOTES).toBe('single_quotes')
19+
})
20+
})

0 commit comments

Comments
 (0)