Skip to content

Commit 29337ae

Browse files
authored
Merge pull request #112 from joomcode/feat/collect-api-statistics
feat: collect API statistics for requests
2 parents 52c7c25 + fccc317 commit 29337ae

69 files changed

Lines changed: 558 additions & 152 deletions

Some content is hidden

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

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/setup-node@v4
1111
with:
1212
cache: npm
13-
node-version: 20.16.0
13+
node-version: 22.14.0
1414
- run: npm ci
1515
- run: npm run build
1616
- run: npm run build:docker
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/setup-node@v4
2323
with:
2424
cache: npm
25-
node-version: 20.16.0
25+
node-version: 22.14.0
2626
- run: npm ci
2727
- run: npm run build
2828
- run: npm run lint
@@ -34,7 +34,7 @@ jobs:
3434
- uses: actions/setup-node@v4
3535
with:
3636
cache: npm
37-
node-version: 20.16.0
37+
node-version: 22.14.0
3838
- run: npm ci
3939
- run: npm run build
4040
- run: npm run test:local

package-lock.json

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
"url": "git+https://github.com/joomcode/e2ed.git"
2626
},
2727
"dependencies": {
28-
"@playwright/test": "1.50.1",
28+
"@playwright/test": "1.51.0",
2929
"create-locator": "0.0.27",
3030
"get-modules-graph": "0.0.11",
3131
"globby": "11.1.0"
3232
},
3333
"devDependencies": {
34-
"@playwright/browser-chromium": "1.50.1",
35-
"@types/node": "22.13.9",
34+
"@playwright/browser-chromium": "1.51.0",
35+
"@types/node": "22.13.10",
3636
"@typescript-eslint/eslint-plugin": "7.18.0",
3737
"@typescript-eslint/parser": "7.18.0",
3838
"assert-modules-support-case-insensitive-fs": "1.0.1",
3939
"assert-package-lock-is-consistent": "1.0.0",
4040
"eslint": "8.57.1",
4141
"eslint-config-airbnb-base": "15.0.0",
42-
"eslint-config-prettier": "10.0.1",
42+
"eslint-config-prettier": "10.1.1",
4343
"eslint-plugin-import": "2.31.0",
4444
"eslint-plugin-simple-import-sort": "12.1.1",
4545
"eslint-plugin-typescript-sort-keys": "3.3.0",

src/README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ Modules in the dependency graph should only import the modules above them:
1414
7. `configurator`
1515
8. `utils/getHash`
1616
9. `generators`
17-
10. `utils/viewport`
18-
11. `utils/parse`
19-
12. `utils/distanceBetweenSelectors`
20-
13. `utils/getDurationWithUnits`
21-
14. `utils/setReadonlyProperty`
22-
15. `utils/paths`
23-
16. `utils/valueToString`
24-
17. `utils/error`
25-
18. `utils/asserts`
17+
10. `utils/headers`
18+
11. `utils/viewport`
19+
12. `utils/parse`
20+
13. `utils/distanceBetweenSelectors`
21+
14. `utils/getDurationWithUnits`
22+
15. `utils/valueToString`
23+
16. `utils/error`
24+
17. `utils/asserts`
25+
18. `utils/object`
2626
19. `utils/uiMode`
2727
20. `utils/runLabel`
2828
21. `utils/clone`
@@ -44,10 +44,11 @@ Modules in the dependency graph should only import the modules above them:
4444
37. `utils/pack`
4545
38. `useContext`
4646
39. `context`
47-
40. `utils/selectors`
48-
41. `selectors`
49-
42. `utils/log`
50-
43. `utils/waitForEvents`
51-
44. `utils/expect`
52-
45. `expect`
53-
46. ...
47+
40. `utils/apiStatistics`
48+
41. `utils/selectors`
49+
42. `selectors`
50+
43. `utils/log`
51+
44. `utils/waitForEvents`
52+
45. `utils/expect`
53+
46. `expect`
54+
47. ...

src/actions/mock/mockApiRoute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {assertValueIsDefined} from '../../utils/asserts';
66
import {setCustomInspectOnFunction} from '../../utils/fn';
77
import {log} from '../../utils/log';
88
import {getRequestsFilter, getSetResponse} from '../../utils/mockApiRoute';
9-
import {setReadonlyProperty} from '../../utils/setReadonlyProperty';
9+
import {setReadonlyProperty} from '../../utils/object';
1010

1111
import type {
1212
ApiMockFunction,

src/actions/mock/mockWebSocketRoute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {assertValueIsDefined} from '../../utils/asserts';
66
import {setCustomInspectOnFunction} from '../../utils/fn';
77
import {log} from '../../utils/log';
88
import {getRequestsFilter, getSetResponse} from '../../utils/mockWebSocketRoute';
9-
import {setReadonlyProperty} from '../../utils/setReadonlyProperty';
9+
import {setReadonlyProperty} from '../../utils/object';
1010

1111
import type {
1212
WebSocketMockFunction,

src/actions/pages/navigateToPage.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import {LogEventType} from '../../constants/internal';
2+
import {addPageToApiStatistics} from '../../utils/apiStatistics';
23
import {getDocumentUrl} from '../../utils/document';
34
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
45
import {log} from '../../utils/log';
56

67
import {createPageInstance} from './createPageInstance';
78

8-
import type {AnyPageClassType, NavigateToOrAssertPageArgs, UtcTimeInMs} from '../../types/internal';
9+
import type {
10+
AnyPageClassType,
11+
NavigateToOrAssertPageArgs,
12+
PageName,
13+
UtcTimeInMs,
14+
} from '../../types/internal';
915

1016
/**
1117
* Navigates to the page by page class and page params.
@@ -24,9 +30,10 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
2430
const url = route.getUrl();
2531
const startNavigateTimeInMs = Date.now() as UtcTimeInMs;
2632
const pageInstanceCreatedInMs = startNavigateTimeInMs - startTimeInMs;
33+
const pageName = PageClass.name as PageName;
2734

2835
log(
29-
`Will navigate to the page "${PageClass.name}"`,
36+
`Will navigate to the page "${pageName}"`,
3037
{pageInstanceCreatedInMs, pageParams, routeParams, url},
3138
LogEventType.InternalAction,
3239
);
@@ -36,7 +43,7 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
3643
await page.navigateToPage(url);
3744

3845
log(
39-
`Navigation to the page "${PageClass.name}" completed`,
46+
`Navigation to the page "${pageName}" completed`,
4047
{pageParams, routeParams, url},
4148
LogEventType.InternalAction,
4249
);
@@ -52,13 +59,12 @@ export const navigateToPage = async <SomePageClass extends AnyPageClassType>(
5259

5360
await page.afterNavigateToPage?.();
5461

55-
const durationWithUnits = getDurationWithUnits(Date.now() - startNavigateTimeInMs);
62+
const duration = Date.now() - startNavigateTimeInMs;
63+
const durationWithUnits = getDurationWithUnits(duration);
5664

57-
log(
58-
`Page "${PageClass.name}" loaded in ${durationWithUnits}`,
59-
{url},
60-
LogEventType.InternalAction,
61-
);
65+
log(`Page "${pageName}" loaded in ${durationWithUnits}`, {url}, LogEventType.InternalAction);
66+
67+
addPageToApiStatistics({duration, pageName, url});
6268

6369
return page;
6470
};

src/actions/setHeadersAndNavigateToUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {AsyncLocalStorage} from 'node:async_hooks';
22

33
import {LogEventType} from '../constants/internal';
44
import {getPlaywrightPage} from '../useContext';
5+
import {applyHeadersMapper} from '../utils/headers';
56
import {log} from '../utils/log';
6-
import {applyHeadersMapper} from '../utils/requestHooks';
77

88
import {navigateToUrl} from './navigateToUrl';
99

src/actions/waitFor/waitForAllRequestsComplete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {E2edError} from '../../utils/error';
66
import {setCustomInspectOnFunction} from '../../utils/fn';
77
import {getDurationWithUnits} from '../../utils/getDurationWithUnits';
88
import {log} from '../../utils/log';
9+
import {setReadonlyProperty} from '../../utils/object';
910
import {getPromiseWithResolveAndReject} from '../../utils/promise';
10-
import {setReadonlyProperty} from '../../utils/setReadonlyProperty';
1111
import {
1212
getInitialIdsForAllRequestsCompletePredicate,
1313
getUrlsByRequestHookContextIds,

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {assertValueIsTrue} from './utils/asserts';
2121
import {assertUserlandPack} from './utils/config/assertUserlandPack';
2222
import {getPathToPack} from './utils/environment';
2323
import {setCustomInspectOnFunction} from './utils/fn';
24-
import {setReadonlyProperty} from './utils/setReadonlyProperty';
24+
import {setReadonlyProperty} from './utils/object';
2525
import {isUiMode} from './utils/uiMode';
2626
import {isLocalRun} from './configurator';
2727

0 commit comments

Comments
 (0)