Skip to content

Commit

Permalink
Merge pull request #547 from snyk/feat/upgrade-dotenv
Browse files Browse the repository at this point in the history
feat: upgrade dotenv to v16.0.3
  • Loading branch information
pavel-snyk authored May 12, 2023
2 parents 8483afe + 0e67e1a commit 553b1b7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"bunyan": "^1.8.12",
"camelcase": "^5.3.1",
"clarify": "^2.0.0",
"dotenv": "^6.2.0",
"dotenv": "^16.0.3",
"ejson": "^2.2.0",
"engine.io": "^6.2.1",
"engine.io-client": "^5.2.0",
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/config/.env-multiline
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VALUE_MULTILINE_DOUBLE_QUOTES="value
multiline
double
quotes"

VALUE_MULTILINE_SINGLE_QUOTES='value
multiline
single
quotes'

4 changes: 4 additions & 0 deletions test/fixtures/config/.env-singleline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BROKER_TOKEN=broker token
BROKER_TOKEN_DOUBLE_QUOTES="broker token double quotes"
BROKER_TOKEN_SINGLE_QUOTES='broker token single quotes'
#BROKER_TOKEN_COMMENTED=broker token commented
4 changes: 4 additions & 0 deletions test/helpers/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class Fixtures {
});
}

static getPathToFixtures(directory: string): string {
return path.resolve(DEFAULT_FIXTURES_ROOT, directory);
}

static getPathToClientFixtures(): string {
return path.resolve(DEFAULT_FIXTURES_ROOT, 'client');
}
Expand Down
37 changes: 37 additions & 0 deletions test/unit/dotenv-parse.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const dotenv = require('dotenv');
import { Fixtures } from '../helpers/fixtures';

const envSingleLine = Fixtures.get(
'.env-singleline',
Fixtures.getPathToFixtures('config'),
);
const envMultiLine = Fixtures.get(
'.env-multiline',
Fixtures.getPathToFixtures('config'),
);

describe('dotenv', () => {
it('should correctly parse env file with singleline values', async () => {
const parsedConfig = dotenv.parse(envSingleLine);

expect(parsedConfig.BROKER_TOKEN).toEqual('broker token');
expect(parsedConfig.BROKER_TOKEN_DOUBLE_QUOTES).toEqual(
'broker token double quotes',
);
expect(parsedConfig.BROKER_TOKEN_SINGLE_QUOTES).toEqual(
'broker token single quotes',
);
expect(parsedConfig.BROKER_TOKEN_COMMENTED).toBeFalsy();
});

it('should correctly parse env file with multiline values', async () => {
const parsedConfig = dotenv.parse(envMultiLine);

expect(parsedConfig.VALUE_MULTILINE_DOUBLE_QUOTES).toEqual(
'value\nmultiline\ndouble\nquotes',
);
expect(parsedConfig.VALUE_MULTILINE_SINGLE_QUOTES).toEqual(
'value\nmultiline\nsingle\nquotes',
);
});
});

0 comments on commit 553b1b7

Please sign in to comment.