e2ed
Version:
E2E testing framework over Playwright
36 lines (25 loc) • 1 kB
text/typescript
import {getShallowCopyOfObjectForLogs, getStringTrimmedToMaxLength} from 'e2ed/configurator';
import type {FieldReplacer} from 'e2ed/types';
const maxStringLength = 500;
/**
* Field replacer for log payload.
*/
export const logFieldReplacer: FieldReplacer = (path, value) => {
if (typeof value === 'string') {
return getStringTrimmedToMaxLength(value, maxStringLength);
}
const key = path.at(-1);
if (key === 'responseBody' && value !== null && typeof value === 'object') {
const {payload, ...responseBodyWithoutPayload} = value as {payload?: unknown};
if (payload !== null && typeof payload === 'object') {
const copyOfPayload = getShallowCopyOfObjectForLogs(payload);
const copyOfResponseBody = getShallowCopyOfObjectForLogs(responseBodyWithoutPayload) as {
payload?: unknown;
};
copyOfResponseBody.payload = copyOfPayload;
return copyOfResponseBody;
}
return getShallowCopyOfObjectForLogs(value);
}
return value;
};