@gravity-ui/playwright-tools 0.4.1 → 0.7.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 +1 -0
- package/actions/index.d.ts +0 -1
- package/actions/index.js +1 -3
- package/actions/matchScreenshot.d.ts +1 -1
- package/actions/matchScreenshot.js +1 -1
- package/fixtures/index.d.ts +2 -0
- package/fixtures/index.js +4 -1
- 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/package.json +16 -2
- package/actions/mockDate.d.ts +0 -10
- package/actions/mockDate.js +0 -20
package/README.md
CHANGED
package/actions/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export { getGlobalSettings } from './getGlobalSettings';
|
|
|
10
10
|
export { getTestSlug } from './getTestSlug';
|
|
11
11
|
export { hasExtraHttpHeader } from './hasExtraHttpHeader';
|
|
12
12
|
export { matchScreenshot } from './matchScreenshot';
|
|
13
|
-
export { mockDate } from './mockDate';
|
|
14
13
|
export { removeExtraHttpHeader } from './removeExtraHttpHeader';
|
|
15
14
|
export { setCacheSettings } from './setCacheSettings';
|
|
16
15
|
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.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");
|
|
@@ -25,8 +25,6 @@ var hasExtraHttpHeader_1 = require("./hasExtraHttpHeader");
|
|
|
25
25
|
Object.defineProperty(exports, "hasExtraHttpHeader", { enumerable: true, get: function () { return hasExtraHttpHeader_1.hasExtraHttpHeader; } });
|
|
26
26
|
var matchScreenshot_1 = require("./matchScreenshot");
|
|
27
27
|
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
28
|
var removeExtraHttpHeader_1 = require("./removeExtraHttpHeader");
|
|
31
29
|
Object.defineProperty(exports, "removeExtraHttpHeader", { enumerable: true, get: function () { return removeExtraHttpHeader_1.removeExtraHttpHeader; } });
|
|
32
30
|
var setCacheSettings_1 = require("./setCacheSettings");
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Locator, Page, PageScreenshotOptions } from '@playwright/test';
|
|
2
2
|
export type Theme = 'light' | 'dark';
|
|
3
3
|
export type OnSwitchThemeCallback = (theme: Theme, page: Page) => Promise<void>;
|
|
4
|
-
export type OnBeforeScreenshotCallback = (page: Page) => Promise<void>;
|
|
5
4
|
export type ScreenshotOptions = Omit<PageScreenshotOptions, 'type' | 'quality' | 'path'> & {
|
|
6
5
|
/**
|
|
7
6
|
* An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is
|
|
@@ -20,6 +19,7 @@ export type ScreenshotOptions = Omit<PageScreenshotOptions, 'type' | 'quality' |
|
|
|
20
19
|
*/
|
|
21
20
|
threshold?: number;
|
|
22
21
|
};
|
|
22
|
+
export type OnBeforeScreenshotCallback = (page: Page, options: ScreenshotOptions) => Promise<void>;
|
|
23
23
|
export type MatchScreenshotOptions = {
|
|
24
24
|
/**
|
|
25
25
|
* The element or page to be screenshotted
|
|
@@ -45,7 +45,7 @@ async function matchScreenshot(page, { locator = page, name = globalSettings_1.g
|
|
|
45
45
|
}
|
|
46
46
|
await page.mouse.move(x, y);
|
|
47
47
|
}
|
|
48
|
-
await onBeforeScreenshot?.(page);
|
|
48
|
+
await onBeforeScreenshot?.(page, combinedOptions);
|
|
49
49
|
const slug = (0, getTestSlug_1.getTestSlug)(page);
|
|
50
50
|
await page.waitForTimeout(pause);
|
|
51
51
|
if (themes && themes.length) {
|
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; } });
|
|
@@ -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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/playwright-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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
|
-
}
|