Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,42 +196,44 @@ The `npx e2ed-init` command is already creating such a file as an example.

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

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

```ts
await debug();
await pause();
```

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

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

In addition, when run pack locally tests can be debugged using the usual `nodejs` debugging flags
(`--inspect-brk`, `--inspect`), as `nodejs` application (for brevity, we omit the setting of
environment variables before commands):
[pause](https://playwright.dev/docs/api/class-page#page-pause) is a function of the `Playwright` itself.

In addition, you can set any non-empty value to the `E2ED_DEBUG` environment variable,
which will also run `e2ed` in debug mode. If this variable has the form `inspect-brk:9229`,
then additionally `nodejs` debugging is started on port `9229` (via `--inspect-brk=9229`):

```sh
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --inspect-brk
E2ED_DEBUG=true npm run e2ed:allTests ./autotests/tests/main/exists.ts
```

You can use the `debugger` instruction to stop execution at the desired line.

Or you can set any non-empty value to the `E2ED_DEBUG` environment variable,
which will also run `e2ed` in `nodejs` debug mode
(this is equivalentto passing the `--inspect-brk` flag):

```sh
E2ED_DEBUG=true npm run e2ed:allTests ./autotests/tests/main/exists.ts
E2ED_DEBUG=inspect-brk:8230 npm run e2ed:allTests ./autotests/tests/main/exists.ts
```

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

When developing a test, you can run it in [UI-mode](https://playwright.dev/docs/test-ui-mode)
by passing the `--ui` parameter (for local run only):

```sh
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --debug-on-fail
npm run e2ed:allTests ./autotests/tests/main/exists.ts -- --ui
```

As a result, `Playwright` will launch its [UI-mode](https://playwright.dev/docs/test-ui-mode),
allowing you to quickly rerun tests and see errors.

### Basic fields of pack config

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

`overriddenConfigFields: PlaywrightTestConfig | null`: if not `null`, then this value will override
fields of internal Playwright config.
fields of internal `Playwright` config.

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

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

`E2ED_DEBUG`: run `e2ed` in `nodejs` debug mode (`--inspect-brk=0.0.0.0`) if this variable is not empty.

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

`E2ED_TERMINATION_SIGNAL`: the termination signal received by the `e2ed` process (if any).
Typically this value is `'SIGUSR1'`.
Expand Down
5 changes: 3 additions & 2 deletions autotests/bin/runDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set -eo pipefail
set +u

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

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

docker run \
--env E2ED_DEBUG=$E2ED_DEBUG \
--env E2ED_ORIGIN=$E2ED_ORIGIN \
--env E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=$E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS \
--env __INTERNAL_E2ED_PATH_TO_PACK=$1 \
Expand Down
6 changes: 6 additions & 0 deletions autotests/tests/internalTypeTests/expect.skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ void expect(htmlElementSelector.textContent, '').toMatchScreenshot('some id');

// @ts-expect-error: eql is acceptable only for non-selectors
void expect(htmlElementSelector, '').eql(htmlElementSelector);

// ok
void (expect('foo', 'foo is correct').toBe('foo') satisfies Promise<void>);

// ok
void (expect('foo', 'foo is correct').toBeDefined() satisfies Promise<void>);
6 changes: 4 additions & 2 deletions bin/dockerEntrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ onExit() {

trap "onExit" EXIT

if [[ -z $E2ED_DEBUG ]]
DEBUG_PORT=$([[ $E2ED_DEBUG == inspect-brk:* ]] && echo "${E2ED_DEBUG#inspect-brk:}" || echo "")

if [[ -z $DEBUG_PORT ]]
then
/node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
else
node --inspect-brk=0.0.0.0:$E2ED_DEBUG /node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
node --inspect-brk=0.0.0.0:$DEBUG_PORT /node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
fi

wait $PID
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
"url": "git+https://github.com/joomcode/e2ed.git"
},
"dependencies": {
"@playwright/test": "1.51.0",
"@playwright/test": "1.51.1",
"create-locator": "0.0.27",
"get-modules-graph": "0.0.11",
"globby": "11.1.0",
"sort-json-keys": "1.0.3"
},
"devDependencies": {
"@playwright/browser-chromium": "1.51.0",
"@types/node": "22.13.10",
"@playwright/browser-chromium": "1.51.1",
"@types/node": "22.14.0",
"@typescript-eslint/eslint-plugin": "7.18.0",
"@typescript-eslint/parser": "7.18.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
Expand All @@ -46,7 +46,7 @@
"eslint-plugin-typescript-sort-keys": "3.3.0",
"husky": "9.1.7",
"prettier": "3.5.3",
"typescript": "5.8.2"
"typescript": "5.8.3"
},
"peerDependencies": {
"@types/node": ">=20",
Expand Down
27 changes: 14 additions & 13 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ Modules in the dependency graph should only import the modules above them:
32. `utils/promise`
33. `utils/resourceUsage`
34. `utils/fs`
35. `utils/tests`
36. `utils/end`
37. `utils/pack`
38. `useContext`
39. `context`
40. `utils/apiStatistics`
41. `utils/selectors`
42. `selectors`
43. `utils/log`
44. `utils/waitForEvents`
45. `utils/expect`
46. `expect`
47. ...
35. `utils/getGlobalErrorHandler`
36. `utils/tests`
37. `utils/end`
38. `utils/pack`
39. `useContext`
40. `context`
41. `utils/apiStatistics`
42. `utils/selectors`
43. `selectors`
44. `utils/log`
45. `utils/waitForEvents`
46. `utils/expect`
47. `expect`
48. ...
7 changes: 4 additions & 3 deletions src/actions/waitFor/waitForNewTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import type {InternalTab, Tab, Trigger, UtcTimeInMs} from '../../types/internal'

type Options = Readonly<{skipLogs?: boolean; timeout?: number}>;

type WaitForNewTab = ((trigger: Trigger, options?: Options) => Promise<Tab>) &
type WaitForNewTab = ((trigger: Trigger | undefined, options?: Options) => Promise<Tab>) &
((options?: Options) => Promise<Tab>);

/**
* Waits for opening of new tab and returns this tab.
*/
export const waitForNewTab = (async (
triggerOrOptions?: Options | Trigger,
triggerOrOptions?: Options | Trigger | undefined,
options?: Options,
): Promise<Tab> => {
const startTimeInMs = Date.now() as UtcTimeInMs;

const context = getPlaywrightPage().context();
const trigger = typeof triggerOrOptions === 'function' ? triggerOrOptions : undefined;
const finalOptions = typeof triggerOrOptions === 'function' ? options : triggerOrOptions;
const finalOptions =
typeof triggerOrOptions === 'function' ? options : (triggerOrOptions ?? options);

const timeout = finalOptions?.timeout ?? getFullPackConfig().navigationTimeout;
const timeoutWithUnits = getDurationWithUnits(timeout);
Expand Down
Loading