Skip to content

Commit

Permalink
feat: add dockerImage field to e2ed config; remove E2ED_DOCKER_IMAGE
Browse files Browse the repository at this point in the history
refactor: renamt exit status to exit code
  • Loading branch information
uid11 committed Sep 2, 2022
1 parent 8fe5d0a commit bf76590
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ with the command `npm run lint`.

You can check that your changes doesn't break core functionality in runtime by building the project
(`npm run build`) and running local tests (`npm run test:local`).
The tests should complete without error, i.e. with an exit status of 0.
The tests should complete without error, i.e. with an exit code 0.

If you have [Docker](https://www.docker.com/) installed, you can also run tests in docker
(`npm run test:docker`) to make sure they also complete without errors.
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

E2E testing framework over [TestCafe](https://testcafe.io/).

`e2ed` is designed to quickly parallel run a large number of independent atomic tests
(or other scenarios) In an arbitrary browser inside a docker container.
Tests are written in TypeScript, using explicit dependencies and the concept of page objects.
After the run, a detailed html report and a summary in JSON format is generated.

## Install

Requires [node](https://nodejs.org/en/) version 16 or higher:
Expand All @@ -37,7 +42,15 @@ Then run tests locally for `https://google.com`:
E2ED_ORIGIN=https://google.com npx e2ed
```

And run tests for `https://google.com` in docker:
### Docker

You can download the latest `e2ed` docker image from https://hub.docker.com/r/e2edhub/e2ed:

```sh
docker pull e2edhub/e2ed
```

And run tests for `https://google.com` in docker container:

```sh
E2ED_ORIGIN=https://google.com ./e2ed/bin/runDocker.sh
Expand Down Expand Up @@ -102,9 +115,6 @@ This parameter can be overridden in the test-specific options.

`E2ED_DOCKER_DO_BEFORE_TESTS`: the name of the executable file from the `e2ed/bin` directory that will be run (into container) before running the tests.

`E2ED_DOCKER_IMAGE`: the name of the docker image used to run tests with the `your-project/e2ed/bin/runDocker.sh` command
(`e2ed` by default).

## License

[MIT][license-url]
Expand Down
6 changes: 6 additions & 0 deletions bin/addPackageJsonToBuildDocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -eu

VERSION=`./bin/getVersion.sh`

echo "{\n \"dependencies\": {\n \"e2ed\": \"$VERSION\"\n }\n}" > ./build/docker/package.json
6 changes: 6 additions & 0 deletions bin/buildDocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -eu

VERSION=`./bin/getVersion.sh`

docker build --tag e2edhub/e2ed:$VERSION .
4 changes: 2 additions & 2 deletions bin/dockerEntrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ else
node --inspect-brk=0.0.0.0 ./node_modules/e2ed/bin/runE2edInDockerEnvironment.js
fi

EXIT_STATUS=$?
EXIT_CODE=$?

if [ -z $E2ED_DOCKER_DO_AFTER_TESTS ]
then
Expand All @@ -36,4 +36,4 @@ else
./e2ed/bin/$E2ED_DOCKER_DO_AFTER_TESTS
fi

exit $EXIT_STATUS
exit $EXIT_CODE
2 changes: 1 addition & 1 deletion bin/getVersion.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
set -eu

grep -m1 version package.json | cut -d '"' -f 4
grep -m1 version ./package.json | cut -d '"' -f 4
12 changes: 6 additions & 6 deletions e2ed/bin/runDocker.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env sh
set -e

DIR="${WORKDIR:-$PWD}"
MOUNTDIR="${MOUNTDIR:-$DIR}"
DOCKER_IMAGE="${E2ED_DOCKER_IMAGE:-e2ed}"
DEBUG_PORT="${E2ED_DOCKER_DEBUG_PORT:-9229}"
DIR="${E2ED_WORKDIR:-$PWD}"
DOCKER_IMAGE=$(grep -m1 dockerImage ./e2ed/config.ts | sed -e "s/^[^'\"\`]*['\"\`]//" -e "s/['\"\`][^'\"\`]*$//")
MOUNTDIR="${E2ED_MOUNTDIR:-$DIR}"
VERSION=$(grep -m1 \"e2ed\": ./package.json | cut -d '"' -f 4)

if [ -z $E2ED_DEBUG ]
then
PORT=""
else
PORT="-p $DEBUG_PORT:$DEBUG_PORT"
PORT="--publish $DEBUG_PORT:$DEBUG_PORT"
fi

docker run --rm $PORT \
Expand All @@ -20,5 +21,4 @@ docker run --rm $PORT \
--env E2ED_DEBUG=$E2ED_DEBUG \
--env E2ED_DOCKER_DO_AFTER_TESTS=$E2ED_DOCKER_DO_AFTER_TESTS \
--env E2ED_DOCKER_DO_BEFORE_TESTS=$E2ED_DOCKER_DO_BEFORE_TESTS \
--env E2ED_DOCKER_IMAGE=$E2ED_DOCKER_IMAGE \
$DOCKER_IMAGE
$DOCKER_IMAGE:$VERSION
1 change: 1 addition & 0 deletions e2ed/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const config: Config = {
browserInitTimeout: 30_000,
browsers: 'chromium:headless --no-sandbox --disable-dev-shm-usage --disable-web-security',
concurrency: isLocalRun ? 1 : 2,
dockerImage: 'e2edhub/e2ed',
liteReportFileName: 'lite-report.json',
maxRetriesCountInDocker: 3,
packTimeout: 90 * 60_000,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@
"prerelease": "npm run build",
"release": "npm publish ./build/node_modules/e2ed",
"postrelease": "if [ -f ./local/postrelease.sh ]; then ./local/postrelease.sh; else echo 'No postrelease hook'; fi",
"build:docker": "docker build -t e2ed .",
"build:docker": "./bin/buildDocker.sh",
"pretest:docker": "npm run build:docker && npm run test:docker:copy",
"test:docker:copy": "rm -rf ./build/docker && mkdir build/docker && cp -r ./build/e2ed ./build/docker/e2ed",
"test:docker": "(cd ./build/docker && E2ED_DOCKER_DO_AFTER_TESTS=doAfterTests.sh E2ED_DOCKER_DO_BEFORE_TESTS=doBeforeTests.sh E2ED_CONCURRENCY=2 E2ED_DOCKER_RETRIES=3 E2ED_ORIGIN=https://google.com ./e2ed/bin/runDocker.sh)",
"posttest:docker:copy": "./bin/addPackageJsonToBuildDocker.sh",
"test:docker": "(cd ./build/docker && E2ED_DOCKER_DO_AFTER_TESTS=doAfterTests.sh E2ED_DOCKER_DO_BEFORE_TESTS=doBeforeTests.sh E2ED_ORIGIN=https://google.com ./e2ed/bin/runDocker.sh)",
"test:esm": "node ./build/testEsmExports.mjs",
"test:local": "(cd ./build && E2ED_ORIGIN=https://google.com ./node_modules/e2ed/bin/localEntrypoint.js)",
"testcafefork:publish": "./bin/TestCafeFork/publish.sh",
Expand Down
4 changes: 2 additions & 2 deletions src/package/constants/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const enum EndE2edReason {
}

/**
* Exit status of e2ed process.
* Exit code of e2ed process.
*/
export const enum ExitStatus {
export const enum ExitCode {
Passed = 0,
Failed = 1,
NoRetries = 2,
Expand Down
1 change: 1 addition & 0 deletions src/package/constants/testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const enum TestRunStatus {
Failed = 'failed',
Skipped = 'skipped',
Broken = 'broken',
Manual = 'manual',
Unknown = 'unknown',
}

Expand Down
1 change: 1 addition & 0 deletions src/package/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {DeepReadonly} from './deep';
* Own e2ed config properties.
*/
type OwnE2edConfig = Readonly<{
dockerImage: string;
maxRetriesCountInDocker: number;
liteReportFileName: string | null;
packTimeout: number;
Expand Down
6 changes: 3 additions & 3 deletions src/package/types/report.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {EndE2edReason, ExitStatus, TestRunStatus} from '../constants/internal';
import type {EndE2edReason, ExitCode, TestRunStatus} from '../constants/internal';

import type {UtcTimeInMs} from './date';
import type {TestFilePath} from './fs';
Expand All @@ -13,7 +13,7 @@ export type ReportData = Readonly<{
endE2edReason: EndE2edReason;
endTimeInMs: UtcTimeInMs;
errors: readonly string[];
exitStatus: ExitStatus;
exitCode: ExitCode;
fullTestRuns: readonly FullTestRun[];
liteReportFileName: string | null;
reportFileName: string | null;
Expand All @@ -28,7 +28,7 @@ export type LiteReport = Readonly<{
endE2edReason: EndE2edReason;
endTimeInMs: UtcTimeInMs;
errors: readonly string[];
exitStatus: ExitStatus;
exitCode: ExitCode;
liteReportFileName: string;
retries: readonly LiteRetry[];
startInfo: StartInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/package/utils/events/registerEndE2edRunEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export const registerEndE2edRunEvent = async (): Promise<void> => {
{error},
);
} finally {
processExit(reportData?.exitStatus);
processExit(reportData?.exitCode);
}
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {ExitStatus, FAILED_TEST_RUN_STATUSES} from '../../constants/internal';
import {ExitCode, FAILED_TEST_RUN_STATUSES} from '../../constants/internal';

import {assertValueIsDefined} from '../asserts';

import type {Retry} from '../../types/internal';

/**
* Get e2ed exit status (from complete report data).
* Get e2ed exit code (from complete report data).
* @internal
*/
export const getExitStatus = (retries: readonly Retry[]): ExitStatus => {
export const getExitCode = (retries: readonly Retry[]): ExitCode => {
if (retries.length === 0) {
return ExitStatus.NoRetries;
return ExitCode.NoRetries;
}

const lastRetry = retries[retries.length - 1];
Expand All @@ -21,8 +21,8 @@ export const getExitStatus = (retries: readonly Retry[]): ExitStatus => {
const hasFailedTests = fullTestRuns.some(({status}) => FAILED_TEST_RUN_STATUSES.includes(status));

if (hasFailedTests) {
return ExitStatus.Failed;
return ExitCode.Failed;
}

return ExitStatus.Passed;
return ExitCode.Passed;
};
2 changes: 1 addition & 1 deletion src/package/utils/exit/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './getExitStatus';
export * from './getExitCode';
export * from './processExit';
10 changes: 5 additions & 5 deletions src/package/utils/exit/processExit.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ExitStatus} from '../../constants/internal';
import {ExitCode} from '../../constants/internal';

import {generalLog} from '../generalLog';

/**
* Exit from e2ed process with correct exit status.
* Exit from e2ed process with correct exit code.
* @internal
*/
export const processExit = (exitStatus: ExitStatus = ExitStatus.NoReportData): void => {
generalLog(`Exit from e2ed with status ${exitStatus}`);
export const processExit = (exitCode: ExitCode = ExitCode.NoReportData): void => {
generalLog(`Exit from e2ed with code ${exitCode}`);

process.exit(exitStatus);
process.exit(exitCode);
};
6 changes: 3 additions & 3 deletions src/package/utils/report/collectReportData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getExitStatus} from '../exit';
import {getExitCode} from '../exit';
import {getFullConfig} from '../getFullConfig';

import {assertThatTestNamesAndFilePathsAreUnique} from './assertThatTestNamesAndFilePathsAreUnique';
Expand Down Expand Up @@ -27,13 +27,13 @@ export const collectReportData = async ({
unificateRunHashes(fullTestRuns);

const retries = getRetries(fullTestRuns);
const exitStatus = getExitStatus(retries);
const exitCode = getExitCode(retries);

return {
endE2edReason,
endTimeInMs,
errors,
exitStatus,
exitCode,
fullTestRuns,
liteReportFileName,
reportFileName,
Expand Down
4 changes: 2 additions & 2 deletions src/package/utils/report/getLiteReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {LiteReport, ReportData} from '../../types/internal';
* @internal
*/
export const getLiteReport = (reportData: ReportData): LiteReport => {
const {endE2edReason, endTimeInMs, errors, exitStatus, liteReportFileName, retries, startInfo} =
const {endE2edReason, endTimeInMs, errors, exitCode, liteReportFileName, retries, startInfo} =
reportData;

assertValueIsNotNull(liteReportFileName, 'liteReportFileName is not null');
Expand All @@ -20,7 +20,7 @@ export const getLiteReport = (reportData: ReportData): LiteReport => {
endE2edReason,
endTimeInMs,
errors,
exitStatus,
exitCode,
liteReportFileName,
retries: liteRetries,
startInfo,
Expand Down

0 comments on commit bf76590

Please sign in to comment.