-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FI-1136 fix: use
E2ED_DOCKER_IMAGE
instead of dockerImage
pack op…
…tion feat: support dotenv file `./autotests/.env` fix: use `E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT` environment variables
- Loading branch information
Showing
22 changed files
with
258 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
trailingComma: all | ||
arrowParens: always | ||
singleQuote: true | ||
bracketSpacing: false | ||
jsxSingleQuote: false | ||
overrides: | ||
- {files: ./tsconfig.json, options: {parser: json}} | ||
printWidth: 100 | ||
bracketSpacing: false | ||
singleQuote: true | ||
trailingComma: all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This required file in standard dotenv format defines the environment variables | ||
# with which all packs will be run. | ||
# {@link https://www.npmjs.com/package/dotenv} | ||
|
||
# Required variable: the name of the docker image where the tests will run. | ||
E2ED_DOCKER_IMAGE='e2edhub/e2ed' | ||
|
||
# Required variable: the path to TypeScript config file of the project | ||
# from the root directory of the project. | ||
E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT='./tsconfig.json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {readFile} from 'node:fs/promises'; | ||
|
||
import {DOT_ENV_PATH, READ_FILE_OPTIONS} from '../../constants/internal'; | ||
|
||
import {E2edError} from '../error'; | ||
|
||
/** | ||
* Get object with values from `.env` file in directory with autotests. | ||
* {@link https://www.npmjs.com/package/dotenv} | ||
* @internal | ||
*/ | ||
export const getDotEnvValuesObject = async (): Promise<Readonly<Record<string, string>>> => { | ||
const dotEnvText = await readFile(DOT_ENV_PATH, READ_FILE_OPTIONS); | ||
|
||
const lines = dotEnvText.split('\n'); | ||
const result = Object.create(null) as Record<string, string>; | ||
|
||
for (const line of lines) { | ||
const trimmedLine = line.trim(); | ||
|
||
if (line === '' || line[0] === '#') { | ||
continue; | ||
} | ||
|
||
const indexOfEqualSign = trimmedLine.indexOf('='); | ||
|
||
if (indexOfEqualSign < 1) { | ||
throw new E2edError('Incorrect name of environment variable in `.env`', {line}); | ||
} | ||
|
||
const name = trimmedLine.slice(0, indexOfEqualSign).trim(); | ||
|
||
if (name in result) { | ||
throw new E2edError(`Duplicate name "${name}" in \`.env\` file`, { | ||
firstValue: result[name], | ||
line, | ||
}); | ||
} | ||
|
||
const valueMaybeWithQuotes = trimmedLine.slice(indexOfEqualSign + 1).trim(); | ||
const firstCharacter = valueMaybeWithQuotes[0]; | ||
const isQuoted = | ||
firstCharacter === valueMaybeWithQuotes.at(-1) && | ||
(firstCharacter === '"' || firstCharacter === "'" || firstCharacter === '`'); | ||
|
||
const value = isQuoted ? valueMaybeWithQuotes.slice(1, -1) : valueMaybeWithQuotes; | ||
|
||
result[name] = value; | ||
} | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {e2edEnvironment} from '../../constants/internal'; | ||
|
||
import {E2edError} from '../error'; | ||
|
||
import {getDotEnvValuesObject} from './getDotEnvValuesObject'; | ||
|
||
/** | ||
* Set values from `.env` file in directory with autotests to environment (to `process.env`). | ||
* @internal | ||
*/ | ||
export const setDotEnvValuesToEnvironment = async (): Promise<void> => { | ||
// eslint-disable-next-line @typescript-eslint/unbound-method | ||
const {hasOwnProperty} = Object.prototype; | ||
const values = await getDotEnvValuesObject(); | ||
|
||
for (const [name, value] of Object.entries(values)) { | ||
if (hasOwnProperty.call(e2edEnvironment, name) && e2edEnvironment[name] !== value) { | ||
throw new E2edError( | ||
`Environment variable "${name}" from \`.env\` already defined in \`process.env\` with other value`, | ||
{ | ||
valueFromDotEnv: value, | ||
valueFromProccessEnv: e2edEnvironment[name], | ||
}, | ||
); | ||
} | ||
|
||
e2edEnvironment[name] = value; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.