Skip to content

Commit 1da8367

Browse files
committed
feat: add project setting in JSON instead of variable.env
1 parent 9762159 commit 1da8367

28 files changed

Lines changed: 144 additions & 152 deletions

‎README.md‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,25 @@ If the wait is longer than this timeout, then the promise returned by the `waitF
412412
`waitForResponseTimeout: number`: default timeout (in milliseconds) for `waitForResponse`/`waitForResponseToRoute` functions.
413413
If the wait is longer than this timeout, then the promise returned by the `waitForResponse`/`waitForResponseToRoute` function will be rejected.
414414

415-
### Environment variables
415+
### Project settings
416+
417+
General static project settings are stored in file `./autotests/projectSettings.json`. They apply to all project packs.
416418

417-
Required environment variables are defined in the `./autotests/variables.env` file (they cannot be deleted):
419+
`allTestFileGlobs: string`: an array of globs covering all project test files across all packs
420+
(used to generate a code report).
418421

419-
`E2ED_DOCKER_IMAGE`: the name of the docker image where the tests will run.
422+
`dockerImage: string | null`: the name of the docker image where the tests will run.
420423
The image must be based on the `e2ed` base image.
421424

422-
`E2ED_PATH_TO_TS_CONFIG_OF_PROJECT_FROM_ROOT`: the path to TypeScript config file of the project
425+
`pathToTsConfigFromRoot: string`: the path to TypeScript config file of the project
423426
from the root directory of the project. The project should have one common TypeScript config
424427
for both the application code and the autotest code.
425428

429+
`testIdentifierKey: Record<string, string>`: an object with a single field that serves as the test identifier key in the test `meta`.
430+
If the project does not use such a key, leave the object empty.
431+
432+
### Environment variables
433+
426434
You can pass the following optional environment variables to the `e2ed` process in any standard way:
427435

428436
`E2ED_ORIGIN`: origin-part of the url (`protocol` + `host`) on which the tests will be run. For example, `https://bing.com`.

‎autotests/bin/runDocker.sh‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ set +u
55
CONTAINER_LABEL="e2ed"
66
DEBUG_PORT=$([[ $E2ED_DEBUG == inspect-brk:* ]] && echo "${E2ED_DEBUG#inspect-brk:}" || echo "")
77
DIR="${E2ED_WORKDIR:-$PWD}"
8+
E2ED_DOCKER_IMAGE=$(grep -m1 \"dockerImage\": $DIR/autotests/projectSettings.json | cut -d '"' -f 4)
89
E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=16
910
MOUNTDIR="${E2ED_MOUNTDIR:-$DIR}"
1011
WITH_DEBUG=$([[ -z $DEBUG_PORT ]] && echo "" || echo "--publish $DEBUG_PORT:$DEBUG_PORT --publish $((DEBUG_PORT + 1)):$((DEBUG_PORT + 1))")
1112
VERSION=$(grep -m1 \"e2ed\": $DIR/package.json | cut -d '"' -f 4)
1213

13-
source ./autotests/variables.env
14-
1514
if [[ -z $E2ED_DOCKER_IMAGE ]]
1615
then
17-
echo "Error: The \"autotests/variables.env\" file does not contain E2ED_DOCKER_IMAGE variable."
16+
echo "Error: The \"autotests/projectSettings.json\" file does not contain dockerImage variable."
1817
echo "Add it so that \"runDocker.sh\" script can run the docker image."
1918
echo "Exit with code 9"
2019
exit 9

‎autotests/configurator/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export {mapLogPayloadInReport} from './mapLogPayloadInReport';
99
export {matchScreenshot} from './matchScreenshot';
1010
export {regroupSteps} from './regroupSteps';
1111
export {skipTests} from './skipTests';
12+
export {testIdentifierKey} from './testIdentifierKey';
1213
export type {
1314
DoAfterPack,
1415
DoBeforePack,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {getTestIdentifierKey} from 'e2ed/configurator';
2+
3+
import projectSettings from '../projectSettings.json';
4+
5+
import type {GetTestIdentifierKey} from 'e2ed/types';
6+
7+
/**
8+
* Project test identifier key in test meta.
9+
*/
10+
export const testIdentifierKey: GetTestIdentifierKey<typeof projectSettings> =
11+
getTestIdentifierKey(projectSettings);

‎autotests/projectSettings.json‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"allTestFileGlobs": ["**/autotests/tests/**/*.ts"],
3+
"dockerImage": "e2edhub/e2ed",
4+
"pathToTsConfigFromRoot": "./tsconfig.json",
5+
"testIdentifierKey": {"testId": "key of the test identifier in test meta"}
6+
}

‎autotests/types/packsTypeChecks.ts‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎autotests/types/typeChecks.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type {Pack, testIdentifierKey} from 'autotests/configurator';
2+
import type {pack as allTestsPack} from 'autotests/packs/allTests';
3+
import type {Expect, IsEqual, IsUnion, Not} from 'e2ed/types';
4+
5+
/**
6+
* Type checks of all project packs and test identifier key.
7+
*/
8+
export type TypeChecks = [
9+
Expect<IsEqual<Pack, typeof allTestsPack>>,
10+
Expect<Not<IsUnion<typeof testIdentifierKey>>>,
11+
];

‎autotests/variables.env‎

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type {GetTestIdentifierKey, ProjectSettings} from '../types/internal';
2+
3+
/**
4+
* Get test identifier key from project settings.
5+
*/
6+
export const getTestIdentifierKey = <const Settings extends ProjectSettings>(
7+
projectSettings: Settings,
8+
): GetTestIdentifierKey<Settings> =>
9+
Object.keys(projectSettings.testIdentifierKey)[0] as GetTestIdentifierKey<Settings>;

‎src/configurator/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type {UserlandPack as PackConfig} from '../types/internal';
22
export {getDurationWithUnits} from '../utils/getDurationWithUnits';
33
export {getShallowCopyOfObjectForLogs, getStringTrimmedToMaxLength} from '../utils/valueToString';
44
export {RunEnvironment, startTimeInMs} from './constants';
5+
export {getTestIdentifierKey} from './getTestIdentifierKey';
56
export {replaceFields} from './replaceFields';
67
export {isDockerRun, isLocalRun, runEnvironment} from './runEnvironment';
78
/** @internal */

0 commit comments

Comments
 (0)