@@ -4,6 +4,7 @@ const common = require('../common');
44const assert = require ( 'node:assert' ) ;
55const path = require ( 'node:path' ) ;
66const { describe, it } = require ( 'node:test' ) ;
7+ const { parseEnv } = require ( 'node:util' ) ;
78const fixtures = require ( '../common/fixtures' ) ;
89
910const validEnvFilePath = '../fixtures/dotenv/valid.env' ;
@@ -202,33 +203,21 @@ describe('.env supports edge cases', () => {
202203 } ) ;
203204
204205 it ( 'should handle invalid syntax in .env file' , async ( ) => {
205- const code = `
206- const resutl = util.parseEnv(
207- \`
208- foo
209-
210- bar
211- baz=whatever
212- VALID_AFTER_INVALID=test
213- multiple_invalid
214- lines_without_equals
215- ANOTHER_VALID=value
216- \`
217- );
218-
219- assert.deepStrictEqual(resutl, {
220- baz: 'whatever',
221- VALID_AFTER_INVALID: 'test',
222- ANOTHER_VALID: 'value',
223- });
224- ` . trim ( ) ;
225- const child = await common . spawnPromisified (
226- process . execPath ,
227- [ '--eval' , code ] ,
228- { cwd : fixtures . path ( 'dotenv' ) }
229- ) ;
230- assert . strictEqual ( child . stderr , '' ) ;
231- assert . strictEqual ( child . stdout , '' ) ;
232- assert . strictEqual ( child . code , 0 ) ;
206+ const resutl = parseEnv ( [
207+ 'foo' ,
208+ '' ,
209+ 'bar' ,
210+ 'baz=whatever' ,
211+ 'VALID_AFTER_INVALID=test' ,
212+ 'multiple_invalid' ,
213+ 'lines_without_equals' ,
214+ 'ANOTHER_VALID=value' ,
215+ ] . join ( '\n' ) ) ;
216+
217+ assert . deepStrictEqual ( resutl , {
218+ baz : 'whatever' ,
219+ VALID_AFTER_INVALID : 'test' ,
220+ ANOTHER_VALID : 'value' ,
221+ } ) ;
233222 } ) ;
234223} ) ;
0 commit comments