|
1 | | -import { getEnvVariableRelaxed, setupEnv } from './env' |
| 1 | +import { getEnvVariableRelaxed, parseEnvString, parseEnvStringAlt, setupEnv } from './env' |
2 | 2 |
|
3 | 3 | describe('eNV', () => { |
4 | 4 | it('should respect both files', () => { |
@@ -28,4 +28,82 @@ describe('eNV', () => { |
28 | 28 | expect(getEnvVariableRelaxed('APROP', env)).toEqual('4') |
29 | 29 | expect(getEnvVariableRelaxed('unknown', env)).toEqual(undefined) |
30 | 30 | }) |
| 31 | + |
| 32 | + it('should parse a complex Docker .env file', () => { |
| 33 | + const envSample = ` |
| 34 | + # This is a comment |
| 35 | + VAR1=unquotedValue |
| 36 | + VAR2= "double quoted value" |
| 37 | + VAR3 = 'single quoted value' |
| 38 | + VAR4=unquotedValue # inline comment |
| 39 | + VAR5=unquotedValue#not a comment |
| 40 | + VAR6="double quoted # not a comment" |
| 41 | + VAR7="double quoted value" # comment |
| 42 | + VAR8='$OTHER' |
| 43 | + VAR9='\${OTHER}' |
| 44 | + VAR10='Let\'s go!' |
| 45 | + VAR11="{"hello": \"json\"}" |
| 46 | + VAR12="some\tvalue" |
| 47 | + VAR13='some\tvalue' |
| 48 | + VAR14=some\tvalue |
| 49 | + ` |
| 50 | + |
| 51 | + expect(envSample).toMatchInlineSnapshot(` |
| 52 | + " |
| 53 | + # This is a comment |
| 54 | + VAR1=unquotedValue |
| 55 | + VAR2= "double quoted value" |
| 56 | + VAR3 = 'single quoted value' |
| 57 | + VAR4=unquotedValue # inline comment |
| 58 | + VAR5=unquotedValue#not a comment |
| 59 | + VAR6="double quoted # not a comment" |
| 60 | + VAR7="double quoted value" # comment |
| 61 | + VAR8='$OTHER' |
| 62 | + VAR9='\${OTHER}' |
| 63 | + VAR10='Let's go!' |
| 64 | + VAR11="{"hello": "json"}" |
| 65 | + VAR12="some value" |
| 66 | + VAR13='some value' |
| 67 | + VAR14=some value |
| 68 | + " |
| 69 | + `) |
| 70 | + |
| 71 | + expect(parseEnvString(envSample)).toMatchInlineSnapshot(` |
| 72 | + Object { |
| 73 | + "VAR1": "unquotedValue", |
| 74 | + "VAR10": "Let's go!", |
| 75 | + "VAR11": "{"hello": "json"}", |
| 76 | + "VAR12": "some value", |
| 77 | + "VAR13": "some value", |
| 78 | + "VAR14": "some value", |
| 79 | + "VAR2": "double quoted value", |
| 80 | + "VAR3": "single quoted value", |
| 81 | + "VAR4": "unquotedValue # inline comment", |
| 82 | + "VAR5": "unquotedValue#not a comment", |
| 83 | + "VAR6": "double quoted # not a comment", |
| 84 | + "VAR7": ""double quoted value" # comment", |
| 85 | + "VAR8": "$OTHER", |
| 86 | + "VAR9": "\${OTHER}", |
| 87 | + } |
| 88 | + `) |
| 89 | + |
| 90 | + expect(parseEnvStringAlt(envSample)).toMatchInlineSnapshot(` |
| 91 | + Object { |
| 92 | + "VAR1": "unquotedValue", |
| 93 | + "VAR10": "Let's go!", |
| 94 | + "VAR11": "{"hello": "json"}", |
| 95 | + "VAR12": "some value", |
| 96 | + "VAR13": "some value", |
| 97 | + "VAR14": "some value", |
| 98 | + "VAR2": "double quoted value", |
| 99 | + "VAR3": "single quoted value", |
| 100 | + "VAR4": "unquotedValue", |
| 101 | + "VAR5": "unquotedValue", |
| 102 | + "VAR6": "double quoted # not a comment", |
| 103 | + "VAR7": "double quoted value", |
| 104 | + "VAR8": "$OTHER", |
| 105 | + "VAR9": "\${OTHER}", |
| 106 | + } |
| 107 | + `) |
| 108 | + }) |
31 | 109 | }) |
0 commit comments