Skip to content

Commit

Permalink
FI-1063 fix: message for failed assertion
Browse files Browse the repository at this point in the history
feat: add `duration` field to `ResponseWithRequest`
fix: move some independent functions to `e2ed/configurator` from `e2ed/utils`
chore: update alpine to 3.19.0
fix: use latest version of nodejs, in which browser connection in Docker is stable
fix: `replaceFields` function for objects with nontrivial prototypes
chore: update devDependencies (@types/node, @typescript-eslint/*, etc)
  • Loading branch information
uid11 committed Dec 12, 2023
1 parent a582959 commit ccfa7b0
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 100 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:20.10.0-alpine AS node
FROM node:20.3.1-alpine AS node

FROM alpine:3.18.5
FROM alpine:3.19.0

COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/lib /usr/local/lib
Expand All @@ -9,7 +9,7 @@ COPY --from=node /usr/local/bin /usr/local/bin

RUN apk --no-cache upgrade && \
apk --no-cache add \
bash libevent npm chromium firefox xwininfo xvfb dbus eudev ttf-freefont fluxbox procps tzdata icu-data-full
bash libevent chromium firefox xwininfo xvfb dbus eudev ttf-freefont fluxbox procps tzdata icu-data-full

COPY ./build/node_modules/e2ed /node_modules/e2ed

Expand Down
2 changes: 1 addition & 1 deletion autotests/configurator/logFieldReplacer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getShallowCopyOfObjectForLogs, getStringTrimmedToMaxLength} from 'e2ed/utils';
import {getShallowCopyOfObjectForLogs, getStringTrimmedToMaxLength} from 'e2ed/configurator';

import type {FieldReplacer} from 'e2ed/types';

Expand Down
18 changes: 2 additions & 16 deletions autotests/configurator/mapBackendResponseErrorToLog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {getDurationWithUnits} from 'e2ed/utils';

import type {MapBackendResponseErrorToLog} from 'autotests/types/packSpecific';

/**
Expand All @@ -12,7 +10,7 @@ import type {MapBackendResponseErrorToLog} from 'autotests/types/packSpecific';
* If the function returns `undefined`, the response is not logged (skipped).
*/
export const mapBackendResponseErrorToLog: MapBackendResponseErrorToLog = ({
completionTimeInMs,
duration,
request,
responseBody,
responseHeaders,
Expand All @@ -22,17 +20,5 @@ export const mapBackendResponseErrorToLog: MapBackendResponseErrorToLog = ({
return undefined;
}

const {requestBody, utcTimeInMs, ...requestWithoutBody} = request;

const duration = getDurationWithUnits(completionTimeInMs - utcTimeInMs);

return {
duration,
request: {
requestBody: requestBody instanceof Buffer ? String(requestBody) : requestBody,
...requestWithoutBody,
},
responseBody: responseBody instanceof Buffer ? String(responseBody) : responseBody,
responseHeaders,
};
return {duration, request, responseBody, responseHeaders};
};
10 changes: 3 additions & 7 deletions autotests/configurator/mapBackendResponseToLog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {getDurationWithUnits} from 'e2ed/utils';

import type {MapBackendResponseToLog} from 'autotests/types/packSpecific';

/**
Expand All @@ -10,15 +8,13 @@ import type {MapBackendResponseToLog} from 'autotests/types/packSpecific';
* If the function returns `undefined`, the response is not logged (skipped).
*/
export const mapBackendResponseToLog: MapBackendResponseToLog = ({
completionTimeInMs,
request,
duration,
statusCode,
request,
}) => {
if (statusCode >= 400) {
return undefined;
}

const duration = getDurationWithUnits(completionTimeInMs - request.utcTimeInMs);

return {duration, statusCode, url: request?.url};
return {duration, statusCode, url: request.url};
};
116 changes: 58 additions & 58 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 @@ -32,9 +32,9 @@
"testcafe-without-typecheck": "3.4.0-rc.1"
},
"devDependencies": {
"@types/node": "20.10.3",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"@types/node": "20.10.4",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"assert-modules-support-case-insensitive-fs": "1.0.1",
"assert-package-lock-is-consistent": "1.0.0",
"eslint": "8.55.0",
Expand All @@ -43,7 +43,7 @@
"eslint-plugin-import": "2.29.0",
"eslint-plugin-simple-import-sort": "10.0.0",
"husky": "8.0.3",
"prettier": "3.1.0",
"prettier": "3.1.1",
"testcafe": "3.4.0",
"typescript": "5.3.3"
},
Expand Down
4 changes: 1 addition & 3 deletions src/configurator/getReplacedObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export const getReplacedObject = <Value extends object>(
return value;
}

const replacedObject = (
Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value) as object | null)
) as Value;
const replacedObject = (Array.isArray(value) ? [] : {}) as Value;

const keys: PropertyKey[] = Object.keys(value);

Expand Down
2 changes: 2 additions & 0 deletions src/configurator/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type {UserlandPack as PackConfig} from '../types/internal';
export {getDurationWithUnits} from '../utils/getDurationWithUnits';
export {getShallowCopyOfObjectForLogs, getStringTrimmedToMaxLength} from '../utils/valueToString';
export {RunEnvironment, startTimeInMs} from './constants';
export {replaceFields} from './replaceFields';
export {runEnvironment} from './runEnvironment';
Expand Down
1 change: 1 addition & 0 deletions src/types/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export type Response<
SomeRequest extends Request = Request,
> = Readonly<{
completionTimeInMs?: UtcTimeInMs;
duration?: string;
request?: SomeRequest;
responseBody: ResponseBody;
responseHeaders: ResponseHeaders;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/expect/createExpectMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createExpectMethod = (
function method(...args: Parameters<ExpectMethod>) {
assertionTimeout ??= getFullPackConfig().assertionTimeout;

const timeout = assertionTimeout ?? 0;
const timeout = assertionTimeout + 1_000;
const message = getAssertionMessage(...args);

const {clearRejectTimeout, promiseWithTimeout, reject, setRejectTimeoutFunction} =
Expand All @@ -42,7 +42,7 @@ export const createExpectMethod = (
setRejectTimeoutFunction(() => {
const timeoutWithUnits = getDurationWithUnits(timeout);
const error = new E2edError(
`${key}-assertion promise rejected after ${timeoutWithUnits} timeout`,
`"${key}" assertion promise rejected after ${timeoutWithUnits} timeout`,
);

reject(error);
Expand Down
7 changes: 1 addition & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export {E2edError, getStackTrace} from './error';
export {getFunctionPresentationForLogs, setCustomInspectOnFunction} from './fn';
export {writeFile} from './fs';
export {removeStyleFromString} from './generalLog';
export {getDurationWithUnits} from './getDurationWithUnits';
export {getFullPackConfig as untypedGetFullPackConfig} from './getFullPackConfig';
export {getKeysCounter} from './getKeysCounter';
export {log} from './log';
Expand All @@ -43,9 +42,5 @@ export {setReadonlyProperty} from './setReadonlyProperty';
export {getPackageInfo} from './startInfo';
export {wrapInTestRunTracker} from './testRun';
export {isArray, isReExecutablePromise, isThenable} from './typeGuards';
export {
getShallowCopyOfObjectForLogs,
getStringTrimmedToMaxLength,
valueToString,
} from './valueToString';
export {valueToString} from './valueToString';
export {isSelectorEntirelyInViewport, isSelectorInViewport} from './viewport';
Loading

0 comments on commit ccfa7b0

Please sign in to comment.