@@ -7,8 +7,8 @@ const fixturesDir = join(import.meta.dir, "../fixtures");
77
88describe ( "parseEnvFile" , ( ) => {
99 describe ( "basic parsing" , ( ) => {
10- test ( "parses simple KEY=value pairs" , ( ) => {
11- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
10+ test ( "parses simple KEY=value pairs" , async ( ) => {
11+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
1212
1313 expect ( result . variables . length ) . toBe ( 7 ) ;
1414 expect ( result . variables [ 0 ] ) . toEqual ( {
@@ -19,191 +19,191 @@ describe("parseEnvFile", () => {
1919 } ) ;
2020 } ) ;
2121
22- test ( "returns correct variable count" , ( ) => {
23- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
22+ test ( "returns correct variable count" , async ( ) => {
23+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
2424 expect ( result . variables . length ) . toBe ( 7 ) ;
2525 } ) ;
2626
27- test ( "captures line numbers" , ( ) => {
28- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
27+ test ( "captures line numbers" , async ( ) => {
28+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
2929 const debugVar = result . variables . find ( ( v ) => v . key === "DEBUG" ) ;
3030 expect ( debugVar ?. line ) . toBe ( 11 ) ;
3131 } ) ;
3232 } ) ;
3333
3434 describe ( "quoted values" , ( ) => {
35- test ( "handles double-quoted values" , ( ) => {
36- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
35+ test ( "handles double-quoted values" , async ( ) => {
36+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
3737 const doubleQuoted = result . variables . find ( ( v ) => v . key === "DOUBLE_QUOTED" ) ;
3838 expect ( doubleQuoted ?. value ) . toBe ( "hello world" ) ;
3939 } ) ;
4040
41- test ( "handles single-quoted values" , ( ) => {
42- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
41+ test ( "handles single-quoted values" , async ( ) => {
42+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
4343 const singleQuoted = result . variables . find ( ( v ) => v . key === "SINGLE_QUOTED" ) ;
4444 expect ( singleQuoted ?. value ) . toBe ( "hello world" ) ;
4545 } ) ;
4646
47- test ( "preserves spaces in quoted values" , ( ) => {
48- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
47+ test ( "preserves spaces in quoted values" , async ( ) => {
48+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
4949 const withSpaces = result . variables . find ( ( v ) => v . key === "DOUBLE_WITH_SPACES" ) ;
5050 expect ( withSpaces ?. value ) . toBe ( " spaces around " ) ;
5151 } ) ;
5252
53- test ( "preserves # in quoted values (not treated as comment)" , ( ) => {
54- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
53+ test ( "preserves # in quoted values (not treated as comment)" , async ( ) => {
54+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
5555 const withHash = result . variables . find ( ( v ) => v . key === "DOUBLE_WITH_HASH" ) ;
5656 expect ( withHash ?. value ) . toBe ( "value # not a comment" ) ;
5757 } ) ;
5858
59- test ( "handles empty quoted values" , ( ) => {
60- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
59+ test ( "handles empty quoted values" , async ( ) => {
60+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
6161 const emptyDouble = result . variables . find ( ( v ) => v . key === "DOUBLE_EMPTY" ) ;
6262 const emptySingle = result . variables . find ( ( v ) => v . key === "SINGLE_EMPTY" ) ;
6363 expect ( emptyDouble ?. value ) . toBe ( "" ) ;
6464 expect ( emptySingle ?. value ) . toBe ( "" ) ;
6565 } ) ;
6666
67- test ( "handles unquoted values" , ( ) => {
68- const result = parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
67+ test ( "handles unquoted values" , async ( ) => {
68+ const result = await parseEnvFile ( join ( fixturesDir , "quoted-values.env" ) ) ;
6969 const unquoted = result . variables . find ( ( v ) => v . key === "UNQUOTED" ) ;
7070 expect ( unquoted ?. value ) . toBe ( "simple_value" ) ;
7171 } ) ;
7272 } ) ;
7373
7474 describe ( "comments" , ( ) => {
75- test ( "preserves standalone comments in lines array" , ( ) => {
76- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
75+ test ( "preserves standalone comments in lines array" , async ( ) => {
76+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
7777 const commentLines = result . lines . filter ( ( l ) => l . type === "comment" ) ;
7878 expect ( commentLines . length ) . toBeGreaterThan ( 0 ) ;
7979 } ) ;
8080
81- test ( "associates comments with following variables" , ( ) => {
82- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
81+ test ( "associates comments with following variables" , async ( ) => {
82+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
8383 const key1 = result . variables . find ( ( v ) => v . key === "KEY1" ) ;
8484 // KEY1 follows empty line, so no associated comment
8585 expect ( key1 ?. comment ) . toBeUndefined ( ) ;
8686 } ) ;
8787
88- test ( "strips inline comments from unquoted values" , ( ) => {
89- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
88+ test ( "strips inline comments from unquoted values" , async ( ) => {
89+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
9090 const dbPort = result . variables . find ( ( v ) => v . key === "DB_PORT" ) ;
9191 expect ( dbPort ?. value ) . toBe ( "5432" ) ;
9292 } ) ;
9393
94- test ( "preserves original comment content including #" , ( ) => {
95- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
94+ test ( "preserves original comment content including #" , async ( ) => {
95+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
9696 const firstComment = result . lines . find ( ( l ) => l . type === "comment" ) ;
9797 expect ( firstComment ?. type === "comment" && firstComment . content ) . toContain ( "#" ) ;
9898 } ) ;
9999 } ) ;
100100
101101 describe ( "empty lines" , ( ) => {
102- test ( "preserves empty lines in lines array" , ( ) => {
103- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
102+ test ( "preserves empty lines in lines array" , async ( ) => {
103+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
104104 const emptyLines = result . lines . filter ( ( l ) => l . type === "empty" ) ;
105105 expect ( emptyLines . length ) . toBeGreaterThan ( 0 ) ;
106106 } ) ;
107107 } ) ;
108108
109109 describe ( "edge cases" , ( ) => {
110- test ( "handles multiple equals signs in value" , ( ) => {
111- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
110+ test ( "handles multiple equals signs in value" , async ( ) => {
111+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
112112 const equation = result . variables . find ( ( v ) => v . key === "EQUATION" ) ;
113113 expect ( equation ?. value ) . toBe ( "a=b=c=d" ) ;
114114 } ) ;
115115
116- test ( "handles URL with query parameters" , ( ) => {
117- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
116+ test ( "handles URL with query parameters" , async ( ) => {
117+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
118118 const url = result . variables . find ( ( v ) => v . key === "URL" ) ;
119119 expect ( url ?. value ) . toBe ( "https://example.com?foo=bar&baz=qux" ) ;
120120 } ) ;
121121
122- test ( "handles unicode characters in values" , ( ) => {
123- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
122+ test ( "handles unicode characters in values" , async ( ) => {
123+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
124124 const emoji = result . variables . find ( ( v ) => v . key === "EMOJI" ) ;
125125 const unicode = result . variables . find ( ( v ) => v . key === "UNICODE" ) ;
126126 expect ( emoji ?. value ) . toContain ( "🎉" ) ;
127127 expect ( unicode ?. value ) . toContain ( "你好" ) ;
128128 } ) ;
129129
130- test ( "handles long values" , ( ) => {
131- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
130+ test ( "handles long values" , async ( ) => {
131+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
132132 const longValue = result . variables . find ( ( v ) => v . key === "LONG_VALUE" ) ;
133133 expect ( longValue ?. value . length ) . toBeGreaterThan ( 100 ) ;
134134 } ) ;
135135
136- test ( "handles special characters in values" , ( ) => {
137- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
136+ test ( "handles special characters in values" , async ( ) => {
137+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
138138 const special = result . variables . find ( ( v ) => v . key === "SPECIAL_CHARS" ) ;
139139 expect ( special ?. value ) . toContain ( "@#$%" ) ;
140140 } ) ;
141141
142- test ( "handles JSON in values" , ( ) => {
143- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
142+ test ( "handles JSON in values" , async ( ) => {
143+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
144144 const json = result . variables . find ( ( v ) => v . key === "JSON_VALUE" ) ;
145145 expect ( json ?. value ) . toContain ( '"key"' ) ;
146146 } ) ;
147147 } ) ;
148148
149149 describe ( "variable names" , ( ) => {
150- test ( "accepts keys starting with underscore" , ( ) => {
151- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
150+ test ( "accepts keys starting with underscore" , async ( ) => {
151+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
152152 const underscoreKey = result . variables . find ( ( v ) => v . key === "_STARTS_WITH_UNDERSCORE" ) ;
153153 expect ( underscoreKey ) . toBeDefined ( ) ;
154154 } ) ;
155155
156- test ( "accepts keys with double underscores" , ( ) => {
157- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
156+ test ( "accepts keys with double underscores" , async ( ) => {
157+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
158158 const doubleUnderscore = result . variables . find ( ( v ) => v . key === "__DOUBLE_UNDERSCORE" ) ;
159159 expect ( doubleUnderscore ) . toBeDefined ( ) ;
160160 } ) ;
161161
162- test ( "accepts keys with numbers after first character" , ( ) => {
163- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
162+ test ( "accepts keys with numbers after first character" , async ( ) => {
163+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
164164 const key123 = result . variables . find ( ( v ) => v . key === "KEY123" ) ;
165165 expect ( key123 ) . toBeDefined ( ) ;
166166 } ) ;
167167
168- test ( "rejects keys starting with numbers" , ( ) => {
168+ test ( "rejects keys starting with numbers" , async ( ) => {
169169 // Need to create a test with invalid key to test this
170- const result = parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
170+ const result = await parseEnvFile ( join ( fixturesDir , "edge-cases.env" ) ) ;
171171 const invalidKey = result . variables . find ( ( v ) => v . key . match ( / ^ [ 0 - 9 ] / ) ) ;
172172 expect ( invalidKey ) . toBeUndefined ( ) ;
173173 } ) ;
174174 } ) ;
175175
176176 describe ( "error handling" , ( ) => {
177- test ( "throws Env2OpError for missing file" , ( ) => {
178- expect ( ( ) => parseEnvFile ( "/nonexistent/path/.env" ) ) . toThrow ( Env2OpError ) ;
177+ test ( "throws Env2OpError for missing file" , async ( ) => {
178+ expect ( parseEnvFile ( "/nonexistent/path/.env" ) ) . rejects . toThrow ( Env2OpError ) ;
179179 } ) ;
180180
181- test ( "throws with correct error code for missing file" , ( ) => {
181+ test ( "throws with correct error code for missing file" , async ( ) => {
182182 try {
183- parseEnvFile ( "/nonexistent/path/.env" ) ;
183+ await parseEnvFile ( "/nonexistent/path/.env" ) ;
184184 } catch ( e ) {
185185 expect ( e ) . toBeInstanceOf ( Env2OpError ) ;
186186 expect ( ( e as Env2OpError ) . code ) . toBe ( "ENV_FILE_NOT_FOUND" ) ;
187187 }
188188 } ) ;
189189
190- test ( "reports invalid variable names in errors array" , ( ) => {
190+ test ( "reports invalid variable names in errors array" , async ( ) => {
191191 // Create inline test for invalid names
192192 // For now, we test the existing fixtures don't have errors
193- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
193+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
194194 expect ( result . errors . length ) . toBe ( 0 ) ;
195195 } ) ;
196196 } ) ;
197197
198198 describe ( "lines array structure" , ( ) => {
199- test ( "preserves original file structure order" , ( ) => {
200- const result = parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
199+ test ( "preserves original file structure order" , async ( ) => {
200+ const result = await parseEnvFile ( join ( fixturesDir , "comments.env" ) ) ;
201201 // First line should be a comment
202202 expect ( result . lines [ 0 ] ?. type ) . toBe ( "comment" ) ;
203203 } ) ;
204204
205- test ( "variable lines include key and value" , ( ) => {
206- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
205+ test ( "variable lines include key and value" , async ( ) => {
206+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
207207 const varLine = result . lines . find ( ( l ) => l . type === "variable" ) ;
208208 expect ( varLine ?. type === "variable" && varLine . key ) . toBeDefined ( ) ;
209209 expect ( varLine ?. type === "variable" && varLine . value ) . toBeDefined ( ) ;
@@ -212,18 +212,18 @@ describe("parseEnvFile", () => {
212212} ) ;
213213
214214describe ( "validateParseResult" , ( ) => {
215- test ( "does not throw when variables exist" , ( ) => {
216- const result = parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
215+ test ( "does not throw when variables exist" , async ( ) => {
216+ const result = await parseEnvFile ( join ( fixturesDir , "valid.env" ) ) ;
217217 expect ( ( ) => validateParseResult ( result , "valid.env" ) ) . not . toThrow ( ) ;
218218 } ) ;
219219
220- test ( "throws Env2OpError when no variables found" , ( ) => {
221- const result = parseEnvFile ( join ( fixturesDir , "empty.env" ) ) ;
220+ test ( "throws Env2OpError when no variables found" , async ( ) => {
221+ const result = await parseEnvFile ( join ( fixturesDir , "empty.env" ) ) ;
222222 expect ( ( ) => validateParseResult ( result , "empty.env" ) ) . toThrow ( Env2OpError ) ;
223223 } ) ;
224224
225- test ( "throws with correct error code for empty file" , ( ) => {
226- const result = parseEnvFile ( join ( fixturesDir , "empty.env" ) ) ;
225+ test ( "throws with correct error code for empty file" , async ( ) => {
226+ const result = await parseEnvFile ( join ( fixturesDir , "empty.env" ) ) ;
227227 try {
228228 validateParseResult ( result , "empty.env" ) ;
229229 } catch ( e ) {
0 commit comments