@gravity-ui/playwright-tools 0.7.0 → 0.8.3

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 (34) hide show
  1. package/README.md +19 -1
  2. package/actions/collectPageActivity/getURL.d.ts +1 -0
  3. package/actions/collectPageActivity/getURL.js +39 -0
  4. package/actions/collectPageActivity/isSameResponse.js +18 -6
  5. package/actions/collectPageActivity/normalizePathname.js +2 -2
  6. package/actions/collectPageActivity/types.d.ts +1 -1
  7. package/actions/disableMetrika.d.ts +8 -0
  8. package/actions/disableMetrika.js +12 -0
  9. package/actions/expect-request/matchers/compare/DiffPrinter.js +0 -1
  10. package/actions/expect-request/matchers/compare/index.d.ts +1 -3
  11. package/actions/expect-request/matchers/compare/index.js +1 -19
  12. package/actions/expect-request/matchers/compare/types.d.ts +13 -13
  13. package/actions/index.d.ts +2 -0
  14. package/actions/index.js +5 -1
  15. package/data/globalSettings.d.ts +0 -16
  16. package/data/globalSettings.js +0 -16
  17. package/fixtures/mock-network/har-patcher.js +2 -0
  18. package/har/addFlushTransform.d.ts +6 -0
  19. package/har/addFlushTransform.js +37 -0
  20. package/har/index.d.ts +2 -0
  21. package/har/index.js +3 -1
  22. package/package.json +35 -12
  23. package/storybook/create-smoke-scenarios.d.ts +6 -0
  24. package/storybook/create-smoke-scenarios.js +54 -0
  25. package/storybook/index.d.ts +2 -0
  26. package/storybook/index.js +5 -0
  27. package/storybook/types.d.ts +5 -0
  28. package/storybook/types.js +2 -0
  29. package/config/browsers.d.ts +0 -24
  30. package/config/browsers.js +0 -7
  31. package/config/browsersDesktop.d.ts +0 -14
  32. package/config/browsersDesktop.js +0 -28
  33. package/config/browsersMobile.d.ts +0 -14
  34. package/config/browsersMobile.js +0 -21
package/README.md CHANGED
@@ -2,9 +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).
5
23
 
6
24
  ## Maintainers
7
25
 
8
26
  [@Avol-V](https://github.com/Avol-V)
9
27
  [SwinX](https://github.com/SwinX)
10
- [@vegancat63](https://github.com/vegancat63)
28
+ [@vegancat63](https://github.com/vegancat63)
@@ -0,0 +1 @@
1
+ export declare function getURL(url: string, base?: string): URL;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getURL = getURL;
4
+ class InvalidURLError extends Error {
5
+ url;
6
+ base;
7
+ constructor(message, url, base) {
8
+ super(message);
9
+ this.name = 'InvalidURLError';
10
+ this.url = url;
11
+ this.base = base;
12
+ //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
13
+ Object.setPrototypeOf(this, InvalidURLError.prototype);
14
+ Error.captureStackTrace?.(this, this.constructor);
15
+ }
16
+ toJSON() {
17
+ const { url, base } = this;
18
+ return {
19
+ url,
20
+ base,
21
+ };
22
+ }
23
+ }
24
+ function getURL(url, base) {
25
+ try {
26
+ return new URL(url, base);
27
+ }
28
+ catch {
29
+ let message;
30
+ if (base === undefined) {
31
+ message = 'isSameResponse: failed to create URL for url %s';
32
+ }
33
+ else {
34
+ message = 'isSameResponse: failed to create URL for url %s and base %s';
35
+ }
36
+ console.error(message, url, base);
37
+ throw new InvalidURLError('isSameResponse: failed to create url', url, base);
38
+ }
39
+ }
@@ -1,16 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isSameResponse = isSameResponse;
4
+ const getURL_1 = require("./getURL");
4
5
  const normalizePathname_1 = require("./normalizePathname");
5
6
  const EMPTY_PATHNAME = '/';
6
7
  function isSameResponse(status, url, baseUrl) {
7
8
  return (expectedResponse) => {
8
- const expectedUrl = new URL(expectedResponse.url, baseUrl);
9
- const failedUrl = new URL(url);
10
- let result = expectedResponse.status === status && expectedUrl.origin === failedUrl.origin;
11
- if (result && expectedUrl.pathname !== EMPTY_PATHNAME) {
12
- result =
13
- (0, normalizePathname_1.normalizePathname)(expectedUrl.pathname) === (0, normalizePathname_1.normalizePathname)(failedUrl.pathname);
9
+ const expectedUrl = typeof expectedResponse.url === 'string'
10
+ ? (0, getURL_1.getURL)(expectedResponse.url, baseUrl)
11
+ : expectedResponse.url;
12
+ let result = expectedResponse.status === status;
13
+ if (result) {
14
+ const failedUrl = (0, getURL_1.getURL)(url);
15
+ if (expectedUrl instanceof RegExp) {
16
+ result = expectedUrl.test(failedUrl.href);
17
+ }
18
+ else {
19
+ result = expectedUrl.origin === failedUrl.origin;
20
+ if (result && expectedUrl.pathname !== EMPTY_PATHNAME) {
21
+ result =
22
+ (0, normalizePathname_1.normalizePathname)(expectedUrl.pathname) ===
23
+ (0, normalizePathname_1.normalizePathname)(failedUrl.pathname);
24
+ }
25
+ }
14
26
  }
15
27
  return result;
16
28
  };
@@ -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;
@@ -10,7 +10,7 @@ export type ExpectedMessage = {
10
10
  };
11
11
  export type ExpectedResponse = {
12
12
  status: number;
13
- url: string;
13
+ url: string | RegExp;
14
14
  };
15
15
  export type Config = {
16
16
  /** Url where app is available */
@@ -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,4 +1,2 @@
1
1
  export { compare } from './compare';
2
- export * from './types';
3
- export * from './utils';
4
- export { printJsonDiff } from './print-json-diff';
2
+ export type { DiffLog } from './types';
@@ -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.printJsonDiff = exports.compare = void 0;
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 type { DecoratedLineType, DiffType, PathAnnotationType } from './constants';
3
- export type DiffType = (typeof DiffType)[keyof typeof DiffType];
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 DiffType.ValueMismatch;
13
+ type: typeof DiffTypeConst.ValueMismatch;
12
14
  expected?: Json;
13
15
  received?: Json;
14
16
  } | {
15
- type: typeof DiffType.ObjectMissingProperty;
17
+ type: typeof DiffTypeConst.ObjectMissingProperty;
16
18
  expected: {
17
19
  key: string;
18
20
  value: Json;
19
21
  };
20
22
  } | {
21
- type: typeof DiffType.ArrayMissingValue;
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 DecoratedLineType.PrimitiveValue;
35
+ type: typeof DecoratedLineTypeConst.PrimitiveValue;
35
36
  value: JsonPrimitive;
36
37
  } | {
37
- type: Exclude<DecoratedLineType, typeof DecoratedLineType.PrimitiveValue>;
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 PathAnnotationType.ObjectMissingProperty;
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 PathAnnotationType.ObjectExtraProperty;
49
+ type: typeof PathAnnotationTypeConst.ObjectExtraProperty;
50
50
  };
51
51
  export type ArrayMissingValueAnnotation = {
52
- type: typeof PathAnnotationType.ArrayMissingValue;
52
+ type: typeof PathAnnotationTypeConst.ArrayMissingValue;
53
53
  expected: Json;
54
54
  };
55
55
  export type ValueMismatchAnnotation = {
56
- type: typeof PathAnnotationType.ValueMismatch;
56
+ type: typeof PathAnnotationTypeConst.ValueMismatch;
57
57
  expected?: Json;
58
58
  received?: Json;
59
59
  };
@@ -4,6 +4,8 @@ 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';
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.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;
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");
@@ -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
  */
@@ -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
  */
@@ -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,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.7.0",
3
+ "version": "0.8.3",
4
4
  "description": "Tools for Playwright Test",
5
5
  "keywords": [
6
6
  "playwright",
@@ -18,26 +18,49 @@
18
18
  "files": [
19
19
  "/actions/**/*.*(js|d.ts)",
20
20
  "/auth/**/*.*(js|d.ts)",
21
- "/config/**/*.*(js|d.ts)",
22
21
  "/data/**/*.*(js|d.ts)",
23
22
  "/fixtures/**/*.*(js|d.ts)",
24
23
  "/har/**/*.*(js|d.ts)",
24
+ "/storybook/**/*.*(js|d.ts)",
25
25
  "/utils/**/*.*(js|d.ts)",
26
26
  "!/**/__tests__"
27
27
  ],
28
- "exports": [
29
- "./actions/**/*.*(js|d.ts)",
30
- "./auth/**/*.*(js|d.ts)",
31
- "./config/**/*.*(js|d.ts)",
32
- "./data/**/*.*(js|d.ts)",
33
- "./fixtures/**/*.*(js|d.ts)",
34
- "./har/**/*.*(js|d.ts)",
35
- "./utils/**/*.*(js|d.ts)"
36
- ],
28
+ "exports": {
29
+ "./actions": {
30
+ "types": "./actions/index.d.ts",
31
+ "import": "./actions/index.js",
32
+ "require": "./actions/index.js"
33
+ },
34
+ "./auth/storage": {
35
+ "types": "./auth/storage/index.d.ts",
36
+ "import": "./auth/storage/index.js",
37
+ "require": "./auth/storage/index.js"
38
+ },
39
+ "./fixtures": {
40
+ "types": "./fixtures/index.d.ts",
41
+ "import": "./fixtures/index.js",
42
+ "require": "./fixtures/index.js"
43
+ },
44
+ "./har": {
45
+ "types": "./har/index.d.ts",
46
+ "import": "./har/index.js",
47
+ "require": "./har/index.js"
48
+ },
49
+ "./storybook": {
50
+ "types": "./storybook/index.d.ts",
51
+ "import": "./storybook/index.js",
52
+ "require": "./storybook/index.js"
53
+ },
54
+ "./utils": {
55
+ "types": "./utils/index.d.ts",
56
+ "import": "./utils/index.js",
57
+ "require": "./utils/index.js"
58
+ }
59
+ },
37
60
  "scripts": {
38
61
  "prepare": "husky",
39
62
  "build": "tsc",
40
- "clean": "find actions auth config data fixtures har utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
63
+ "clean": "find actions auth data fixtures har utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
41
64
  "typecheck": "tsc --noEmit",
42
65
  "lint": "eslint --ext .ts ./",
43
66
  "test": "jest --colors --config=jest.config.js",
@@ -0,0 +1,6 @@
1
+ import type { Cases, CasesWithName, Scenario } from './types';
2
+ interface Options {
3
+ scenarioName?: string;
4
+ }
5
+ export declare const createSmokeScenarios: <Props extends {}>(baseProps: Props, propsCases: Partial<{ [K in keyof Props]: CasesWithName<Props[K]> | Cases<Props[K]>; }>, options?: Options) => Scenario<Props>[];
6
+ export {};
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSmokeScenarios = void 0;
4
+ function checkIsCasesWithName(cases) {
5
+ const firstCase = cases[0] || null;
6
+ return Array.isArray(firstCase) && firstCase.length === 2;
7
+ }
8
+ const createSmokeScenarios = (baseProps, propsCases, options) => {
9
+ const scenarioName = `${options?.scenarioName ? ` ${options?.scenarioName} ` : ''}`;
10
+ const scenarios = [
11
+ [
12
+ `${scenarioName}[default]`,
13
+ {
14
+ ...baseProps,
15
+ },
16
+ ],
17
+ ];
18
+ const propNames = Object.keys(propsCases);
19
+ propNames.forEach((propName) => {
20
+ const propCases = propsCases[propName];
21
+ if (!propCases) {
22
+ return;
23
+ }
24
+ if (checkIsCasesWithName(propCases)) {
25
+ propCases.forEach((propCase) => {
26
+ const [caseName, caseProps] = propCase;
27
+ scenarios.push([
28
+ `${scenarioName}[${propName}: ${caseName}]`,
29
+ {
30
+ ...baseProps,
31
+ [propName]: caseProps,
32
+ },
33
+ ]);
34
+ });
35
+ }
36
+ else {
37
+ propCases.forEach((propCase) => {
38
+ const hasStringifyMethod = propCase?.toString;
39
+ if (!hasStringifyMethod) {
40
+ throw new Error('The case value does not have a method "toString", use case with name.');
41
+ }
42
+ scenarios.push([
43
+ `${scenarioName}[${propName}: ${propCase?.toString()}]`,
44
+ {
45
+ ...baseProps,
46
+ [propName]: propCase,
47
+ },
48
+ ]);
49
+ });
50
+ }
51
+ });
52
+ return scenarios;
53
+ };
54
+ exports.createSmokeScenarios = createSmokeScenarios;
@@ -0,0 +1,2 @@
1
+ export type { Cases, CasesWithName, Scenario, ScenarioName } from './types';
2
+ export { createSmokeScenarios } from './create-smoke-scenarios';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSmokeScenarios = void 0;
4
+ var create_smoke_scenarios_1 = require("./create-smoke-scenarios");
5
+ Object.defineProperty(exports, "createSmokeScenarios", { enumerable: true, get: function () { return create_smoke_scenarios_1.createSmokeScenarios; } });
@@ -0,0 +1,5 @@
1
+ export type CaseName = string;
2
+ export type Cases<T> = Array<T>;
3
+ export type CasesWithName<T> = Array<[CaseName, T]>;
4
+ export type ScenarioName = string;
5
+ export type Scenario<T> = [ScenarioName, T];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,24 +0,0 @@
1
- export declare const projects: ({
2
- name: string;
3
- use: {
4
- projectName: "Chrome" | "Safari" | "Firefox";
5
- viewport: import("playwright-core").ViewportSize;
6
- userAgent: string;
7
- deviceScaleFactor: number;
8
- isMobile: boolean;
9
- hasTouch: boolean;
10
- defaultBrowserType: "chromium" | "firefox" | "webkit";
11
- };
12
- } | {
13
- name: string;
14
- use: {
15
- projectName: "Android" | "iPhone";
16
- viewport: import("playwright-core").ViewportSize;
17
- userAgent: string;
18
- deviceScaleFactor: number;
19
- isMobile: boolean;
20
- hasTouch: boolean;
21
- defaultBrowserType: "chromium" | "firefox" | "webkit";
22
- };
23
- })[];
24
- export default projects;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projects = void 0;
4
- const browsersDesktop_1 = require("./browsersDesktop");
5
- const browsersMobile_1 = require("./browsersMobile");
6
- exports.projects = [...browsersDesktop_1.projects, ...browsersMobile_1.projects];
7
- exports.default = exports.projects;
@@ -1,14 +0,0 @@
1
- type ProjectName = 'Chrome' | 'Safari' | 'Firefox';
2
- export declare const projects: {
3
- name: string;
4
- use: {
5
- projectName: ProjectName;
6
- viewport: import("@playwright/test").ViewportSize;
7
- userAgent: string;
8
- deviceScaleFactor: number;
9
- isMobile: boolean;
10
- hasTouch: boolean;
11
- defaultBrowserType: "chromium" | "firefox" | "webkit";
12
- };
13
- }[];
14
- export default projects;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projects = void 0;
4
- const test_1 = require("@playwright/test");
5
- exports.projects = [
6
- {
7
- name: 'Chrome',
8
- use: {
9
- ...test_1.devices['Desktop Chrome'],
10
- projectName: 'Chrome',
11
- },
12
- },
13
- {
14
- name: 'Safari',
15
- use: {
16
- ...test_1.devices['Desktop Safari'],
17
- projectName: 'Safari',
18
- },
19
- },
20
- {
21
- name: 'Firefox',
22
- use: {
23
- ...test_1.devices['Desktop Firefox'],
24
- projectName: 'Firefox',
25
- },
26
- },
27
- ];
28
- exports.default = exports.projects;
@@ -1,14 +0,0 @@
1
- type ProjectName = 'Android' | 'iPhone';
2
- export declare const projects: {
3
- name: string;
4
- use: {
5
- projectName: ProjectName;
6
- viewport: import("@playwright/test").ViewportSize;
7
- userAgent: string;
8
- deviceScaleFactor: number;
9
- isMobile: boolean;
10
- hasTouch: boolean;
11
- defaultBrowserType: "chromium" | "firefox" | "webkit";
12
- };
13
- }[];
14
- export default projects;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projects = void 0;
4
- const test_1 = require("@playwright/test");
5
- exports.projects = [
6
- {
7
- name: 'Android',
8
- use: {
9
- ...test_1.devices['Pixel 5'],
10
- projectName: 'Android',
11
- },
12
- },
13
- {
14
- name: 'iPhone',
15
- use: {
16
- ...test_1.devices['iPhone 12'],
17
- projectName: 'iPhone',
18
- },
19
- },
20
- ];
21
- exports.default = exports.projects;