@gravity-ui/playwright-tools 1.1.3 → 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.
Files changed (31) hide show
  1. package/actions/getTestSlug.js +1 -1
  2. package/actions/matchScreenshot.js +5 -7
  3. package/actions/setTestSlug.d.ts +2 -3
  4. package/actions/setTestSlug.js +6 -8
  5. package/data/globalSettings.js +2 -2
  6. package/fixtures/expect-request/expect-request-fixture.d.ts +3 -8
  7. package/fixtures/expect-request/expect-request-fixture.js +21 -23
  8. package/fixtures/expect-request/index.d.ts +2 -2
  9. package/fixtures/expect-request/index.js +2 -2
  10. package/fixtures/expect-request/types.d.ts +2 -0
  11. package/fixtures/expect-screenshot/expect-screenshot-fixture.d.ts +3 -5
  12. package/fixtures/expect-screenshot/expect-screenshot-fixture.js +8 -10
  13. package/fixtures/expect-screenshot/index.d.ts +2 -2
  14. package/fixtures/expect-screenshot/index.js +2 -2
  15. package/fixtures/expect-screenshot/types.d.ts +2 -0
  16. package/fixtures/index.d.ts +8 -8
  17. package/fixtures/index.js +6 -6
  18. package/fixtures/mock-network/index.d.ts +2 -2
  19. package/fixtures/mock-network/index.js +2 -2
  20. package/fixtures/mock-network/mock-network-fixture.d.ts +3 -6
  21. package/fixtures/mock-network/mock-network-fixture.js +23 -49
  22. package/fixtures/mock-network/types.d.ts +4 -8
  23. package/fixtures/test-slug/index.d.ts +2 -0
  24. package/fixtures/test-slug/index.js +5 -0
  25. package/fixtures/test-slug/test-slug-fixture.d.ts +3 -0
  26. package/fixtures/test-slug/test-slug-fixture.js +15 -0
  27. package/fixtures/test-slug/types.d.ts +6 -0
  28. package/fixtures/test-slug/types.js +2 -0
  29. package/package.json +1 -1
  30. package/fixtures/testSlug.d.ts +0 -12
  31. package/fixtures/testSlug.js +0 -19
@@ -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, shouldPrependSlugToName, soft } = params;
82
- const resolvedName = resolveScreenshotName({ name, slug, shouldPrependSlugToName });
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, shouldPrependSlugToName } = params;
90
+ const { name, slug } = params;
93
91
  if (!name) {
94
92
  return undefined;
95
93
  }
96
94
  const resolvedName = [name + '.png'];
97
- if (shouldPrependSlugToName) {
95
+ if (slug) {
98
96
  resolvedName.unshift(slug);
99
97
  }
100
98
  return resolvedName;
@@ -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, required?: boolean): void;
8
+ export declare function setTestSlug(page: Page, title: string): void;
@@ -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, required = false) {
14
- let slug = (0, extractTestSlug_1.extractTestSlug)(title, !required);
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
- if (required) {
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
  }
@@ -49,11 +49,11 @@ exports.globalSettings = {
49
49
  /**
50
50
  * Default screenshot name
51
51
  */
52
- name: 'plain',
52
+ name: undefined,
53
53
  /**
54
54
  * Should I add a slug to the screenshot file name?
55
55
  */
56
- shouldPrependSlugToName: true,
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, TestFixture } from '@playwright/test';
2
- import type { ExpectRequestFn } from './types';
3
- export declare const expectRequestFixture: TestFixture<ExpectRequestFn, PlaywrightTestOptions & PlaywrightTestArgs>;
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.expectRequest = exports.expectRequestFixture = void 0;
3
+ exports.expectRequestFixturesBuilder = expectRequestFixturesBuilder;
4
4
  const expect_request_1 = require("../../actions/expect-request");
5
- const expectRequestFixture = async ({ page, baseURL }, use) => {
6
- if (!baseURL) {
7
- throw new Error('Base URL required for requests matching!');
8
- }
9
- const requests = new Map();
10
- page.on('request', (request) => {
11
- const url = new URL(request.url());
12
- const key = `${url.protocol}//${url.hostname}${url.pathname}`;
13
- requests.set(key, request);
14
- });
15
- const boundExpectRequest = expect_request_1.expectRequest.bind(null, requests);
16
- await use(boundExpectRequest);
17
- requests.clear();
18
- };
19
- exports.expectRequestFixture = expectRequestFixture;
20
- const fixtureOptions = {
21
- scope: 'test',
22
- };
23
- exports.expectRequest = [
24
- exports.expectRequestFixture,
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 { expectRequest } from './expect-request-fixture';
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.expectRequest = void 0;
3
+ exports.expectRequestFixturesBuilder = void 0;
4
4
  var expect_request_fixture_1 = require("./expect-request-fixture");
5
- Object.defineProperty(exports, "expectRequest", { enumerable: true, get: function () { return expect_request_fixture_1.expectRequest; } });
5
+ Object.defineProperty(exports, "expectRequestFixturesBuilder", { enumerable: true, get: function () { return expect_request_fixture_1.expectRequestFixturesBuilder; } });
@@ -3,3 +3,5 @@ export type ExpectRequestFn = (url: string | RegExp, matcher?: ExpectRequestFnMa
3
3
  export interface ExpectRequestTestArgs {
4
4
  expectRequest: ExpectRequestFn;
5
5
  }
6
+ export type ExpectRequestWorkerArgs = {};
7
+ export type ExpectRequestFixturesBuilderParams = {};
@@ -1,5 +1,3 @@
1
- import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
2
- import type { ExpectScreenshotFixtureBuilderParams, ExpectScreenshotFn } from './types';
3
- export declare function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults }?: ExpectScreenshotFixtureBuilderParams): [TestFixture<ExpectScreenshotFn, PlaywrightTestArgs & PlaywrightTestOptions>, {
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.expectScreenshotFixtureBuilder = expectScreenshotFixtureBuilder;
3
+ exports.expectScreenshotFixturesBuilder = expectScreenshotFixturesBuilder;
4
4
  const matchScreenshot_1 = require("../../actions/matchScreenshot");
5
- function expectScreenshotFixtureBuilder({ screenshotOptions, getDefaultMask, ...restDefaults } = {}) {
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 fixtureOptions = {
21
- scope: 'test',
22
+ const fixtures = {
23
+ expectScreenshot: [expectScreenshotFixture, { scope: 'test' }],
22
24
  };
23
- const expectScreenshot = [
24
- expectScreenshotFixture,
25
- fixtureOptions,
26
- ];
27
- return expectScreenshot;
25
+ return fixtures;
28
26
  }
@@ -1,2 +1,2 @@
1
- export { expectScreenshotFixtureBuilder } from './expect-screenshot-fixture';
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.expectScreenshotFixtureBuilder = void 0;
3
+ exports.expectScreenshotFixturesBuilder = void 0;
4
4
  var expect_screenshot_fixture_1 = require("./expect-screenshot-fixture");
5
- Object.defineProperty(exports, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_fixture_1.expectScreenshotFixtureBuilder; } });
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 = {};
@@ -1,10 +1,10 @@
1
- export type { TestSlugResult } from './testSlug';
2
- export { testSlug } from './testSlug';
3
- export type { MockNetworkFixtureBuilderParams } from './mock-network';
4
- export { mockNetworkFixtureBuilder } from './mock-network';
5
- export type { ExpectRequestFn, ExpectRequestTestArgs, ExpectRequestFnMatcher, ExpectRequestFnOptions, } from './expect-request';
6
- export { expectRequest } from './expect-request';
7
- export type { ExpectScreenshotFn, ExpectScreenshotTestArgs, ExpectScreenshotFixtureBuilderParams, } from './expect-screenshot';
8
- export { expectScreenshotFixtureBuilder } from './expect-screenshot';
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.expectScreenshotFixtureBuilder = exports.expectRequest = exports.mockNetworkFixtureBuilder = exports.testSlug = void 0;
4
- var testSlug_1 = require("./testSlug");
5
- Object.defineProperty(exports, "testSlug", { enumerable: true, get: function () { return testSlug_1.testSlug; } });
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, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_1.mockNetworkFixtureBuilder; } });
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, "expectRequest", { enumerable: true, get: function () { return expect_request_1.expectRequest; } });
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, "expectScreenshotFixtureBuilder", { enumerable: true, get: function () { return expect_screenshot_1.expectScreenshotFixtureBuilder; } });
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 { mockNetworkFixtureBuilder } from './mock-network-fixture';
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.mockNetworkFixtureBuilder = void 0;
3
+ exports.mockNetworkFixturesBuilder = void 0;
4
4
  var mock_network_fixture_1 = require("./mock-network-fixture");
5
- Object.defineProperty(exports, "mockNetworkFixtureBuilder", { enumerable: true, get: function () { return mock_network_fixture_1.mockNetworkFixtureBuilder; } });
5
+ Object.defineProperty(exports, "mockNetworkFixturesBuilder", { enumerable: true, get: function () { return mock_network_fixture_1.mockNetworkFixturesBuilder; } });
@@ -1,6 +1,3 @@
1
- import type { PlaywrightTestArgs, PlaywrightTestOptions, TestFixture } from '@playwright/test';
2
- import type { MockNetworkFixtureBuilderParams } from './types';
3
- export declare function mockNetworkFixtureBuilder<TestArgs extends PlaywrightTestArgs & PlaywrightTestOptions = PlaywrightTestArgs & PlaywrightTestOptions>({ shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip, url, dumpsFilePath, optionallyEnabled, ...harPatcherParams }: MockNetworkFixtureBuilderParams): [TestFixture<boolean, TestArgs>, {
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.mockNetworkFixtureBuilder = mockNetworkFixtureBuilder;
3
+ exports.mockNetworkFixturesBuilder = mockNetworkFixturesBuilder;
4
4
  const har_1 = require("../../har");
5
5
  const har_patcher_1 = require("./har-patcher");
6
- const fixtureFunction = async ({ baseURL: rawBaseURL, page, }, { shouldUpdate, forceUpdateIfHarMissing, updateTimeout, zip = true, url: urlMatcherBuilder, dumpsFilePath, ...harPatcherParams }, use, testInfo) => {
7
- if (!rawBaseURL) {
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
- return fixtureFunction({ baseURL, page }, {
44
- shouldUpdate,
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
- zip,
25
+ update,
48
26
  url,
49
- dumpsFilePath,
50
- ...harPatcherParams,
51
- }, use, testInfo);
27
+ zip,
28
+ });
29
+ await use(!finalUpdate);
52
30
  };
53
- const fixtureOptions = {
54
- auto: true,
55
- scope: 'test',
31
+ const fixtures = {
32
+ enableNetworkMocking: [true, { scope: 'test', option: true }],
33
+ isMockingEnabled: [isMockingEnabledFixture, { scope: 'test', auto: true }],
56
34
  };
57
- const mockNetwork = [
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 OptionallyEnabledTestArgs = {
94
- enableNetworkMocking?: boolean;
87
+ export type MockNetworkTestArgs = {
88
+ enableNetworkMocking: boolean;
89
+ isMockingEnabled: boolean;
95
90
  };
91
+ export type MockNetworkWorkerArgs = {};
@@ -0,0 +1,2 @@
1
+ export { testSlugFixturesBuilder } from './test-slug-fixture';
2
+ export type { TestSlugFixturesBuilderParams, TestSlugResult, TestSlugTestArgs, TestSlugWorkerArgs, } from './types';
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ export type TestSlugResult = string;
2
+ export interface TestSlugTestArgs {
3
+ testSlug: TestSlugResult;
4
+ }
5
+ export type TestSlugWorkerArgs = {};
6
+ export type TestSlugFixturesBuilderParams = {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/playwright-tools",
3
- "version": "1.1.3",
3
+ "version": "1.1.4-beta.114525d1176b54fc8177c759986ee94fa4516af0.0",
4
4
  "description": "Tools for Playwright Test",
5
5
  "keywords": [
6
6
  "playwright",
@@ -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 {};
@@ -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
- ];