@gravity-ui/playwright-tools 1.1.2 → 1.1.4-beta.114525d1176b54fc8177c759986ee94fa4516af0.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/actions/getTestSlug.js +1 -1
- package/actions/matchScreenshot.js +5 -7
- package/actions/setTestSlug.d.ts +2 -3
- package/actions/setTestSlug.js +6 -8
- package/component-tests/fixtures/mount/mount-fixture.d.ts +13 -0
- package/component-tests/fixtures/mount/mount-fixture.js +17 -10
- package/component-tests/fixtures/mount/mount-wrapper.d.ts +29 -0
- package/component-tests/fixtures/mount/mount-wrapper.js +66 -0
- package/data/globalSettings.js +2 -2
- package/fixtures/expect-request/expect-request-fixture.d.ts +3 -8
- package/fixtures/expect-request/expect-request-fixture.js +21 -23
- package/fixtures/expect-request/index.d.ts +2 -2
- package/fixtures/expect-request/index.js +2 -2
- package/fixtures/expect-request/types.d.ts +2 -0
- package/fixtures/expect-screenshot/expect-screenshot-fixture.d.ts +3 -5
- package/fixtures/expect-screenshot/expect-screenshot-fixture.js +8 -10
- package/fixtures/expect-screenshot/index.d.ts +2 -2
- package/fixtures/expect-screenshot/index.js +2 -2
- package/fixtures/expect-screenshot/types.d.ts +2 -0
- package/fixtures/index.d.ts +8 -8
- package/fixtures/index.js +6 -6
- package/fixtures/mock-network/index.d.ts +2 -2
- package/fixtures/mock-network/index.js +2 -2
- package/fixtures/mock-network/mock-network-fixture.d.ts +3 -6
- package/fixtures/mock-network/mock-network-fixture.js +23 -49
- package/fixtures/mock-network/types.d.ts +4 -8
- package/fixtures/test-slug/index.d.ts +2 -0
- package/fixtures/test-slug/index.js +5 -0
- package/fixtures/test-slug/test-slug-fixture.d.ts +3 -0
- package/fixtures/test-slug/test-slug-fixture.js +15 -0
- package/fixtures/test-slug/types.d.ts +6 -0
- package/fixtures/test-slug/types.js +2 -0
- package/package.json +2 -4
- package/fixtures/testSlug.d.ts +0 -12
- package/fixtures/testSlug.js +0 -19
package/actions/getTestSlug.js
CHANGED
|
@@ -9,5 +9,5 @@ function getTestSlug(page) {
|
|
|
9
9
|
if (testSlugs_1.testSlugs.has(page)) {
|
|
10
10
|
return testSlugs_1.testSlugs.get(page);
|
|
11
11
|
}
|
|
12
|
-
throw new Error("Can't find slug for test");
|
|
12
|
+
throw new Error("Can't find slug for test. Probably you need to add testSlug fixture to your test config");
|
|
13
13
|
}
|
|
@@ -46,7 +46,7 @@ async function matchScreenshot(page, { locator = page, name = globalSettings_1.g
|
|
|
46
46
|
await page.mouse.move(x, y);
|
|
47
47
|
}
|
|
48
48
|
await onBeforeScreenshot?.(page, combinedOptions);
|
|
49
|
-
const slug = (0, getTestSlug_1.getTestSlug)(page);
|
|
49
|
+
const slug = shouldPrependSlugToName ? (0, getTestSlug_1.getTestSlug)(page) : undefined;
|
|
50
50
|
await page.waitForTimeout(pause);
|
|
51
51
|
if (themes && themes.length) {
|
|
52
52
|
for (const theme of themes) {
|
|
@@ -57,7 +57,6 @@ async function matchScreenshot(page, { locator = page, name = globalSettings_1.g
|
|
|
57
57
|
name: resolvedName,
|
|
58
58
|
slug,
|
|
59
59
|
options: combinedOptions,
|
|
60
|
-
shouldPrependSlugToName,
|
|
61
60
|
soft,
|
|
62
61
|
});
|
|
63
62
|
}
|
|
@@ -68,7 +67,6 @@ async function matchScreenshot(page, { locator = page, name = globalSettings_1.g
|
|
|
68
67
|
name,
|
|
69
68
|
slug,
|
|
70
69
|
options: combinedOptions,
|
|
71
|
-
shouldPrependSlugToName,
|
|
72
70
|
soft,
|
|
73
71
|
});
|
|
74
72
|
}
|
|
@@ -78,8 +76,8 @@ async function matchScreenshot(page, { locator = page, name = globalSettings_1.g
|
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
78
|
async function doMatchScreenshot(params) {
|
|
81
|
-
const { locator, name, slug, options,
|
|
82
|
-
const resolvedName = resolveScreenshotName({ name, slug
|
|
79
|
+
const { locator, name, slug, options, soft } = params;
|
|
80
|
+
const resolvedName = resolveScreenshotName({ name, slug });
|
|
83
81
|
const resolvedExpect = soft ? test_1.expect.soft : test_1.expect;
|
|
84
82
|
if (resolvedName) {
|
|
85
83
|
await resolvedExpect(locator).toHaveScreenshot(resolvedName, options);
|
|
@@ -89,12 +87,12 @@ async function doMatchScreenshot(params) {
|
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
function resolveScreenshotName(params) {
|
|
92
|
-
const { name, slug
|
|
90
|
+
const { name, slug } = params;
|
|
93
91
|
if (!name) {
|
|
94
92
|
return undefined;
|
|
95
93
|
}
|
|
96
94
|
const resolvedName = [name + '.png'];
|
|
97
|
-
if (
|
|
95
|
+
if (slug) {
|
|
98
96
|
resolvedName.unshift(slug);
|
|
99
97
|
}
|
|
100
98
|
return resolvedName;
|
package/actions/setTestSlug.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Page } from '@playwright/test';
|
|
2
2
|
/**
|
|
3
|
-
* Sets the test slug
|
|
3
|
+
* Sets the test slug by extracting from title or generating from title
|
|
4
4
|
*
|
|
5
5
|
* @param page
|
|
6
6
|
* @param title The name of the test from which the slug will be extracted
|
|
7
|
-
* @param required Requires the slug to be specified in a specific way in the title (otherwise the title itself will be used)
|
|
8
7
|
*/
|
|
9
|
-
export declare function setTestSlug(page: Page, title: string
|
|
8
|
+
export declare function setTestSlug(page: Page, title: string): void;
|
package/actions/setTestSlug.js
CHANGED
|
@@ -4,19 +4,17 @@ exports.setTestSlug = setTestSlug;
|
|
|
4
4
|
const testSlugs_1 = require("../data/testSlugs");
|
|
5
5
|
const extractTestSlug_1 = require("../utils/extractTestSlug");
|
|
6
6
|
/**
|
|
7
|
-
* Sets the test slug
|
|
7
|
+
* Sets the test slug by extracting from title or generating from title
|
|
8
8
|
*
|
|
9
9
|
* @param page
|
|
10
10
|
* @param title The name of the test from which the slug will be extracted
|
|
11
|
-
* @param required Requires the slug to be specified in a specific way in the title (otherwise the title itself will be used)
|
|
12
11
|
*/
|
|
13
|
-
function setTestSlug(page, title
|
|
14
|
-
|
|
12
|
+
function setTestSlug(page, title) {
|
|
13
|
+
// Try to extract slug from [slug] pattern in title
|
|
14
|
+
let slug = (0, extractTestSlug_1.extractTestSlug)(title, true);
|
|
15
|
+
// Fallback: if extraction failed, use the generated slug from title
|
|
15
16
|
if (!slug) {
|
|
16
|
-
|
|
17
|
-
throw new Error(`Can't extract slug from title "${title}"`);
|
|
18
|
-
}
|
|
19
|
-
slug = title.replace(/<>:"\/\\\|\?\*/, '_');
|
|
17
|
+
slug = title.replace(/[<>:"/\\|?*]/g, '_');
|
|
20
18
|
}
|
|
21
19
|
testSlugs_1.testSlugs.set(page, slug);
|
|
22
20
|
}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
|
|
2
2
|
import type { MountFn, MountTestArgs } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Enhanced mount fixture that wraps components with styling and layout controls.
|
|
5
|
+
*
|
|
6
|
+
* This fixture intercepts the base mount function to:
|
|
7
|
+
* 1. Always wrap components in a div with TEST_WRAPPER_CLASS for screenshot targeting
|
|
8
|
+
* 2. Apply padding and fit-content sizing for better visual testing
|
|
9
|
+
* 3. Disable CSS transform animations that can cause flaky screenshots
|
|
10
|
+
* 4. Support custom width and rootStyle options
|
|
11
|
+
*
|
|
12
|
+
* The wrapper is inlined using string element types ('div', 'style') because
|
|
13
|
+
* Playwright blocks function components defined in test context. See mount-wrapper.ts
|
|
14
|
+
* for more details on this restriction.
|
|
15
|
+
*/
|
|
3
16
|
export declare const mountFixture: TestFixture<MountFn, PlaywrightTestArgs & PlaywrightTestOptions & MountTestArgs>;
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mountFixture = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const mount_wrapper_1 = require("./mount-wrapper");
|
|
5
|
+
/**
|
|
6
|
+
* Enhanced mount fixture that wraps components with styling and layout controls.
|
|
7
|
+
*
|
|
8
|
+
* This fixture intercepts the base mount function to:
|
|
9
|
+
* 1. Always wrap components in a div with TEST_WRAPPER_CLASS for screenshot targeting
|
|
10
|
+
* 2. Apply padding and fit-content sizing for better visual testing
|
|
11
|
+
* 3. Disable CSS transform animations that can cause flaky screenshots
|
|
12
|
+
* 4. Support custom width and rootStyle options
|
|
13
|
+
*
|
|
14
|
+
* The wrapper is inlined using string element types ('div', 'style') because
|
|
15
|
+
* Playwright blocks function components defined in test context. See mount-wrapper.ts
|
|
16
|
+
* for more details on this restriction.
|
|
17
|
+
*/
|
|
6
18
|
const mountFixture = async ({ mount: baseMount }, use) => {
|
|
7
19
|
const mount = async (component, options) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
20
|
+
const { width, rootStyle, ...baseMountOptions } = options || {};
|
|
21
|
+
const wrapper = (0, mount_wrapper_1.createComponentWrapper)(component, { width, rootStyle });
|
|
22
|
+
return await baseMount(wrapper, baseMountOptions);
|
|
16
23
|
};
|
|
17
24
|
await use(mount);
|
|
18
25
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Playwright JSX object structure that mimics Playwright's jsx-runtime output.
|
|
4
|
+
* This is the internal structure Playwright expects when mounting components.
|
|
5
|
+
*/
|
|
6
|
+
type PlaywrightJsxObject<T extends keyof React.JSX.IntrinsicElements> = {
|
|
7
|
+
__pw_type: 'jsx';
|
|
8
|
+
type: T;
|
|
9
|
+
props: React.JSX.IntrinsicElements[T];
|
|
10
|
+
key: string | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Creates a wrapper around a component with styling and animation controls.
|
|
14
|
+
*
|
|
15
|
+
* This wrapper:
|
|
16
|
+
* 1. Wraps component in a div with TEST_WRAPPER_CLASS for screenshot targeting
|
|
17
|
+
* 2. Applies padding and fit-content sizing for better visual testing
|
|
18
|
+
* 3. Injects global styles to disable CSS transform animations
|
|
19
|
+
* 4. Supports custom width and rootStyle options
|
|
20
|
+
*
|
|
21
|
+
* The wrapper uses only string element types ('div', 'style') because
|
|
22
|
+
* Playwright blocks function components defined in test context.
|
|
23
|
+
* See createPlaywrightJsxObject documentation for details.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createComponentWrapper(component: React.JSX.Element, options?: {
|
|
26
|
+
width?: number | string;
|
|
27
|
+
rootStyle?: React.CSSProperties;
|
|
28
|
+
}): PlaywrightJsxObject<"div">;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createComponentWrapper = createComponentWrapper;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a Playwright JSX object representation.
|
|
7
|
+
*
|
|
8
|
+
* Playwright expects JSX components in a special format with __pw_type: 'jsx'.
|
|
9
|
+
* This mimics what Playwright's jsx-runtime creates when you write JSX in test files.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: The `type` parameter MUST be either:
|
|
12
|
+
* - A string (HTML element name like 'div', 'span', 'style')
|
|
13
|
+
* - An import reference resolved by Playwright's import registry
|
|
14
|
+
*
|
|
15
|
+
* Function references are explicitly blocked by Playwright's serializers.js:
|
|
16
|
+
* "if (value?.__pw_type === 'jsx' && typeof value.type === 'function')"
|
|
17
|
+
* This prevents components defined in test context from being mounted.
|
|
18
|
+
*
|
|
19
|
+
* That's why we use only string types (like 'div', 'style')
|
|
20
|
+
* instead of function component references.
|
|
21
|
+
*
|
|
22
|
+
* @template T - The HTML element type (e.g., 'div', 'span', 'style')
|
|
23
|
+
* @param type - HTML element name
|
|
24
|
+
* @param props - Props for the HTML element
|
|
25
|
+
* @returns A Playwright JSX object compatible with React.JSX.Element
|
|
26
|
+
*/
|
|
27
|
+
function createPlaywrightJsxObject(type, props) {
|
|
28
|
+
return {
|
|
29
|
+
__pw_type: 'jsx',
|
|
30
|
+
type,
|
|
31
|
+
props,
|
|
32
|
+
key: null, // Must be null (not undefined) to match React.JSX.Element type
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a wrapper around a component with styling and animation controls.
|
|
37
|
+
*
|
|
38
|
+
* This wrapper:
|
|
39
|
+
* 1. Wraps component in a div with TEST_WRAPPER_CLASS for screenshot targeting
|
|
40
|
+
* 2. Applies padding and fit-content sizing for better visual testing
|
|
41
|
+
* 3. Injects global styles to disable CSS transform animations
|
|
42
|
+
* 4. Supports custom width and rootStyle options
|
|
43
|
+
*
|
|
44
|
+
* The wrapper uses only string element types ('div', 'style') because
|
|
45
|
+
* Playwright blocks function components defined in test context.
|
|
46
|
+
* See createPlaywrightJsxObject documentation for details.
|
|
47
|
+
*/
|
|
48
|
+
function createComponentWrapper(component, options) {
|
|
49
|
+
const { width, rootStyle } = options || {};
|
|
50
|
+
const styleElement = createPlaywrightJsxObject('style', {
|
|
51
|
+
children: '.g-button, .g-button::after { transform: scale(1) !important; }',
|
|
52
|
+
});
|
|
53
|
+
const wrapper = createPlaywrightJsxObject('div', {
|
|
54
|
+
style: {
|
|
55
|
+
padding: 20,
|
|
56
|
+
// When width is set, padding should not affect total width
|
|
57
|
+
boxSizing: width ? 'content-box' : undefined,
|
|
58
|
+
width: width ? width : 'fit-content',
|
|
59
|
+
height: 'fit-content',
|
|
60
|
+
...rootStyle,
|
|
61
|
+
},
|
|
62
|
+
className: constants_1.TEST_WRAPPER_CLASS,
|
|
63
|
+
children: [styleElement, component],
|
|
64
|
+
});
|
|
65
|
+
return wrapper;
|
|
66
|
+
}
|
package/data/globalSettings.js
CHANGED
|
@@ -49,11 +49,11 @@ exports.globalSettings = {
|
|
|
49
49
|
/**
|
|
50
50
|
* Default screenshot name
|
|
51
51
|
*/
|
|
52
|
-
name:
|
|
52
|
+
name: undefined,
|
|
53
53
|
/**
|
|
54
54
|
* Should I add a slug to the screenshot file name?
|
|
55
55
|
*/
|
|
56
|
-
shouldPrependSlugToName:
|
|
56
|
+
shouldPrependSlugToName: false,
|
|
57
57
|
/**
|
|
58
58
|
* Topics that require a screenshot
|
|
59
59
|
* By default, screenshots are taken for the current theme. Switching does not occur
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type { PlaywrightTestArgs, PlaywrightTestOptions,
|
|
2
|
-
import type {
|
|
3
|
-
export declare
|
|
4
|
-
declare const fixtureOptions: {
|
|
5
|
-
readonly scope: "test";
|
|
6
|
-
};
|
|
7
|
-
export declare const expectRequest: [typeof expectRequestFixture, typeof fixtureOptions];
|
|
8
|
-
export {};
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
import type { ExpectRequestFixturesBuilderParams, ExpectRequestTestArgs, ExpectRequestWorkerArgs } from './types';
|
|
3
|
+
export declare function expectRequestFixturesBuilder(_params?: ExpectRequestFixturesBuilderParams): Fixtures<ExpectRequestTestArgs, ExpectRequestWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.expectRequestFixturesBuilder = expectRequestFixturesBuilder;
|
|
4
4
|
const expect_request_1 = require("../../actions/expect-request");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fixtureOptions,
|
|
26
|
-
];
|
|
5
|
+
function expectRequestFixturesBuilder(_params = {}) {
|
|
6
|
+
const expectRequestFixture = async ({ page, baseURL }, use) => {
|
|
7
|
+
if (!baseURL) {
|
|
8
|
+
throw new Error('Base URL required for requests matching!');
|
|
9
|
+
}
|
|
10
|
+
const requests = new Map();
|
|
11
|
+
page.on('request', (request) => {
|
|
12
|
+
const url = new URL(request.url());
|
|
13
|
+
const key = `${url.protocol}//${url.hostname}${url.pathname}`;
|
|
14
|
+
requests.set(key, request);
|
|
15
|
+
});
|
|
16
|
+
const boundExpectRequest = expect_request_1.expectRequest.bind(null, requests);
|
|
17
|
+
await use(boundExpectRequest);
|
|
18
|
+
requests.clear();
|
|
19
|
+
};
|
|
20
|
+
const fixtures = {
|
|
21
|
+
expectRequest: [expectRequestFixture, { scope: 'test' }],
|
|
22
|
+
};
|
|
23
|
+
return fixtures;
|
|
24
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { ExpectRequestFn, ExpectRequestTestArgs } from './types';
|
|
1
|
+
export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestWorkerArgs, ExpectRequestFixturesBuilderParams, } from './types';
|
|
2
2
|
export type { ExpectRequestFnMatcher, ExpectRequestFnOptions } from '../../actions/expect-request';
|
|
3
|
-
export {
|
|
3
|
+
export { expectRequestFixturesBuilder } from './expect-request-fixture';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.expectRequestFixturesBuilder = void 0;
|
|
4
4
|
var expect_request_fixture_1 = require("./expect-request-fixture");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "expectRequestFixturesBuilder", { enumerable: true, get: function () { return expect_request_fixture_1.expectRequestFixturesBuilder; } });
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { PlaywrightTestArgs, PlaywrightTestOptions,
|
|
2
|
-
import type { ExpectScreenshotFixtureBuilderParams,
|
|
3
|
-
export declare function
|
|
4
|
-
scope: "test";
|
|
5
|
-
}];
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
import type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotTestArgs, ExpectScreenshotWorkerArgs } from './types';
|
|
3
|
+
export declare function expectScreenshotFixturesBuilder({ screenshotOptions, getDefaultMask, getDefaultLocator, ...restDefaults }?: ExpectScreenshotFixtureBuilderParams): Fixtures<ExpectScreenshotTestArgs, ExpectScreenshotWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.expectScreenshotFixturesBuilder = expectScreenshotFixturesBuilder;
|
|
4
4
|
const matchScreenshot_1 = require("../../actions/matchScreenshot");
|
|
5
|
-
function
|
|
5
|
+
function expectScreenshotFixturesBuilder({ screenshotOptions, getDefaultMask, getDefaultLocator, ...restDefaults } = {}) {
|
|
6
6
|
const expectScreenshotFixture = async ({ page }, use) => {
|
|
7
|
-
const expectScreenshot = ({ options = {}, shouldUseDefaultMask = true, ...restParams } = {}) => {
|
|
7
|
+
const expectScreenshot = ({ options = {}, shouldUseDefaultMask = true, locator, ...restParams } = {}) => {
|
|
8
8
|
const { mask = [] } = options;
|
|
9
9
|
const defaultMask = shouldUseDefaultMask && getDefaultMask ? getDefaultMask(page) : [];
|
|
10
10
|
const maskToUse = [...mask, ...defaultMask];
|
|
11
|
+
const locatorToUse = locator ?? getDefaultLocator?.(page);
|
|
11
12
|
const mergedOptions = {
|
|
12
13
|
options: { ...screenshotOptions, ...options, mask: maskToUse },
|
|
14
|
+
locator: locatorToUse,
|
|
13
15
|
...restDefaults,
|
|
14
16
|
...restParams,
|
|
15
17
|
};
|
|
@@ -17,12 +19,8 @@ function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...
|
|
|
17
19
|
};
|
|
18
20
|
await use(expectScreenshot);
|
|
19
21
|
};
|
|
20
|
-
const
|
|
21
|
-
scope: 'test',
|
|
22
|
+
const fixtures = {
|
|
23
|
+
expectScreenshot: [expectScreenshotFixture, { scope: 'test' }],
|
|
22
24
|
};
|
|
23
|
-
|
|
24
|
-
expectScreenshotFixture,
|
|
25
|
-
fixtureOptions,
|
|
26
|
-
];
|
|
27
|
-
return expectScreenshot;
|
|
25
|
+
return fixtures;
|
|
28
26
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn, ExpectScreenshotTestArgs, } from './types';
|
|
1
|
+
export { expectScreenshotFixturesBuilder } from './expect-screenshot-fixture';
|
|
2
|
+
export type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotWorkerArgs, } from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.expectScreenshotFixturesBuilder = void 0;
|
|
4
4
|
var expect_screenshot_fixture_1 = require("./expect-screenshot-fixture");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "expectScreenshotFixturesBuilder", { enumerable: true, get: function () { return expect_screenshot_fixture_1.expectScreenshotFixturesBuilder; } });
|
|
@@ -7,8 +7,10 @@ export type ExpectScreenshotOptions = MatchScreenshotOptions & {
|
|
|
7
7
|
export type ExpectScreenshotFixtureBuilderParams = Pick<MatchScreenshotOptions, 'hideBySelector' | 'pause' | 'soft' | 'shouldPrependSlugToName' | 'themes' | 'onBeforeScreenshot' | 'onSwitchTheme'> & {
|
|
8
8
|
screenshotOptions?: DefaultScreenshotOptions;
|
|
9
9
|
getDefaultMask?: (page: Page) => Locator[];
|
|
10
|
+
getDefaultLocator?: (page: Page) => Locator | Page;
|
|
10
11
|
};
|
|
11
12
|
export type ExpectScreenshotFn = (params?: ExpectScreenshotOptions) => Promise<void>;
|
|
12
13
|
export type ExpectScreenshotTestArgs = {
|
|
13
14
|
expectScreenshot: ExpectScreenshotFn;
|
|
14
15
|
};
|
|
16
|
+
export type ExpectScreenshotWorkerArgs = {};
|
package/fixtures/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type { TestSlugResult } from './
|
|
2
|
-
export {
|
|
3
|
-
export type { MockNetworkFixtureBuilderParams } from './mock-network';
|
|
4
|
-
export {
|
|
5
|
-
export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestFnMatcher, ExpectRequestFnOptions, } from './expect-request';
|
|
6
|
-
export {
|
|
7
|
-
export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotFixtureBuilderParams, } from './expect-screenshot';
|
|
8
|
-
export {
|
|
1
|
+
export type { TestSlugFixturesBuilderParams, TestSlugResult, TestSlugTestArgs, TestSlugWorkerArgs, } from './test-slug';
|
|
2
|
+
export { testSlugFixturesBuilder } from './test-slug';
|
|
3
|
+
export type { MockNetworkFixtureBuilderParams, MockNetworkTestArgs, MockNetworkWorkerArgs, } from './mock-network';
|
|
4
|
+
export { mockNetworkFixturesBuilder } from './mock-network';
|
|
5
|
+
export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestWorkerArgs, ExpectRequestFixturesBuilderParams, ExpectRequestFnMatcher, ExpectRequestFnOptions, } from './expect-request';
|
|
6
|
+
export { expectRequestFixturesBuilder } from './expect-request';
|
|
7
|
+
export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotWorkerArgs, ExpectScreenshotFixtureBuilderParams, } from './expect-screenshot';
|
|
8
|
+
export { expectScreenshotFixturesBuilder } from './expect-screenshot';
|
|
9
9
|
export type { GlobalSettingsFixturesBuilderParams, GlobalSettingsTestArgs, GlobalSettingsWorkerArgs, } from './global-settings';
|
|
10
10
|
export { globalSettingsFixturesBuilder } from './global-settings';
|
package/fixtures/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.globalSettingsFixturesBuilder = exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.globalSettingsFixturesBuilder = exports.expectScreenshotFixturesBuilder = exports.expectRequestFixturesBuilder = exports.mockNetworkFixturesBuilder = exports.testSlugFixturesBuilder = void 0;
|
|
4
|
+
var test_slug_1 = require("./test-slug");
|
|
5
|
+
Object.defineProperty(exports, "testSlugFixturesBuilder", { enumerable: true, get: function () { return test_slug_1.testSlugFixturesBuilder; } });
|
|
6
6
|
var mock_network_1 = require("./mock-network");
|
|
7
|
-
Object.defineProperty(exports, "
|
|
7
|
+
Object.defineProperty(exports, "mockNetworkFixturesBuilder", { enumerable: true, get: function () { return mock_network_1.mockNetworkFixturesBuilder; } });
|
|
8
8
|
var expect_request_1 = require("./expect-request");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
9
|
+
Object.defineProperty(exports, "expectRequestFixturesBuilder", { enumerable: true, get: function () { return expect_request_1.expectRequestFixturesBuilder; } });
|
|
10
10
|
var expect_screenshot_1 = require("./expect-screenshot");
|
|
11
|
-
Object.defineProperty(exports, "
|
|
11
|
+
Object.defineProperty(exports, "expectScreenshotFixturesBuilder", { enumerable: true, get: function () { return expect_screenshot_1.expectScreenshotFixturesBuilder; } });
|
|
12
12
|
var global_settings_1 = require("./global-settings");
|
|
13
13
|
Object.defineProperty(exports, "globalSettingsFixturesBuilder", { enumerable: true, get: function () { return global_settings_1.globalSettingsFixturesBuilder; } });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { MockNetworkFixtureBuilderParams } from './types';
|
|
1
|
+
export { mockNetworkFixturesBuilder } from './mock-network-fixture';
|
|
2
|
+
export type { MockNetworkFixtureBuilderParams, MockNetworkTestArgs, MockNetworkWorkerArgs, } from './types';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mockNetworkFixturesBuilder = void 0;
|
|
4
4
|
var mock_network_fixture_1 = require("./mock-network-fixture");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "mockNetworkFixturesBuilder", { enumerable: true, get: function () { return mock_network_fixture_1.mockNetworkFixturesBuilder; } });
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type { PlaywrightTestArgs, PlaywrightTestOptions,
|
|
2
|
-
import type { MockNetworkFixtureBuilderParams } from './types';
|
|
3
|
-
export declare function
|
|
4
|
-
auto: boolean;
|
|
5
|
-
scope: "test";
|
|
6
|
-
}];
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
import type { MockNetworkFixtureBuilderParams, MockNetworkTestArgs, MockNetworkWorkerArgs } from './types';
|
|
3
|
+
export declare function mockNetworkFixturesBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }: MockNetworkFixtureBuilderParams): Fixtures<MockNetworkTestArgs, MockNetworkWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
@@ -1,62 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.mockNetworkFixturesBuilder = mockNetworkFixturesBuilder;
|
|
4
4
|
const har_1 = require("../../har");
|
|
5
5
|
const har_patcher_1 = require("./har-patcher");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
throw new Error('baseURL should be specified in playwright config');
|
|
9
|
-
}
|
|
10
|
-
const baseURL = rawBaseURL.replace(/\/+$/, '');
|
|
11
|
-
(0, har_patcher_1.harPatcher)({
|
|
12
|
-
baseURL,
|
|
13
|
-
...harPatcherParams,
|
|
14
|
-
});
|
|
15
|
-
const update = Boolean(shouldUpdate);
|
|
16
|
-
const url = urlMatcherBuilder(baseURL);
|
|
17
|
-
const finalUpdate = await (0, har_1.initDumps)(page, testInfo, {
|
|
18
|
-
dumpsFilePath,
|
|
19
|
-
forceUpdateIfHarMissing,
|
|
20
|
-
updateTimeout,
|
|
21
|
-
update,
|
|
22
|
-
url,
|
|
23
|
-
zip,
|
|
24
|
-
});
|
|
25
|
-
await use(!finalUpdate);
|
|
26
|
-
};
|
|
27
|
-
function mockNetworkFixtureBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url, dumpsFilePath, optionallyEnabled, ...harPatcherParams }) {
|
|
28
|
-
const mockNetworkFixture = async ({ baseURL, page }, use, testInfo) => {
|
|
29
|
-
return fixtureFunction({ baseURL, page }, {
|
|
30
|
-
shouldUpdate,
|
|
31
|
-
forceUpdateIfHarMissing,
|
|
32
|
-
updateTimeout,
|
|
33
|
-
zip,
|
|
34
|
-
url,
|
|
35
|
-
dumpsFilePath,
|
|
36
|
-
...harPatcherParams,
|
|
37
|
-
}, use, testInfo);
|
|
38
|
-
};
|
|
39
|
-
const mockNetworkFixtureWithOptionalParam = async ({ baseURL, page, enableNetworkMocking }, use, testInfo) => {
|
|
6
|
+
function mockNetworkFixturesBuilder({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }) {
|
|
7
|
+
const isMockingEnabledFixture = async ({ baseURL: rawBaseURL, page, enableNetworkMocking }, use, testInfo) => {
|
|
40
8
|
if (!enableNetworkMocking) {
|
|
41
9
|
return use(false);
|
|
42
10
|
}
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
if (!rawBaseURL) {
|
|
12
|
+
throw new Error('baseURL should be specified in playwright config');
|
|
13
|
+
}
|
|
14
|
+
const baseURL = rawBaseURL.replace(/\/+$/, '');
|
|
15
|
+
(0, har_patcher_1.harPatcher)({
|
|
16
|
+
baseURL,
|
|
17
|
+
...harPatcherParams,
|
|
18
|
+
});
|
|
19
|
+
const update = Boolean(shouldUpdate);
|
|
20
|
+
const url = urlMatcherBuilder(baseURL);
|
|
21
|
+
const finalUpdate = await (0, har_1.initDumps)(page, testInfo, {
|
|
22
|
+
dumpsFilePath,
|
|
45
23
|
forceUpdateIfHarMissing,
|
|
46
24
|
updateTimeout,
|
|
47
|
-
|
|
25
|
+
update,
|
|
48
26
|
url,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
zip,
|
|
28
|
+
});
|
|
29
|
+
await use(!finalUpdate);
|
|
52
30
|
};
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
scope: 'test',
|
|
31
|
+
const fixtures = {
|
|
32
|
+
enableNetworkMocking: [true, { scope: 'test', option: true }],
|
|
33
|
+
isMockingEnabled: [isMockingEnabledFixture, { scope: 'test', auto: true }],
|
|
56
34
|
};
|
|
57
|
-
|
|
58
|
-
optionallyEnabled ? mockNetworkFixtureWithOptionalParam : mockNetworkFixture,
|
|
59
|
-
fixtureOptions,
|
|
60
|
-
];
|
|
61
|
-
return mockNetwork;
|
|
35
|
+
return fixtures;
|
|
62
36
|
}
|
|
@@ -77,12 +77,6 @@ export type MockNetworkFixtureBuilderParams = {
|
|
|
77
77
|
* @param baseURL The base URL of the test
|
|
78
78
|
*/
|
|
79
79
|
onTransformHarLookupResult?: (result: Parameters<HarLookupResultTransformFunction>[0], params: Parameters<HarLookupResultTransformFunction>[1], baseURL: string) => ReturnType<HarLookupResultTransformFunction>;
|
|
80
|
-
/**
|
|
81
|
-
* Allow optionally enable fixture.
|
|
82
|
-
* Set "enableNetworkMocking" fixture to turn on/off network mocking
|
|
83
|
-
* @defaultValue false `
|
|
84
|
-
*/
|
|
85
|
-
optionallyEnabled?: boolean;
|
|
86
80
|
/**
|
|
87
81
|
* Flag to enable or disable adding the x-tests-duplicate-id header for identical requests
|
|
88
82
|
* By default, the header is not added
|
|
@@ -90,6 +84,8 @@ export type MockNetworkFixtureBuilderParams = {
|
|
|
90
84
|
*/
|
|
91
85
|
shouldMarkIdenticalRequests?: boolean;
|
|
92
86
|
};
|
|
93
|
-
export type
|
|
94
|
-
enableNetworkMocking
|
|
87
|
+
export type MockNetworkTestArgs = {
|
|
88
|
+
enableNetworkMocking: boolean;
|
|
89
|
+
isMockingEnabled: boolean;
|
|
95
90
|
};
|
|
91
|
+
export type MockNetworkWorkerArgs = {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testSlugFixturesBuilder = void 0;
|
|
4
|
+
var test_slug_fixture_1 = require("./test-slug-fixture");
|
|
5
|
+
Object.defineProperty(exports, "testSlugFixturesBuilder", { enumerable: true, get: function () { return test_slug_fixture_1.testSlugFixturesBuilder; } });
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
|
|
2
|
+
import type { TestSlugFixturesBuilderParams, TestSlugTestArgs, TestSlugWorkerArgs } from './types';
|
|
3
|
+
export declare function testSlugFixturesBuilder(_params?: TestSlugFixturesBuilderParams): Fixtures<TestSlugTestArgs, TestSlugWorkerArgs, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testSlugFixturesBuilder = testSlugFixturesBuilder;
|
|
4
|
+
const actions_1 = require("../../actions");
|
|
5
|
+
function testSlugFixturesBuilder(_params = {}) {
|
|
6
|
+
const testSlugFixture = async ({ page }, use, testInfo) => {
|
|
7
|
+
(0, actions_1.setTestSlug)(page, testInfo.title);
|
|
8
|
+
const slug = (0, actions_1.getTestSlug)(page);
|
|
9
|
+
await use(slug);
|
|
10
|
+
};
|
|
11
|
+
const fixtures = {
|
|
12
|
+
testSlug: [testSlugFixture, { auto: true }],
|
|
13
|
+
};
|
|
14
|
+
return fixtures;
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/playwright-tools",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-beta.114525d1176b54fc8177c759986ee94fa4516af0.0",
|
|
4
4
|
"description": "Tools for Playwright Test",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"playwright",
|
|
@@ -100,9 +100,7 @@
|
|
|
100
100
|
},
|
|
101
101
|
"peerDependencies": {
|
|
102
102
|
"@playwright/experimental-ct-react": "^1.22",
|
|
103
|
-
"@playwright/test": "^1.22"
|
|
104
|
-
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
105
|
-
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
103
|
+
"@playwright/test": "^1.22"
|
|
106
104
|
},
|
|
107
105
|
"engines": {
|
|
108
106
|
"node": ">=20"
|
package/fixtures/testSlug.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { TestFixture } from '@playwright/test';
|
|
2
|
-
import type { PlaywrightTestArgsBase } from './types';
|
|
3
|
-
export type TestSlugResult = string;
|
|
4
|
-
declare const testSlugValue: TestFixture<TestSlugResult, PlaywrightTestArgsBase>;
|
|
5
|
-
declare const fixtureOptions: {
|
|
6
|
-
auto: boolean;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Automatically sets and adds the current slug value for the test to the test fixtures
|
|
10
|
-
*/
|
|
11
|
-
export declare const testSlug: [typeof testSlugValue, typeof fixtureOptions];
|
|
12
|
-
export {};
|
package/fixtures/testSlug.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.testSlug = void 0;
|
|
4
|
-
const actions_1 = require("../actions");
|
|
5
|
-
const testSlugValue = async ({ page }, use, testInfo) => {
|
|
6
|
-
(0, actions_1.setTestSlug)(page, testInfo.title, true);
|
|
7
|
-
const slug = (0, actions_1.getTestSlug)(page);
|
|
8
|
-
await use(slug);
|
|
9
|
-
};
|
|
10
|
-
const fixtureOptions = {
|
|
11
|
-
auto: true,
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Automatically sets and adds the current slug value for the test to the test fixtures
|
|
15
|
-
*/
|
|
16
|
-
exports.testSlug = [
|
|
17
|
-
testSlugValue,
|
|
18
|
-
fixtureOptions,
|
|
19
|
-
];
|