@gravity-ui/playwright-tools 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/actions/collectPageActivity/isSameResponse.js +16 -5
- package/actions/collectPageActivity/normalizePathname.js +2 -2
- package/actions/collectPageActivity/types.d.ts +1 -1
- package/actions/disableMetrika.d.ts +8 -0
- package/actions/disableMetrika.js +12 -0
- package/actions/expect-request/matchers/compare/DiffPrinter.js +0 -1
- package/actions/expect-request/matchers/compare/index.d.ts +1 -3
- package/actions/expect-request/matchers/compare/index.js +1 -19
- package/actions/expect-request/matchers/compare/types.d.ts +13 -13
- package/actions/index.d.ts +2 -1
- package/actions/index.js +5 -3
- package/data/globalSettings.d.ts +0 -16
- package/data/globalSettings.js +0 -16
- package/fixtures/index.d.ts +2 -0
- package/fixtures/index.js +4 -1
- package/fixtures/mock-network/har-patcher.js +2 -0
- package/fixtures/mount/constants.d.ts +1 -0
- package/fixtures/mount/constants.js +4 -0
- package/fixtures/mount/index.d.ts +3 -0
- package/fixtures/mount/index.js +7 -0
- package/fixtures/mount/mount-fixture.d.ts +3 -0
- package/fixtures/mount/mount-fixture.js +19 -0
- package/fixtures/mount/types.d.ts +9 -0
- package/fixtures/mount/types.js +2 -0
- package/har/addFlushTransform.d.ts +6 -0
- package/har/addFlushTransform.js +37 -0
- package/har/index.d.ts +2 -0
- package/har/index.js +3 -1
- package/package.json +16 -2
- package/actions/mockDate.d.ts +0 -10
- package/actions/mockDate.js +0 -20
package/README.md
CHANGED
|
@@ -2,8 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
A library of additional utilities for writing tests using Playwright Test.
|
|
4
4
|
|
|
5
|
+
```
|
|
6
|
+
npm i -D playwright-tools
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The package contains several subdirectories with utilities for different purposes. You should import from these subdirectories, for example:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { matchScreenshot } from 'playwright-tools/actions';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- [actions](./actions/README.md) — Browser actions.
|
|
16
|
+
- [auth/storage](./auth/storage/README.md) — Authentication functions for saving and restoring browser storage snapshots.
|
|
17
|
+
- [fixtures](./fixtures/README.md) — Fixtures for passing values into tests.
|
|
18
|
+
- [har](./har/README.md) — Functions for working with HAR request dumps.
|
|
19
|
+
- [config](./config/README.md) — Base configuration.
|
|
20
|
+
- [utils](./utils/README.md) — Helper functions.
|
|
21
|
+
|
|
22
|
+
You can learn more about Playwright and how to configure it in the [Playwright documentation](https://playwright.dev/docs/intro).
|
|
23
|
+
|
|
5
24
|
## Maintainers
|
|
6
25
|
|
|
7
26
|
[@Avol-V](https://github.com/Avol-V)
|
|
8
27
|
[SwinX](https://github.com/SwinX)
|
|
9
|
-
[@vegancat63](https://github.com/vegancat63)
|
|
28
|
+
[@vegancat63](https://github.com/vegancat63)
|
|
@@ -5,12 +5,23 @@ const normalizePathname_1 = require("./normalizePathname");
|
|
|
5
5
|
const EMPTY_PATHNAME = '/';
|
|
6
6
|
function isSameResponse(status, url, baseUrl) {
|
|
7
7
|
return (expectedResponse) => {
|
|
8
|
-
const expectedUrl =
|
|
8
|
+
const expectedUrl = typeof expectedResponse.url === 'string'
|
|
9
|
+
? new URL(expectedResponse.url, baseUrl)
|
|
10
|
+
: expectedResponse.url;
|
|
9
11
|
const failedUrl = new URL(url);
|
|
10
|
-
let result = expectedResponse.status === status
|
|
11
|
-
if (result
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
let result = expectedResponse.status === status;
|
|
13
|
+
if (result) {
|
|
14
|
+
if (expectedUrl instanceof RegExp) {
|
|
15
|
+
result = expectedUrl.test(failedUrl.href);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result = expectedUrl.origin === failedUrl.origin;
|
|
19
|
+
if (result && expectedUrl.pathname !== EMPTY_PATHNAME) {
|
|
20
|
+
result =
|
|
21
|
+
(0, normalizePathname_1.normalizePathname)(expectedUrl.pathname) ===
|
|
22
|
+
(0, normalizePathname_1.normalizePathname)(failedUrl.pathname);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
14
25
|
}
|
|
15
26
|
return result;
|
|
16
27
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePathname = void 0;
|
|
2
4
|
// remove the last '/'
|
|
3
5
|
// for the case if pathname was not specified in the URL, since by default it is equal to '/'
|
|
4
6
|
// for the case if '/search' is compared with '/search/'
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalizePathname = void 0;
|
|
7
7
|
const normalizePathname = (pathname) => pathname.replace(/\/$/, '');
|
|
8
8
|
exports.normalizePathname = normalizePathname;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Page } from '@playwright/test';
|
|
2
|
+
/**
|
|
3
|
+
* Disables selected Metrika counters using the standard API
|
|
4
|
+
* {@see https://yandex.ru/support/metrica/general/user-opt-out.html}
|
|
5
|
+
*/
|
|
6
|
+
export declare function disableMetrika(page: Page, { counters }: {
|
|
7
|
+
counters: number[];
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.disableMetrika = disableMetrika;
|
|
4
|
+
/**
|
|
5
|
+
* Disables selected Metrika counters using the standard API
|
|
6
|
+
* {@see https://yandex.ru/support/metrica/general/user-opt-out.html}
|
|
7
|
+
*/
|
|
8
|
+
async function disableMetrika(page, { counters }) {
|
|
9
|
+
await page.addInitScript({
|
|
10
|
+
content: counters.reduce((countersCode, counterId) => `${countersCode}\nwindow['disableYaCounter${counterId}'] = true;`, ''),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -35,7 +35,6 @@ class DiffPrinter {
|
|
|
35
35
|
const { context, type } = logItem;
|
|
36
36
|
const path = this.makePathFromContext(context);
|
|
37
37
|
if (!acc[path]) {
|
|
38
|
-
/* eslint-disable no-return-assign, no-param-reassign */
|
|
39
38
|
acc[path] = [];
|
|
40
39
|
}
|
|
41
40
|
if (type === constants_1.DiffType.ValueMismatch) {
|
|
@@ -1,23 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
3
|
+
exports.compare = void 0;
|
|
18
4
|
var compare_1 = require("./compare");
|
|
19
5
|
Object.defineProperty(exports, "compare", { enumerable: true, get: function () { return compare_1.compare; } });
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
|
-
__exportStar(require("./utils"), exports);
|
|
22
|
-
var print_json_diff_1 = require("./print-json-diff");
|
|
23
|
-
Object.defineProperty(exports, "printJsonDiff", { enumerable: true, get: function () { return print_json_diff_1.printJsonDiff; } });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Json, JsonPrimitive } from '../../types';
|
|
2
|
-
import
|
|
3
|
-
export type DiffType = (typeof
|
|
2
|
+
import { DecoratedLineType as DecoratedLineTypeConst, DiffType as DiffTypeConst, PathAnnotationType as PathAnnotationTypeConst } from './constants';
|
|
3
|
+
export type DiffType = (typeof DiffTypeConst)[keyof typeof DiffTypeConst];
|
|
4
|
+
export type DecoratedLineType = (typeof DecoratedLineTypeConst)[keyof typeof DecoratedLineTypeConst];
|
|
5
|
+
export type PathAnnotationType = (typeof PathAnnotationTypeConst)[keyof typeof PathAnnotationTypeConst];
|
|
4
6
|
export type DiffLog = DiffItem[];
|
|
5
7
|
export type DiffItem = DiffItemBase & {
|
|
6
8
|
context: DiffContextItem[];
|
|
@@ -8,52 +10,50 @@ export type DiffItem = DiffItemBase & {
|
|
|
8
10
|
export type DiffItemBase = {
|
|
9
11
|
side?: 'left' | 'right';
|
|
10
12
|
} & ({
|
|
11
|
-
type: typeof
|
|
13
|
+
type: typeof DiffTypeConst.ValueMismatch;
|
|
12
14
|
expected?: Json;
|
|
13
15
|
received?: Json;
|
|
14
16
|
} | {
|
|
15
|
-
type: typeof
|
|
17
|
+
type: typeof DiffTypeConst.ObjectMissingProperty;
|
|
16
18
|
expected: {
|
|
17
19
|
key: string;
|
|
18
20
|
value: Json;
|
|
19
21
|
};
|
|
20
22
|
} | {
|
|
21
|
-
type: typeof
|
|
23
|
+
type: typeof DiffTypeConst.ArrayMissingValue;
|
|
22
24
|
expected: Json;
|
|
23
25
|
});
|
|
24
26
|
export type DiffContextItem = {
|
|
25
27
|
objectField?: string;
|
|
26
28
|
arrayIndex?: number;
|
|
27
29
|
};
|
|
28
|
-
export type DecoratedLineType = (typeof DecoratedLineType)[keyof typeof DecoratedLineType];
|
|
29
30
|
export type DecoratedLine = {
|
|
30
31
|
fieldName?: string;
|
|
31
32
|
level: number;
|
|
32
33
|
diffMarker?: 'expected' | 'received';
|
|
33
34
|
} & ({
|
|
34
|
-
type: typeof
|
|
35
|
+
type: typeof DecoratedLineTypeConst.PrimitiveValue;
|
|
35
36
|
value: JsonPrimitive;
|
|
36
37
|
} | {
|
|
37
|
-
type: Exclude<DecoratedLineType, typeof
|
|
38
|
+
type: Exclude<DecoratedLineType, typeof DecoratedLineTypeConst.PrimitiveValue>;
|
|
38
39
|
});
|
|
39
40
|
export type PathAnnotation = ObjectMissingPropertyAnnotation | ObjectExtraPropertyAnnotation | ArrayMissingValueAnnotation | ValueMismatchAnnotation;
|
|
40
|
-
export type PathAnnotationType = (typeof PathAnnotationType)[keyof typeof PathAnnotationType];
|
|
41
41
|
export type ObjectMissingPropertyAnnotation = {
|
|
42
|
-
type: typeof
|
|
42
|
+
type: typeof PathAnnotationTypeConst.ObjectMissingProperty;
|
|
43
43
|
expected: {
|
|
44
44
|
key: string;
|
|
45
45
|
value: Json;
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
export type ObjectExtraPropertyAnnotation = {
|
|
49
|
-
type: typeof
|
|
49
|
+
type: typeof PathAnnotationTypeConst.ObjectExtraProperty;
|
|
50
50
|
};
|
|
51
51
|
export type ArrayMissingValueAnnotation = {
|
|
52
|
-
type: typeof
|
|
52
|
+
type: typeof PathAnnotationTypeConst.ArrayMissingValue;
|
|
53
53
|
expected: Json;
|
|
54
54
|
};
|
|
55
55
|
export type ValueMismatchAnnotation = {
|
|
56
|
-
type: typeof
|
|
56
|
+
type: typeof PathAnnotationTypeConst.ValueMismatch;
|
|
57
57
|
expected?: Json;
|
|
58
58
|
received?: Json;
|
|
59
59
|
};
|
package/actions/index.d.ts
CHANGED
|
@@ -4,13 +4,14 @@ export { assertElementsHidden } from './assertElementsHidden';
|
|
|
4
4
|
export { clearExtraHttpHeaders } from './clearExtraHttpHeaders';
|
|
5
5
|
export { collectPageActivity } from './collectPageActivity';
|
|
6
6
|
export { disableAnimations } from './disableAnimation';
|
|
7
|
+
export { disableMetrika } from './disableMetrika';
|
|
8
|
+
export { expectRequest } from './expect-request';
|
|
7
9
|
export { getExtraHttpHeader } from './getExtraHttpHeader';
|
|
8
10
|
export { getExtraHttpHeaders } from './getExtraHttpHeaders';
|
|
9
11
|
export { getGlobalSettings } from './getGlobalSettings';
|
|
10
12
|
export { getTestSlug } from './getTestSlug';
|
|
11
13
|
export { hasExtraHttpHeader } from './hasExtraHttpHeader';
|
|
12
14
|
export { matchScreenshot } from './matchScreenshot';
|
|
13
|
-
export { mockDate } from './mockDate';
|
|
14
15
|
export { removeExtraHttpHeader } from './removeExtraHttpHeader';
|
|
15
16
|
export { setCacheSettings } from './setCacheSettings';
|
|
16
17
|
export { setGlobalSettings } from './setGlobalSettings';
|
package/actions/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.waitForNetworkSettled = exports.setTestSlug = exports.setGlobalSettings = exports.setCacheSettings = exports.removeExtraHttpHeader = exports.
|
|
3
|
+
exports.waitForNetworkSettled = exports.setTestSlug = exports.setGlobalSettings = exports.setCacheSettings = exports.removeExtraHttpHeader = exports.matchScreenshot = exports.hasExtraHttpHeader = exports.getTestSlug = exports.getGlobalSettings = exports.getExtraHttpHeaders = exports.getExtraHttpHeader = exports.expectRequest = exports.disableMetrika = exports.disableAnimations = exports.collectPageActivity = exports.clearExtraHttpHeaders = exports.assertElementsHidden = exports.addExtraHttpHeaders = exports.addExtraHttpHeader = void 0;
|
|
4
4
|
var addExtraHttpHeader_1 = require("./addExtraHttpHeader");
|
|
5
5
|
Object.defineProperty(exports, "addExtraHttpHeader", { enumerable: true, get: function () { return addExtraHttpHeader_1.addExtraHttpHeader; } });
|
|
6
6
|
var addExtraHttpHeaders_1 = require("./addExtraHttpHeaders");
|
|
@@ -13,6 +13,10 @@ var collectPageActivity_1 = require("./collectPageActivity");
|
|
|
13
13
|
Object.defineProperty(exports, "collectPageActivity", { enumerable: true, get: function () { return collectPageActivity_1.collectPageActivity; } });
|
|
14
14
|
var disableAnimation_1 = require("./disableAnimation");
|
|
15
15
|
Object.defineProperty(exports, "disableAnimations", { enumerable: true, get: function () { return disableAnimation_1.disableAnimations; } });
|
|
16
|
+
var disableMetrika_1 = require("./disableMetrika");
|
|
17
|
+
Object.defineProperty(exports, "disableMetrika", { enumerable: true, get: function () { return disableMetrika_1.disableMetrika; } });
|
|
18
|
+
var expect_request_1 = require("./expect-request");
|
|
19
|
+
Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_1.expectRequest; } });
|
|
16
20
|
var getExtraHttpHeader_1 = require("./getExtraHttpHeader");
|
|
17
21
|
Object.defineProperty(exports, "getExtraHttpHeader", { enumerable: true, get: function () { return getExtraHttpHeader_1.getExtraHttpHeader; } });
|
|
18
22
|
var getExtraHttpHeaders_1 = require("./getExtraHttpHeaders");
|
|
@@ -25,8 +29,6 @@ var hasExtraHttpHeader_1 = require("./hasExtraHttpHeader");
|
|
|
25
29
|
Object.defineProperty(exports, "hasExtraHttpHeader", { enumerable: true, get: function () { return hasExtraHttpHeader_1.hasExtraHttpHeader; } });
|
|
26
30
|
var matchScreenshot_1 = require("./matchScreenshot");
|
|
27
31
|
Object.defineProperty(exports, "matchScreenshot", { enumerable: true, get: function () { return matchScreenshot_1.matchScreenshot; } });
|
|
28
|
-
var mockDate_1 = require("./mockDate");
|
|
29
|
-
Object.defineProperty(exports, "mockDate", { enumerable: true, get: function () { return mockDate_1.mockDate; } });
|
|
30
32
|
var removeExtraHttpHeader_1 = require("./removeExtraHttpHeader");
|
|
31
33
|
Object.defineProperty(exports, "removeExtraHttpHeader", { enumerable: true, get: function () { return removeExtraHttpHeader_1.removeExtraHttpHeader; } });
|
|
32
34
|
var setCacheSettings_1 = require("./setCacheSettings");
|
package/data/globalSettings.d.ts
CHANGED
|
@@ -58,22 +58,6 @@ export declare const globalSettings: {
|
|
|
58
58
|
*/
|
|
59
59
|
onSwitchTheme: undefined | OnSwitchThemeCallback;
|
|
60
60
|
};
|
|
61
|
-
/**
|
|
62
|
-
* actions/mockDate
|
|
63
|
-
*/
|
|
64
|
-
mockDate: {
|
|
65
|
-
/**
|
|
66
|
-
* Default date
|
|
67
|
-
*/
|
|
68
|
-
defaultDate: {
|
|
69
|
-
year: number;
|
|
70
|
-
month: number;
|
|
71
|
-
day: number;
|
|
72
|
-
hour: number;
|
|
73
|
-
min: number;
|
|
74
|
-
sec: number;
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
61
|
/**
|
|
78
62
|
* utils/waitForResolve
|
|
79
63
|
*/
|
package/data/globalSettings.js
CHANGED
|
@@ -74,22 +74,6 @@ exports.globalSettings = {
|
|
|
74
74
|
await page.emulateMedia({ colorScheme: theme });
|
|
75
75
|
}),
|
|
76
76
|
},
|
|
77
|
-
/**
|
|
78
|
-
* actions/mockDate
|
|
79
|
-
*/
|
|
80
|
-
mockDate: {
|
|
81
|
-
/**
|
|
82
|
-
* Default date
|
|
83
|
-
*/
|
|
84
|
-
defaultDate: {
|
|
85
|
-
year: 2020,
|
|
86
|
-
month: 7,
|
|
87
|
-
day: 15,
|
|
88
|
-
hour: 12,
|
|
89
|
-
min: 0,
|
|
90
|
-
sec: 0,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
77
|
/**
|
|
94
78
|
* utils/waitForResolve
|
|
95
79
|
*/
|
package/fixtures/index.d.ts
CHANGED
|
@@ -8,3 +8,5 @@ export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotFixt
|
|
|
8
8
|
export { expectScreenshotFixtureBuilder } from './expect-screenshot';
|
|
9
9
|
export type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, } from './global-settings';
|
|
10
10
|
export { globalSettingsFixturesBuilder } from './global-settings';
|
|
11
|
+
export type { MountFn, MountTestArgs } from './mount';
|
|
12
|
+
export { mountFixture, TEST_WRAPPER_CLASS } from './mount';
|
package/fixtures/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.globalSettingsFixturesBuilder = exports.expectScreenshotFixtureBuilder = exports.expectRequest = exports.mockNetworkFixtureBuilder = exports.testSlug = void 0;
|
|
3
|
+
exports.TEST_WRAPPER_CLASS = exports.mountFixture = exports.globalSettingsFixturesBuilder = exports.expectScreenshotFixtureBuilder = exports.expectRequest = exports.mockNetworkFixtureBuilder = exports.testSlug = void 0;
|
|
4
4
|
var testSlug_1 = require("./testSlug");
|
|
5
5
|
Object.defineProperty(exports, "testSlug", { enumerable: true, get: function () { return testSlug_1.testSlug; } });
|
|
6
6
|
var mock_network_1 = require("./mock-network");
|
|
@@ -11,3 +11,6 @@ var expect_screenshot_1 = require("./expect-screenshot");
|
|
|
11
11
|
Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_1.expectScreenshotFixtureBuilder; } });
|
|
12
12
|
var global_settings_1 = require("./global-settings");
|
|
13
13
|
Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_1.globalSettingsFixturesBuilder; } });
|
|
14
|
+
var mount_1 = require("./mount");
|
|
15
|
+
Object.defineProperty(exports, "mountFixture", { enumerable: true, get: function () { return mount_1.mountFixture; } });
|
|
16
|
+
Object.defineProperty(exports, "TEST_WRAPPER_CLASS", { enumerable: true, get: function () { return mount_1.TEST_WRAPPER_CLASS; } });
|
|
@@ -37,4 +37,6 @@ function harPatcher({ baseURL, headersToRemove: additionalHeadersToRemove = [],
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
(0, har_1.addHarLookupTransform)(onTransformHarLookupParams, onTransformHarLookupResult);
|
|
40
|
+
// Filter out canceled requests before writing to har file
|
|
41
|
+
(0, har_1.addFlushTransform)((entries) => entries.filter((entry) => entry.time !== -1));
|
|
40
42
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TEST_WRAPPER_CLASS = "playwright-wrapper-test";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TEST_WRAPPER_CLASS = exports.mountFixture = void 0;
|
|
4
|
+
var mount_fixture_1 = require("./mount-fixture");
|
|
5
|
+
Object.defineProperty(exports, "mountFixture", { enumerable: true, get: function () { return mount_fixture_1.mountFixture; } });
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
Object.defineProperty(exports, "TEST_WRAPPER_CLASS", { enumerable: true, get: function () { return constants_1.TEST_WRAPPER_CLASS; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mountFixture = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const mountFixture = async ({ mount: baseMount }, use) => {
|
|
7
|
+
const mount = async (component, options) => {
|
|
8
|
+
return await baseMount((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
9
|
+
padding: 20,
|
|
10
|
+
// When we set width we didn't expect that paddings for better screenshots would be included
|
|
11
|
+
boxSizing: options?.width ? 'content-box' : undefined,
|
|
12
|
+
width: options?.width ? options.width : 'fit-content',
|
|
13
|
+
height: 'fit-content',
|
|
14
|
+
...options?.rootStyle,
|
|
15
|
+
}, className: constants_1.TEST_WRAPPER_CLASS, children: [(0, jsx_runtime_1.jsx)("style", { children: '.g-button, .g-button::after { transform: scale(1) !important; }' }), component] }), options);
|
|
16
|
+
};
|
|
17
|
+
await use(mount);
|
|
18
|
+
};
|
|
19
|
+
exports.mountFixture = mountFixture;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { MountOptions, MountResult } from '@playwright/experimental-ct-react';
|
|
3
|
+
export type MountFn = <HooksConfig>(component: React.JSX.Element, options?: MountOptions<HooksConfig> & {
|
|
4
|
+
width?: number | string;
|
|
5
|
+
rootStyle?: React.CSSProperties;
|
|
6
|
+
}) => Promise<MountResult>;
|
|
7
|
+
export type MountTestArgs = {
|
|
8
|
+
mount: MountFn;
|
|
9
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Entry } from './types';
|
|
2
|
+
export type FlushTransformFunction = (entries: Entry[]) => Entry[];
|
|
3
|
+
/**
|
|
4
|
+
* Allows making changes to the JSON that will be written to the HAR file
|
|
5
|
+
*/
|
|
6
|
+
export declare function addFlushTransform(transform: FlushTransformFunction): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addFlushTransform = addFlushTransform;
|
|
4
|
+
const getPlaywrightCoreModule_1 = require("./getPlaywrightCoreModule");
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
+
function wrapHarRecorderMethods(HarRecorder, transform) {
|
|
7
|
+
const originalFlush = HarRecorder.prototype.flush;
|
|
8
|
+
if (originalFlush) {
|
|
9
|
+
HarRecorder.prototype.flush = function flush() {
|
|
10
|
+
if (transform) {
|
|
11
|
+
// Transform requests when transform function is present
|
|
12
|
+
this._entries = transform(this._entries);
|
|
13
|
+
}
|
|
14
|
+
// Call the original method
|
|
15
|
+
return originalFlush.call(this);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error('Can\'t find "flush" method in "HarRecorder" class.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
let patchInited = false;
|
|
23
|
+
function initHarRecorderPatch(transform) {
|
|
24
|
+
patchInited = true;
|
|
25
|
+
const modules = (0, getPlaywrightCoreModule_1.getPlaywrightCoreModule)('lib/server/har/harRecorder');
|
|
26
|
+
for (const module of modules) {
|
|
27
|
+
wrapHarRecorderMethods(module.HarRecorder, transform);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Allows making changes to the JSON that will be written to the HAR file
|
|
32
|
+
*/
|
|
33
|
+
function addFlushTransform(transform) {
|
|
34
|
+
if (!patchInited) {
|
|
35
|
+
initHarRecorderPatch(transform);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/har/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type { HarTransformFunction } from './addHarOpenTransform';
|
|
|
4
4
|
export { addHarOpenTransform } from './addHarOpenTransform';
|
|
5
5
|
export type { EntryTransformFunction } from './addHarRecorderTransform';
|
|
6
6
|
export { addHarRecorderTransform } from './addHarRecorderTransform';
|
|
7
|
+
export type { FlushTransformFunction } from './addFlushTransform';
|
|
8
|
+
export { addFlushTransform } from './addFlushTransform';
|
|
7
9
|
export { clearHeaders } from './clearHeaders';
|
|
8
10
|
export { initDumps } from './initDumps';
|
|
9
11
|
export { replaceBaseUrlInEntry } from './replaceBaseUrlInEntry';
|
package/har/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setExtraHash = exports.replaceBaseUrlInEntry = exports.initDumps = exports.clearHeaders = exports.addHarRecorderTransform = exports.addHarOpenTransform = exports.addHarLookupTransform = void 0;
|
|
3
|
+
exports.setExtraHash = exports.replaceBaseUrlInEntry = exports.initDumps = exports.clearHeaders = exports.addFlushTransform = exports.addHarRecorderTransform = exports.addHarOpenTransform = exports.addHarLookupTransform = void 0;
|
|
4
4
|
var addHarLookupTransform_1 = require("./addHarLookupTransform");
|
|
5
5
|
Object.defineProperty(exports, "addHarLookupTransform", { enumerable: true, get: function () { return addHarLookupTransform_1.addHarLookupTransform; } });
|
|
6
6
|
var addHarOpenTransform_1 = require("./addHarOpenTransform");
|
|
7
7
|
Object.defineProperty(exports, "addHarOpenTransform", { enumerable: true, get: function () { return addHarOpenTransform_1.addHarOpenTransform; } });
|
|
8
8
|
var addHarRecorderTransform_1 = require("./addHarRecorderTransform");
|
|
9
9
|
Object.defineProperty(exports, "addHarRecorderTransform", { enumerable: true, get: function () { return addHarRecorderTransform_1.addHarRecorderTransform; } });
|
|
10
|
+
var addFlushTransform_1 = require("./addFlushTransform");
|
|
11
|
+
Object.defineProperty(exports, "addFlushTransform", { enumerable: true, get: function () { return addFlushTransform_1.addFlushTransform; } });
|
|
10
12
|
var clearHeaders_1 = require("./clearHeaders");
|
|
11
13
|
Object.defineProperty(exports, "clearHeaders", { enumerable: true, get: function () { return clearHeaders_1.clearHeaders; } });
|
|
12
14
|
var initDumps_1 = require("./initDumps");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/playwright-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Tools for Playwright Test",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"./utils/**/*.*(js|d.ts)"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
+
"prepare": "husky",
|
|
38
39
|
"build": "tsc",
|
|
39
40
|
"clean": "find actions auth config data fixtures har utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
|
|
40
41
|
"typecheck": "tsc --noEmit",
|
|
@@ -54,21 +55,34 @@
|
|
|
54
55
|
"@gravity-ui/eslint-config": "^3.3.0",
|
|
55
56
|
"@gravity-ui/prettier-config": "^1.1.0",
|
|
56
57
|
"@jest/globals": "^29.7.0",
|
|
57
|
-
"@playwright/
|
|
58
|
+
"@playwright/experimental-ct-react": "^1.55.0",
|
|
59
|
+
"@playwright/test": "^1.55.0",
|
|
58
60
|
"@swc/core": "^1.11.5",
|
|
59
61
|
"@swc/jest": "^0.2.37",
|
|
60
62
|
"@types/jest": "^29.5.14",
|
|
61
63
|
"@types/node": "^20.17.9",
|
|
64
|
+
"@types/react": "^18.3.24",
|
|
62
65
|
"eslint": "^8.57.1",
|
|
66
|
+
"husky": "^9.1.7",
|
|
63
67
|
"jest": "^29.7.0",
|
|
68
|
+
"nano-staged": "^0.8.0",
|
|
64
69
|
"prettier": "^3.4.2",
|
|
65
70
|
"ts-jest": "^29.3.1",
|
|
66
71
|
"typescript": "^5.7.2"
|
|
67
72
|
},
|
|
68
73
|
"peerDependencies": {
|
|
74
|
+
"@playwright/experimental-ct-react": "^1.22",
|
|
69
75
|
"@playwright/test": "^1.22"
|
|
70
76
|
},
|
|
71
77
|
"engines": {
|
|
72
78
|
"node": ">=20"
|
|
79
|
+
},
|
|
80
|
+
"nano-staged": {
|
|
81
|
+
"*.{js,jsx,ts,tsx}": [
|
|
82
|
+
"eslint --fix --quiet"
|
|
83
|
+
],
|
|
84
|
+
"*.{md,mdx}": [
|
|
85
|
+
"prettier --write"
|
|
86
|
+
]
|
|
73
87
|
}
|
|
74
88
|
}
|
package/actions/mockDate.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Page } from '@playwright/test';
|
|
2
|
-
/**
|
|
3
|
-
* NOTE:
|
|
4
|
-
* Replaces the Date object with an object in which the date is set to the specified one.
|
|
5
|
-
*
|
|
6
|
-
* The date and time are not fixed, but go at the usual speed, but starting from the specified one.
|
|
7
|
-
*
|
|
8
|
-
* Use playwright API Clock https://playwright.dev/docs/clock
|
|
9
|
-
*/
|
|
10
|
-
export declare function mockDate(page: Page, year?: number, month?: number, day?: number, hour?: number, min?: number, sec?: number): Promise<void>;
|
package/actions/mockDate.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockDate = mockDate;
|
|
4
|
-
const path_1 = require("path");
|
|
5
|
-
const globalSettings_1 = require("../data/globalSettings");
|
|
6
|
-
/**
|
|
7
|
-
* NOTE:
|
|
8
|
-
* Replaces the Date object with an object in which the date is set to the specified one.
|
|
9
|
-
*
|
|
10
|
-
* The date and time are not fixed, but go at the usual speed, but starting from the specified one.
|
|
11
|
-
*
|
|
12
|
-
* Use playwright API Clock https://playwright.dev/docs/clock
|
|
13
|
-
*/
|
|
14
|
-
async function mockDate(page, year = globalSettings_1.globalSettings.mockDate.defaultDate.year, month = globalSettings_1.globalSettings.mockDate.defaultDate.month, day = globalSettings_1.globalSettings.mockDate.defaultDate.day, hour = globalSettings_1.globalSettings.mockDate.defaultDate.hour, min = globalSettings_1.globalSettings.mockDate.defaultDate.min, sec = globalSettings_1.globalSettings.mockDate.defaultDate.sec) {
|
|
15
|
-
await page.addInitScript({ path: (0, path_1.resolve)(require.resolve('timekeeper')) });
|
|
16
|
-
await page.addInitScript(({ year, month, day, hour, min, sec, }) => {
|
|
17
|
-
const date = new Date(year, month, day, hour, min, sec);
|
|
18
|
-
window.timekeeper.travel(date);
|
|
19
|
-
}, { year, month, day, hour, min, sec });
|
|
20
|
-
}
|