Skip to content

Commit

Permalink
FI-1616 fix: restore debug of main nodejs process by E2ED_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
uid11 committed Jan 22, 2025
1 parent 4b42ca3 commit d34234f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ After the run, a detailed HTML report and a summary lite report in JSON format a

## Adding e2ed to a project

Prerequisites: [node](https://nodejs.org/en/) >=16,
[TypeScript](https://www.typescriptlang.org/) >=4.8.
Prerequisites: [node](https://nodejs.org/en/) >=20,
[TypeScript](https://www.typescriptlang.org/) >=5.

All commands below are run from the root directory of the project.

Expand Down
2 changes: 1 addition & 1 deletion autotests/packs/allTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const browserFlags = [
const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.testId !== '13';

const userAgent =
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.35 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.35';
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36';

const msInMinute = 60_000;
const packTimeoutInMinutes = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ export class E2edReportExample extends Page<CustomPageParams> {

return setPageCookiesAndNavigateToUrl(url, this.pageCookies);
}

override async waitForPageLoaded(): Promise<void> {
await this.waitForDomContentLoaded();
}
}
16 changes: 0 additions & 16 deletions bin/dockerEntrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
set -eo pipefail
set +u

restoreE2edPackage() {
if [[ -d "./node_modules/_e2ed" ]]
then
echo "Restore temporarily hiding locally installed e2ed package:"
mv --verbose ./node_modules/_e2ed ./node_modules/e2ed
fi
}

onExit() {
if [[ $PID ]] && ps -p $PID > /dev/null
then
Expand All @@ -20,20 +12,12 @@ onExit() {
sleep "${E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS:-16}"
fi

restoreE2edPackage;

echo "Exit from docker entrypoint"
exit
}

trap "onExit" EXIT

#if [[ -d "./node_modules/e2ed" ]]
#then
# echo "Temporarily hide locally installed e2ed package:"
# mv --verbose ./node_modules/e2ed ./node_modules/_e2ed
#fi

if [[ -z $E2ED_DEBUG ]]
then
/node_modules/e2ed/bin/runE2edInDockerEnvironment.js & PID=$!
Expand Down
12 changes: 12 additions & 0 deletions bin/localEntrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eo pipefail
set +u

BIN_DIR="$(dirname "$(realpath "$BASH_SOURCE")")"

if [[ -z $E2ED_DEBUG ]]
then
"$BIN_DIR/runE2edInLocalEnvironment.js" "$@"
else
node --inspect-brk "$BIN_DIR/runE2edInLocalEnvironment.js" "$@"
fi
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"author": "uid11",
"license": "MIT",
"bin": {
"e2ed": "./bin/runE2edInLocalEnvironment.js",
"e2ed": "./bin/localEntrypoint.sh",
"e2ed-init": "./bin/init.js",
"e2ed-install-browsers": "./bin/installBrowsers.sh"
},
Expand Down Expand Up @@ -92,7 +92,7 @@
"build:remove:types-js": "find ./build/node_modules/e2ed/types/ -name *.js -exec rm {} \\;",
"postbuild:remove": "touch ./build/node_modules/e2ed/types/index.js",
"build:copy": "npm run build:copy:bin && npm run build:copy:scripts && npm run build:copy:meta && npm run build:copy:example && npm run build:copy:tsconfig",
"build:copy:bin": "cp ./bin/dockerEntrypoint.sh ./bin/installBrowsers.sh ./build/node_modules/e2ed/bin",
"build:copy:bin": "cp ./bin/dockerEntrypoint.sh ./bin/installBrowsers.sh ./bin/localEntrypoint.sh ./build/node_modules/e2ed/bin",
"postbuild:copy:bin": "npm run make:executable build/node_modules/e2ed/bin/init.js build/node_modules/e2ed/bin/runE2edInLocalEnvironment.js build/node_modules/e2ed/bin/runE2edInDockerEnvironment.js",
"build:copy:scripts": "cp ./build/scripts/*.js ./build",
"build:copy:meta": "cp -R ./LICENSE ./logo.svg ./README.md ./styles ./build/node_modules/e2ed",
Expand All @@ -118,7 +118,7 @@
"test:docker:copy": "cp -R ./build/autotests ./build/docker/autotests && cp ./build/tsconfig.json ./build/docker",
"posttest:docker:copy": "rm -rf ./build/docker/autotests/reports && ./bin/addPackageJsonToBuildDocker.sh",
"test:docker": "(cd ./build/docker && E2ED_ORIGIN=https://google.com ./autotests/bin/runDocker.sh ./autotests/packs/allTests.ts)",
"test:local": "(cd ./build && E2ED_ORIGIN=https://google.com ./node_modules/e2ed/bin/runE2edInLocalEnvironment.js ./autotests/packs/allTests.ts)"
"test:local": "(cd ./build && E2ED_ORIGIN=https://google.com ./node_modules/e2ed/bin/localEntrypoint.sh ./autotests/packs/allTests.ts)"
},
"sideEffects": false,
"types": "index.d.ts"
Expand Down
3 changes: 2 additions & 1 deletion src/utils/events/registerEndTestRunEvent.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {isLocalRun} from '../../configurator';
import {isDebug, TestRunStatus} from '../../constants/internal';
import {getFullMocksState} from '../../context/fullMocks';
import {getPlaywrightPage} from '../../useContext';
Expand Down Expand Up @@ -99,7 +100,7 @@ export const registerEndTestRunEvent = async (endTestRunEvent: EndTestRunEvent):
await writeTestRunToJsonFile(fullTestRun);
await writeLogsToFile();

if (isDebug) {
if (isDebug && isLocalRun) {
await getPlaywrightPage().pause();
}
};
9 changes: 6 additions & 3 deletions src/utils/tests/runTests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {fork} from 'node:child_process';

import {isLocalRun} from '../../configurator';
import {CONFIG_PATH, e2edEnvironment, isDebug} from '../../constants/internal';

import {getFullPackConfig} from '../config';
Expand Down Expand Up @@ -43,8 +44,7 @@ export const runTests = async ({runLabel}: RunRetryOptions): Promise<void> => {
await new Promise<void>((resolve, reject) => {
const playwrightArgs = ['test', `--config=${CONFIG_PATH}`];

if (isDebug) {
// playwrightArgs.unshift('--node-options=--inspect-brk');
if (isDebug && isLocalRun) {
e2edEnvironment.PWDEBUG = 'console';
playwrightArgs.push('--debug');
}
Expand All @@ -59,7 +59,10 @@ export const runTests = async ({runLabel}: RunRetryOptions): Promise<void> => {
beforeRunFirstTest();
}

const playwrightProcess = fork(playwrightCliPath, playwrightArgs, {stdio: 'pipe'});
const playwrightProcess = fork(playwrightCliPath, playwrightArgs, {
execArgv: [],
stdio: 'pipe',
});

playwrightProcess.stdout?.on('data', (data) => {
const stringData = stripExtraLogs(String(data).trim()).trim();
Expand Down

0 comments on commit d34234f

Please sign in to comment.