@gravity-ui/playwright-tools 0.8.0 → 0.8.4

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.
@@ -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,17 @@
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
9
  const expectedUrl = typeof expectedResponse.url === 'string'
9
- ? new URL(expectedResponse.url, baseUrl)
10
+ ? (0, getURL_1.getURL)(expectedResponse.url, baseUrl)
10
11
  : expectedResponse.url;
11
- const failedUrl = new URL(url);
12
12
  let result = expectedResponse.status === status;
13
13
  if (result) {
14
+ const failedUrl = (0, getURL_1.getURL)(url);
14
15
  if (expectedUrl instanceof RegExp) {
15
16
  result = expectedUrl.test(failedUrl.href);
16
17
  }
@@ -78,7 +78,10 @@ export declare const globalSettings: {
78
78
  delay: number;
79
79
  };
80
80
  };
81
- export type GlobalSettings = typeof globalSettings;
81
+ type GlobalSettingsType = typeof globalSettings;
82
+ export interface GlobalSettings extends GlobalSettingsType {
83
+ }
82
84
  export type PartialGlobalSettings = {
83
85
  [Key in keyof GlobalSettings]?: Partial<GlobalSettings[Key]>;
84
86
  };
87
+ export {};
@@ -0,0 +1,8 @@
1
+ export type { CacheSettings } from './cacheSettings';
2
+ export { cacheSettings } from './cacheSettings';
3
+ export { extraHttpHeaders } from './extraHttpHeaders';
4
+ export type { GlobalSettings, PartialGlobalSettings } from './globalSettings';
5
+ export { globalSettings } from './globalSettings';
6
+ export type { StorageState } from './storageStates';
7
+ export { setState, getState, hasState, deleteState } from './storageStates';
8
+ export { testSlugs } from './testSlugs';
package/data/index.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testSlugs = exports.deleteState = exports.hasState = exports.getState = exports.setState = exports.globalSettings = exports.extraHttpHeaders = exports.cacheSettings = void 0;
4
+ var cacheSettings_1 = require("./cacheSettings");
5
+ Object.defineProperty(exports, "cacheSettings", { enumerable: true, get: function () { return cacheSettings_1.cacheSettings; } });
6
+ var extraHttpHeaders_1 = require("./extraHttpHeaders");
7
+ Object.defineProperty(exports, "extraHttpHeaders", { enumerable: true, get: function () { return extraHttpHeaders_1.extraHttpHeaders; } });
8
+ var globalSettings_1 = require("./globalSettings");
9
+ Object.defineProperty(exports, "globalSettings", { enumerable: true, get: function () { return globalSettings_1.globalSettings; } });
10
+ var storageStates_1 = require("./storageStates");
11
+ Object.defineProperty(exports, "setState", { enumerable: true, get: function () { return storageStates_1.setState; } });
12
+ Object.defineProperty(exports, "getState", { enumerable: true, get: function () { return storageStates_1.getState; } });
13
+ Object.defineProperty(exports, "hasState", { enumerable: true, get: function () { return storageStates_1.hasState; } });
14
+ Object.defineProperty(exports, "deleteState", { enumerable: true, get: function () { return storageStates_1.deleteState; } });
15
+ var testSlugs_1 = require("./testSlugs");
16
+ Object.defineProperty(exports, "testSlugs", { enumerable: true, get: function () { return testSlugs_1.testSlugs; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/playwright-tools",
3
- "version": "0.8.0",
3
+ "version": "0.8.4",
4
4
  "description": "Tools for Playwright Test",
5
5
  "keywords": [
6
6
  "playwright",
@@ -18,26 +18,54 @@
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
+ "./data": {
40
+ "types": "./data/index.d.ts",
41
+ "import": "./data/index.js",
42
+ "require": "./data/index.js"
43
+ },
44
+ "./fixtures": {
45
+ "types": "./fixtures/index.d.ts",
46
+ "import": "./fixtures/index.js",
47
+ "require": "./fixtures/index.js"
48
+ },
49
+ "./har": {
50
+ "types": "./har/index.d.ts",
51
+ "import": "./har/index.js",
52
+ "require": "./har/index.js"
53
+ },
54
+ "./storybook": {
55
+ "types": "./storybook/index.d.ts",
56
+ "import": "./storybook/index.js",
57
+ "require": "./storybook/index.js"
58
+ },
59
+ "./utils": {
60
+ "types": "./utils/index.d.ts",
61
+ "import": "./utils/index.js",
62
+ "require": "./utils/index.js"
63
+ }
64
+ },
37
65
  "scripts": {
38
66
  "prepare": "husky",
39
67
  "build": "tsc",
40
- "clean": "find actions auth config data fixtures har utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
68
+ "clean": "find actions auth data fixtures har storybook utils -type f ! -name '.eslintrc.js' \\( -name '*.js' -o -name '*.d.ts' \\) -delete",
41
69
  "typecheck": "tsc --noEmit",
42
70
  "lint": "eslint --ext .ts ./",
43
71
  "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;