Skip to content

Commit db9989c

Browse files
committed
FI-1741 fix: separate e2ed debug and nodejs debug
fix: `testTimeout` and `testIdleTimeout` in debug mode
1 parent 870aecd commit db9989c

17 files changed

Lines changed: 77 additions & 59 deletions

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,42 +196,44 @@ The `npx e2ed-init` command is already creating such a file as an example.
196196

197197
For debugging tests, the local run of the pack is intended.
198198

199-
For example, you can use the `debug` action from `e2ed/actions` in the test code:
199+
For example, you can use the `pause` action from `e2ed/actions` in the test code:
200200

201201
```ts
202-
await debug();
202+
await pause();
203203
```
204204

205-
When calling the `debug` action, `e2ed` will stop the test execution and enter
205+
When calling the `pause` action, `e2ed` will stop the test execution and enter
206206
the debug-mode.
207207

208-
After debugging is complete, remember to remove the call of the `debug` action.
208+
After debugging is complete, remember to remove the call of the `pause` action.
209209

210-
In addition, when run pack locally tests can be debugged using the usual `nodejs` debugging flags
211-
(`--inspect-brk`, `--inspect`), as `nodejs` application (for brevity, we omit the setting of
212-
environment variables before commands):
210+
[pause](https://playwright.dev/docs/api/class-page#page-pause) is a function of the `Playwright` itself.
211+
212+
In addition, you can set any non-empty value to the `E2ED_DEBUG` environment variable,
213+
which will also run `e2ed` in debug mode. If this variable has the form `inspect-brk:9229`,
214+
then additionally `nodejs` debugging is started on port `9229` (via `--inspect-brk=9229`):
213215

214216
```sh
215-
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --inspect-brk
217+
E2ED_DEBUG=true npm run e2ed:allTests ./autotests/tests/main/exists.ts
216218
```
217219

218-
You can use the `debugger` instruction to stop execution at the desired line.
219-
220-
Or you can set any non-empty value to the `E2ED_DEBUG` environment variable,
221-
which will also run `e2ed` in `nodejs` debug mode
222-
(this is equivalentto passing the `--inspect-brk` flag):
223-
224220
```sh
225-
E2ED_DEBUG=true npm run e2ed:allTests ./autotests/tests/main/exists.ts
221+
E2ED_DEBUG=inspect-brk:8230 npm run e2ed:allTests ./autotests/tests/main/exists.ts
226222
```
227223

228224
`E2ED_DEBUG` also works for run in docker, and allows you to connect a debugger
229225
to the `e2ed` running in docker container.
230226

227+
When developing a test, you can run it in [UI-mode](https://playwright.dev/docs/test-ui-mode)
228+
by passing the `--ui` parameter (for local run only):
229+
231230
```sh
232-
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --debug-on-fail
231+
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --ui
233232
```
234233

234+
As a result, `Playwright` will launch its [UI-mode](https://playwright.dev/docs/test-ui-mode),
235+
allowing you to quickly rerun tests and see errors.
236+
235237
### Basic fields of pack config
236238

237239
The [pack](autotests/packs/allTests.ts) is a single `ts` file
@@ -334,7 +336,7 @@ For example, if it is equal to three, the test will be run no more than three ti
334336
(`navigateToPage`, `navigateToUrl` actions) in milliseconds.
335337

336338
`overriddenConfigFields: PlaywrightTestConfig | null`: if not `null`, then this value will override
337-
fields of internal Playwright config.
339+
fields of internal `Playwright` config.
338340

339341
`packTimeout: number`: timeout (in millisecond) for the entire pack of tests (tasks).
340342
If the test pack takes longer than this timeout, the pack will fail with the appropriate error.
@@ -419,9 +421,8 @@ You can pass the following optional environment variables to the `e2ed` process
419421

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

422-
`E2ED_DEBUG`: run `e2ed` in `nodejs` debug mode (`--inspect-brk=0.0.0.0`) if this variable is not empty.
423-
424-
`E2ED_DOCKER_DEBUG_PORT`: debug port when run in docker (`9229` by default).
424+
`E2ED_DEBUG`: run `e2ed` in debug mode if this variable is not empty. If this variable has the form `inspect-brk:9229`,
425+
then `nodejs` debugging is started on port `9229` (via `--inspect-brk=9229`).
425426

426427
`E2ED_TERMINATION_SIGNAL`: the termination signal received by the `e2ed` process (if any).
427428
Typically this value is `'SIGUSR1'`.

autotests/bin/runDocker.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ set -eo pipefail
33
set +u
44

55
CONTAINER_LABEL="e2ed"
6-
DEBUG_PORT="${E2ED_DOCKER_DEBUG_PORT:-9229}"
6+
DEBUG_PORT=$([[ $E2ED_DEBUG == inspect-brk:* ]] && echo "${E2ED_DEBUG#inspect-brk:}" || echo "")
77
DIR="${E2ED_WORKDIR:-$PWD}"
88
E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=16
99
MOUNTDIR="${E2ED_MOUNTDIR:-$DIR}"
10-
WITH_DEBUG=$([[ -z $E2ED_DEBUG ]] && echo "" || echo "--env E2ED_DEBUG=$DEBUG_PORT --publish $DEBUG_PORT:$DEBUG_PORT --publish $((DEBUG_PORT + 1)):$((DEBUG_PORT + 1))")
10+
WITH_DEBUG=$([[ -z $DEBUG_PORT ]] && echo "" || echo "--publish $DEBUG_PORT:$DEBUG_PORT --publish $((DEBUG_PORT + 1)):$((DEBUG_PORT + 1))")
1111
VERSION=$(grep -m1 \"e2ed\": $DIR/package.json | cut -d '"' -f 4)
1212

1313
source ./autotests/variables.env
@@ -47,6 +47,7 @@ echo "Run docker image $E2ED_DOCKER_IMAGE:$VERSION"
4747
trap "onExit" EXIT
4848

4949
docker run \
50+
--env E2ED_DEBUG=$E2ED_DEBUG \
5051
--env E2ED_ORIGIN=$E2ED_ORIGIN \
5152
--env E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=$E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS \
5253
--env __INTERNAL_E2ED_PATH_TO_PACK=$1 \

bin/dockerEntrypoint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ onExit() {
1818

1919
trap "onExit" EXIT
2020

21-
if [[ -z $E2ED_DEBUG ]]
21+
DEBUG_PORT=$([[ $E2ED_DEBUG == inspect-brk:* ]] && echo "${E2ED_DEBUG#inspect-brk:}" || echo "")
22+
23+
if [[ -z $DEBUG_PORT ]]
2224
then
2325
/node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
2426
else
25-
node --inspect-brk=0.0.0.0:$E2ED_DEBUG /node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
27+
node --inspect-brk=0.0.0.0:$DEBUG_PORT /node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
2628
fi
2729

2830
wait $PID

src/bin/localEntrypoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {fork} from 'node:child_process';
22
import {join} from 'node:path';
33

4-
import {INSTALLED_E2ED_DIRECTORY_PATH, isDebug} from '../constants/internal';
4+
import {DEBUG_PORT, INSTALLED_E2ED_DIRECTORY_PATH} from '../constants/internal';
55

66
const entrypoitFilePath = join(
77
INSTALLED_E2ED_DIRECTORY_PATH,
88
'bin',
99
'runE2edInLocalEnvironment.js',
1010
);
1111

12-
const execArgv = isDebug ? ['--inspect-brk'] : [];
12+
const execArgv = DEBUG_PORT !== undefined ? [`--inspect-brk=${DEBUG_PORT}`] : [];
1313

1414
const e2edProcess = fork(entrypoitFilePath, process.argv.slice(2), {execArgv, stdio: 'inherit'});
1515

src/config.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
e2edEnvironment,
1313
EXPECTED_SCREENSHOTS_DIRECTORY_PATH,
1414
INTERNAL_REPORTS_DIRECTORY_PATH,
15-
isDebug,
15+
IS_DEBUG,
16+
MAX_TIMEOUT_IN_MS,
1617
PATH_TO_TEST_FILE_VARIABLE_NAME,
1718
TESTS_DIRECTORY_PATH,
1819
} from './constants/internal';
@@ -29,8 +30,6 @@ import type {FullPackConfig, Mutable, UserlandPack} from './types/internal';
2930

3031
import {defineConfig, type PlaywrightTestConfig} from '@playwright/test';
3132

32-
const maxTimeoutInMs = 3600_000;
33-
3433
const pathToPack = getPathToPack();
3534
const relativePathFromInstalledE2edToRoot = relative(
3635
ABSOLUTE_PATH_TO_INSTALLED_E2ED_DIRECTORY,
@@ -87,10 +86,10 @@ setCustomInspectOnFunction(mapLogPayloadInConsole);
8786
setCustomInspectOnFunction(mapLogPayloadInLogFile);
8887
setCustomInspectOnFunction(mapLogPayloadInReport);
8988

90-
if (isDebug || isUiMode) {
91-
setReadonlyProperty(userlandPack, 'packTimeout', maxTimeoutInMs);
92-
setReadonlyProperty(userlandPack, 'testIdleTimeout', maxTimeoutInMs);
93-
setReadonlyProperty(userlandPack, 'testTimeout', maxTimeoutInMs);
89+
if (IS_DEBUG || isUiMode) {
90+
setReadonlyProperty(userlandPack, 'packTimeout', MAX_TIMEOUT_IN_MS);
91+
setReadonlyProperty(userlandPack, 'testIdleTimeout', MAX_TIMEOUT_IN_MS);
92+
setReadonlyProperty(userlandPack, 'testTimeout', MAX_TIMEOUT_IN_MS);
9493
}
9594

9695
const useOptions: PlaywrightTestConfig['use'] = {

src/constants/debug.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Maximum timeout in milliseconds for debug mode (24 hours).
3+
* In debug mode, all timers are set to this value.
4+
* @internal
5+
*/
6+
export const MAX_TIMEOUT_IN_MS = 86_400_000;

src/constants/environment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import type {E2edEnvironment} from '../types/internal';
66
*/
77
export const e2edEnvironment = process.env as E2edEnvironment;
88

9+
/**
10+
* Debug port (for `--inspect-brk`) or `undefined`.
11+
*/
12+
export const DEBUG_PORT: number | undefined = e2edEnvironment.E2ED_DEBUG?.startsWith('inspect-brk:')
13+
? Number(e2edEnvironment.E2ED_DEBUG.slice('inspect-brk:'.length)) || undefined
14+
: undefined;
15+
916
/**
1017
* `true` if e2ed run in debug mode, and `false` otherwise.
1118
*/
12-
export const isDebug: boolean = Boolean(e2edEnvironment.E2ED_DEBUG);
19+
export const IS_DEBUG: boolean = Boolean(e2edEnvironment.E2ED_DEBUG);
1320

1421
/**
1522
* Name of e2ed environment variable with path to pack.

src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export {EndE2edReason, ExitCode} from './end';
2-
export {isDebug} from './environment';
2+
export {DEBUG_PORT, IS_DEBUG} from './environment';
33
export {READ_FILE_OPTIONS} from './fs';
44
export {
55
BAD_REQUEST_STATUS_CODE,

src/constants/internal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ export {attributesOptions} from './attributesOptions';
44
export {EXEC_FILE_OPTIONS} from './childProcess';
55
/** @internal */
66
export {ConsoleBackgroundColor} from './color';
7+
/** @internal */
8+
export {MAX_TIMEOUT_IN_MS} from './debug';
79
export {EndE2edReason, ExitCode} from './end';
8-
export {isDebug, RunEnvironment} from './environment';
10+
export {DEBUG_PORT, IS_DEBUG, RunEnvironment} from './environment';
911
/** @internal */
1012
export {
1113
e2edEnvironment,

src/generators/createRunId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {getHash} from '../utils/getHash';
33
import type {RunId, Test} from '../types/internal';
44

55
/**
6-
* Creates new RunId for TestRun.
6+
* Creates new `RunId` for TestRun.
77
* @internal
88
*/
99
export const createRunId = (test: Test, retryIndex: number): RunId => {

0 commit comments

Comments
 (0)