Skip to content

Commit 6b489b8

Browse files
committed
FI-705 fix: stricter type of expect function
fix: support usual promises in `expect` function feat: add field `maxIntervalBetweenRequestsInMs` ot abstract class `Page` feat: add examples of `mapBackendResponseErrorToLog`/`mapBackendResponseToLog` tests: more tests of types of selectors methods chore: update nodejs to current LTS (20.10.0) chore: update alpine to 3.18.5 fix: support new contributor in `updateChangelog` script refactor: move selectors code to `utils/selectors` refactor: remove `utils/locators` fix: use default cursor for empty expanded steps feat: add duration to backend response logs refactor: rename function `it` to `test` in initial autotests examples fix: print `message` and `cause` fields of `E2edError` in `replaceFields` fix: reject stuck assertion of `expect` by timeout tests: add separate tests for `expect` function feat: add type `ResponseWithRequest` to public API feat: use `ResponseWithRequest` for mapping backend responses to logs chore: update devDependencies (typescript, eslint, @types/node, etc) chore: update npm `lockfileVersion` (package-lock.json) from 2 to 3 chore: update github action and node version in ci.yaml
1 parent 791ed2f commit 6b489b8

File tree

89 files changed

+807
-5939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+807
-5939
lines changed

.github/workflows/ci.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@ jobs:
66
build-docker:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v3
10-
- uses: actions/setup-node@v3
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
1111
with:
1212
cache: npm
13-
node-version: 16.11.1
13+
node-version: lts
1414
- run: npm ci
1515
- run: npm run build
1616
- run: npm run build:docker
1717

1818
lint:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
22-
- uses: actions/setup-node@v3
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
2323
with:
2424
cache: npm
25-
node-version: 16.11.1
25+
node-version: lts
2626
- run: npm ci
2727
- run: npm run build
2828
- run: npm run lint
2929

3030
test-local:
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v3
34-
- uses: actions/setup-node@v3
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-node@v4
3535
with:
3636
cache: npm
37-
node-version: 16.11.1
37+
node-version: lts
3838
- run: npm ci
3939
- run: npm run build
4040
- run: npm run test:local

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
FROM alpine:3.18.4
1+
FROM node:20.10.0-alpine AS node
2+
3+
FROM alpine:3.18.5
4+
5+
COPY --from=node /usr/lib /usr/lib
6+
COPY --from=node /usr/local/lib /usr/local/lib
7+
COPY --from=node /usr/local/include /usr/local/include
8+
COPY --from=node /usr/local/bin /usr/local/bin
29

310
RUN apk --no-cache upgrade && \
411
apk --no-cache add \
5-
bash libevent nodejs npm chromium firefox xwininfo xvfb dbus eudev ttf-freefont fluxbox procps tzdata icu-data-full
12+
bash libevent npm chromium firefox xwininfo xvfb dbus eudev ttf-freefont fluxbox procps tzdata icu-data-full
613

714
COPY ./build/node_modules/e2ed /node_modules/e2ed
815

autotests/configurator/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export {doAfterPack} from './doAfterPack';
22
export {doBeforePack} from './doBeforePack';
3+
export {mapBackendResponseErrorToLog} from './mapBackendResponseErrorToLog';
4+
export {mapBackendResponseToLog} from './mapBackendResponseToLog';
35
export {mapLogPayloadInConsole} from './mapLogPayloadInConsole';
46
export {mapLogPayloadInLogFile} from './mapLogPayloadInLogFile';
57
export {mapLogPayloadInReport} from './mapLogPayloadInReport';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {getDurationWithUnits} from 'e2ed/utils';
2+
3+
import type {MapBackendResponseErrorToLog} from 'autotests/types/packSpecific';
4+
5+
/**
6+
* Maps responses with errors from the backend to "red" logs (as errors) during the test.
7+
* It is assumed that the function will select responses with
8+
* statuse codes of 400 and higher (client and server errors).
9+
* Backend responses with errors are accumulated in separate "red" log step
10+
* (with `logEventStatus: 'failed'`).
11+
* Log the `responseBody` field carefully, as the body of backend response can be very large.
12+
* If the function returns `undefined`, the response is not logged (skipped).
13+
*/
14+
export const mapBackendResponseErrorToLog: MapBackendResponseErrorToLog = ({
15+
completionTimeInMs,
16+
request,
17+
responseBody,
18+
responseHeaders,
19+
statusCode,
20+
}) => {
21+
if (statusCode < 400) {
22+
return undefined;
23+
}
24+
25+
const {requestBody, utcTimeInMs, ...requestWithoutBody} = request;
26+
27+
const duration = getDurationWithUnits(completionTimeInMs - utcTimeInMs);
28+
29+
return {
30+
duration,
31+
request: {
32+
requestBody: requestBody instanceof Buffer ? String(requestBody) : requestBody,
33+
...requestWithoutBody,
34+
},
35+
responseBody: responseBody instanceof Buffer ? String(responseBody) : responseBody,
36+
responseHeaders,
37+
};
38+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {getDurationWithUnits} from 'e2ed/utils';
2+
3+
import type {MapBackendResponseToLog} from 'autotests/types/packSpecific';
4+
5+
/**
6+
* Maps responses from the backend to logs during the test.
7+
* Backend responses received during a certain test step are accumulated
8+
* in an array in the `backendResponses` field of the log of this step.
9+
* Log the `responseBody` field carefully, as the body of backend response can be very large.
10+
* If the function returns `undefined`, the response is not logged (skipped).
11+
*/
12+
export const mapBackendResponseToLog: MapBackendResponseToLog = ({
13+
completionTimeInMs,
14+
request,
15+
responseBody,
16+
responseHeaders,
17+
statusCode,
18+
}) => {
19+
if (statusCode >= 400) {
20+
return undefined;
21+
}
22+
23+
if (request) {
24+
const maybeWithDuration: {duration?: string} = {};
25+
26+
if (completionTimeInMs !== undefined && request.utcTimeInMs !== undefined) {
27+
maybeWithDuration.duration = getDurationWithUnits(completionTimeInMs - request.utcTimeInMs);
28+
}
29+
30+
return {...maybeWithDuration, statusCode, url: request?.url};
31+
}
32+
33+
return {
34+
responseBody: responseBody instanceof Buffer ? String(responseBody) : responseBody,
35+
responseHeaders,
36+
statusCode,
37+
};
38+
};

autotests/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {it} from './it';
1+
export {test} from './test';

autotests/packs/allTests.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {RunEnvironment, runEnvironment} from 'e2ed/configurator';
1010
import {
1111
doAfterPack,
1212
doBeforePack,
13+
mapBackendResponseErrorToLog,
14+
mapBackendResponseToLog,
1315
mapLogPayloadInConsole,
1416
mapLogPayloadInLogFile,
1517
mapLogPayloadInReport,
@@ -30,7 +32,7 @@ const filterTestsIntoPack: FilterTestsIntoPack = ({options}) => options.meta.tes
3032
*/
3133
export const pack: Pack = {
3234
ajaxRequestTimeout: 40_000,
33-
assertionTimeout: 10_000,
35+
assertionTimeout: 5_000,
3436
browser: [browser, ...browserFlags].join(' '),
3537
browserInitTimeout: 60_000,
3638
concurrency: isLocalRun ? 1 : 2,
@@ -42,10 +44,8 @@ export const pack: Pack = {
4244
filterTestsIntoPack,
4345
liteReportFileName: 'lite-report.json',
4446
logFileName: 'pack-logs.log',
45-
mapBackendResponseErrorToLog: ({request, responseHeaders, statusCode}) =>
46-
statusCode >= 400 ? {request, responseHeaders, statusCode} : undefined,
47-
mapBackendResponseToLog: ({request, statusCode}) =>
48-
statusCode < 400 ? {statusCode, url: request?.url} : undefined,
47+
mapBackendResponseErrorToLog,
48+
mapBackendResponseToLog,
4949
mapLogPayloadInConsole,
5050
mapLogPayloadInLogFile,
5151
mapLogPayloadInReport,

autotests/pageObjects/pages/Main.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,19 @@ export class Main extends Page<CustomPageParams> {
7474
}
7575

7676
override async waitForPageLoaded(): Promise<void> {
77-
await waitForAllRequestsComplete(({url}) => {
78-
if (url.startsWith('https://adservice.google.com/')) {
79-
return false;
80-
}
81-
82-
return true;
83-
});
77+
await waitForAllRequestsComplete(
78+
({url}) => {
79+
if (
80+
url.startsWith('https://adservice.google.com/') ||
81+
url.startsWith('https://play.google.com/')
82+
) {
83+
return false;
84+
}
85+
86+
return true;
87+
},
88+
{maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs},
89+
);
8490

8591
await waitForInterfaceStabilization(this.pageStabilizationInterval);
8692
}

autotests/pageObjects/pages/Search.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,21 @@ export class Search extends MobilePage<CustomPageParams> {
3434
}
3535

3636
override async waitForPageLoaded(): Promise<void> {
37-
await waitForAllRequestsComplete(({url}) => {
38-
if (
39-
url.startsWith('https://adservice.google.com/') ||
40-
url.startsWith('https://googleads.g.doubleclick.net/') ||
41-
url.startsWith('https://play.google.com/') ||
42-
url.startsWith('https://static.doubleclick.net/')
43-
) {
44-
return false;
45-
}
46-
47-
return true;
48-
});
37+
await waitForAllRequestsComplete(
38+
({url}) => {
39+
if (
40+
url.startsWith('https://adservice.google.com/') ||
41+
url.startsWith('https://googleads.g.doubleclick.net/') ||
42+
url.startsWith('https://play.google.com/') ||
43+
url.startsWith('https://static.doubleclick.net/')
44+
) {
45+
return false;
46+
}
47+
48+
return true;
49+
},
50+
{maxIntervalBetweenRequestsInMs: this.maxIntervalBetweenRequestsInMs},
51+
);
4952

5053
await waitForInterfaceStabilization(this.pageStabilizationInterval);
5154
}

autotests/it.ts renamed to autotests/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import type {Pack} from 'autotests/types/packSpecific';
88
* Test function that describes the test or the task
99
* (test does not necessarily contain checks).
1010
*/
11-
export const it = createTestFunction<Pack>(hooks);
11+
export const test = createTestFunction<Pack>(hooks);

0 commit comments

Comments
 (0)