-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
88 changed files
with
798 additions
and
5,930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {getDurationWithUnits} from 'e2ed/utils'; | ||
|
||
import type {MapBackendResponseErrorToLog} from 'autotests/types/packSpecific'; | ||
|
||
/** | ||
* Maps responses with errors from the backend to "red" logs (as errors) during the test. | ||
* It is assumed that the function will select responses with | ||
* statuse codes of 400 and higher (client and server errors). | ||
* Backend responses with errors are accumulated in separate "red" log step | ||
* (with `logEventStatus: 'failed'`). | ||
* Log the `responseBody` field carefully, as the body of backend response can be very large. | ||
* If the function returns `undefined`, the response is not logged (skipped). | ||
*/ | ||
export const mapBackendResponseErrorToLog: MapBackendResponseErrorToLog = ({ | ||
completionTimeInMs, | ||
request, | ||
responseBody, | ||
responseHeaders, | ||
statusCode, | ||
}) => { | ||
if (statusCode < 400) { | ||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {getDurationWithUnits} from 'e2ed/utils'; | ||
|
||
import type {MapBackendResponseToLog} from 'autotests/types/packSpecific'; | ||
|
||
/** | ||
* Maps responses from the backend to logs during the test. | ||
* Backend responses received during a certain test step are accumulated | ||
* in an array in the `backendResponses` field of the log of this step. | ||
* Log the `responseBody` field carefully, as the body of backend response can be very large. | ||
* If the function returns `undefined`, the response is not logged (skipped). | ||
*/ | ||
export const mapBackendResponseToLog: MapBackendResponseToLog = ({ | ||
completionTimeInMs, | ||
request, | ||
responseBody, | ||
responseHeaders, | ||
statusCode, | ||
}) => { | ||
if (statusCode >= 400) { | ||
return undefined; | ||
} | ||
|
||
if (request) { | ||
const maybeWithDuration: {duration?: string} = {}; | ||
|
||
if (completionTimeInMs !== undefined && request.utcTimeInMs !== undefined) { | ||
maybeWithDuration.duration = getDurationWithUnits(completionTimeInMs - request.utcTimeInMs); | ||
} | ||
|
||
return {...maybeWithDuration, statusCode, url: request?.url}; | ||
} | ||
|
||
return { | ||
responseBody: responseBody instanceof Buffer ? String(responseBody) : responseBody, | ||
responseHeaders, | ||
statusCode, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export {it} from './it'; | ||
export {test} from './test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...2edReportExample/customSelectorMethods.ts → ...2edReportExample/selectorCustomMethods.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {test} from 'autotests'; | ||
import {createSelectorByCss} from 'autotests/selectors'; | ||
import {expect} from 'e2ed'; | ||
import {assertFunctionThrows, getTimeoutPromise} from 'e2ed/utils'; | ||
|
||
test('expect function works correctly', {meta: {testId: '16'}}, async () => { | ||
await assertFunctionThrows(async () => { | ||
await expect(1, 'should throws').eql(2); | ||
}, 'throws an error when actual value do not fit expected value'); | ||
|
||
await assertFunctionThrows(async () => { | ||
await expect(getTimeoutPromise(5_100), 'should failed by timeout').ok(); | ||
}, 'throws an timeout error when actual value is a pending promise'); | ||
|
||
await expect(Promise.resolve('foo'), 'awaits usual promises').eql('foo'); | ||
|
||
await assertFunctionThrows(async () => { | ||
await expect( | ||
Promise.resolve('foo'), | ||
'throws an error when comparing for equality of values of different types', | ||
// @ts-expect-error: actual value and expected value has different types | ||
).eql(3); | ||
}, 'throws an error when actual value and expected value has different types'); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
expect(1, 'should be an eslint error when we call expect without await').eql(1); | ||
|
||
// eslint-disable-next-line @typescript-eslint/await-thenable | ||
await expect(1, 'should be an eslint error when we do not call the assertion method'); | ||
|
||
const htmlSelector = createSelectorByCss('html'); | ||
|
||
// @ts-expect-error: expect function should not accept a selector as a actual value | ||
await expect(htmlSelector, 'should be type error when actual value is a selector').ok(); | ||
}); |
Oops, something went wrong.