From c89e401c87f2483764de18c71dc0813533c7f000 Mon Sep 17 00:00:00 2001 From: Ilya Isupov Date: Tue, 25 Nov 2025 19:02:52 +0300 Subject: [PATCH] fix: fixed exports format for package Added conditional exports as modern approach Restrited interface to index files only for each lib part Removed config examples as non-relevant content Ported patch for collectPageActivity action from playwright-utils --- actions/collectPageActivity/getURL.ts | 44 +++++++++++++++ actions/collectPageActivity/isSameResponse.ts | 6 ++- config/README.md | 53 ------------------- config/browsers.ts | 5 -- config/browsersDesktop.ts | 28 ---------- config/browsersMobile.ts | 21 -------- package.json | 42 +++++++++++---- storybook/index.ts | 2 + 8 files changed, 83 insertions(+), 118 deletions(-) create mode 100644 actions/collectPageActivity/getURL.ts delete mode 100644 config/README.md delete mode 100644 config/browsers.ts delete mode 100644 config/browsersDesktop.ts delete mode 100644 config/browsersMobile.ts create mode 100644 storybook/index.ts diff --git a/actions/collectPageActivity/getURL.ts b/actions/collectPageActivity/getURL.ts new file mode 100644 index 0000000..05ea696 --- /dev/null +++ b/actions/collectPageActivity/getURL.ts @@ -0,0 +1,44 @@ +class InvalidURLError extends Error { + readonly url: string; + readonly base: string | undefined; + + constructor(message: string, url: string, base: string | undefined) { + super(message); + + this.name = 'InvalidURLError'; + this.url = url; + this.base = base; + + //https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + Object.setPrototypeOf(this, InvalidURLError.prototype); + + Error.captureStackTrace?.(this, this.constructor); + } + + toJSON() { + const { url, base } = this; + + return { + url, + base, + }; + } +} + +export function getURL(url: string, base?: string) { + try { + return new URL(url, base); + } catch { + let message: string; + + if (base === undefined) { + message = 'isSameResponse: failed to create URL for url %s'; + } else { + message = 'isSameResponse: failed to create URL for url %s and base %s'; + } + + console.error(message, url, base); + + throw new InvalidURLError('isSameResponse: failed to create url', url, base); + } +} diff --git a/actions/collectPageActivity/isSameResponse.ts b/actions/collectPageActivity/isSameResponse.ts index 643bf93..d83a212 100644 --- a/actions/collectPageActivity/isSameResponse.ts +++ b/actions/collectPageActivity/isSameResponse.ts @@ -1,3 +1,4 @@ +import { getURL } from './getURL'; import { normalizePathname } from './normalizePathname'; import type { ExpectedResponse } from './types'; @@ -7,13 +8,14 @@ export function isSameResponse(status: number, url: string, baseUrl: string) { return (expectedResponse: ExpectedResponse) => { const expectedUrl = typeof expectedResponse.url === 'string' - ? new URL(expectedResponse.url, baseUrl) + ? getURL(expectedResponse.url, baseUrl) : expectedResponse.url; - const failedUrl = new URL(url); let result = expectedResponse.status === status; if (result) { + const failedUrl = getURL(url); + if (expectedUrl instanceof RegExp) { result = expectedUrl.test(failedUrl.href); } else { diff --git a/config/README.md b/config/README.md deleted file mode 100644 index c471207..0000000 --- a/config/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# Base Configuration - -Can be used as a configuration example, or imported and extended in your project. - -## base - -All essential settings for Playwright test configuration. This base config includes: -- Different settings for CI and local environments (retries, timeouts, workers) -- Default test options (locale, timezone, screenshot/video settings) -- Reporter configuration -- Default Chrome browser project - -In the config, `use.baseURL` is set to `https://localhost`. You should change it to your service address. For example, you can create a new object based on the base config with overrides: - -```ts -{ - ...baseConfig, - use: { - ...baseConfig.use, - baseURL: 'https://your-service-url.com', - }, -} -``` - -The default browser is Desktop Chrome only. - -## browsers - -Collection of standard browsers. Contains both desktop and mobile browsers. - -Browser configurations include a non-standard `projectName` parameter to make it easy to filter tests by browser (for example, via `test.skip`). To use this parameter, you need to specify it in your extension for `test`. - -Provides a combined list of browsers from browsersDesktop and browsersMobile. - -For a complete list of browsers that Playwright can emulate, see [deviceDescriptorsSource.json](https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json). - -## browsersDesktop - -Desktop browsers only. - -Browsers in the set: -- `Chrome` (Desktop Chrome) -- `Safari` (Desktop Safari) -- `Firefox` (Desktop Firefox) - -## browsersMobile - -Mobile browsers only. - -Browsers in the set: -- `Android` (Pixel 5) -- `iPhone` (iPhone 12) - diff --git a/config/browsers.ts b/config/browsers.ts deleted file mode 100644 index c07c11c..0000000 --- a/config/browsers.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { projects as desktop } from './browsersDesktop'; -import { projects as mobile } from './browsersMobile'; - -export const projects = [...desktop, ...mobile]; -export default projects; diff --git a/config/browsersDesktop.ts b/config/browsersDesktop.ts deleted file mode 100644 index b96ffc8..0000000 --- a/config/browsersDesktop.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { devices } from '@playwright/test'; - -type ProjectName = 'Chrome' | 'Safari' | 'Firefox'; - -export const projects = [ - { - name: 'Chrome', - use: { - ...devices['Desktop Chrome'], - projectName: 'Chrome' as ProjectName, - }, - }, - { - name: 'Safari', - use: { - ...devices['Desktop Safari'], - projectName: 'Safari' as ProjectName, - }, - }, - { - name: 'Firefox', - use: { - ...devices['Desktop Firefox'], - projectName: 'Firefox' as ProjectName, - }, - }, -]; -export default projects; diff --git a/config/browsersMobile.ts b/config/browsersMobile.ts deleted file mode 100644 index c62c91e..0000000 --- a/config/browsersMobile.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { devices } from '@playwright/test'; - -type ProjectName = 'Android' | 'iPhone'; - -export const projects = [ - { - name: 'Android', - use: { - ...devices['Pixel 5'], - projectName: 'Android' as ProjectName, - }, - }, - { - name: 'iPhone', - use: { - ...devices['iPhone 12'], - projectName: 'iPhone' as ProjectName, - }, - }, -]; -export default projects; diff --git a/package.json b/package.json index 8d81500..99624e2 100644 --- a/package.json +++ b/package.json @@ -22,18 +22,42 @@ "/data/**/*.*(js|d.ts)", "/fixtures/**/*.*(js|d.ts)", "/har/**/*.*(js|d.ts)", + "/storybook/**/*.*(js|d.ts)", "/utils/**/*.*(js|d.ts)", "!/**/__tests__" ], - "exports": [ - "./actions/**/*.*(js|d.ts)", - "./auth/**/*.*(js|d.ts)", - "./config/**/*.*(js|d.ts)", - "./data/**/*.*(js|d.ts)", - "./fixtures/**/*.*(js|d.ts)", - "./har/**/*.*(js|d.ts)", - "./utils/**/*.*(js|d.ts)" - ], + "exports": { + "./actions": { + "types": "./actions/index.d.ts", + "import": "./actions/index.js", + "require": "./actions/index.js" + }, + "./auth/storage": { + "types": "./auth/storage/index.d.ts", + "import": "./auth/storage/index.js", + "require": "./auth/storage/index.js" + }, + "./fixtures": { + "types": "./fixtures/index.d.ts", + "import": "./fixtures/index.js", + "require": "./fixtures/index.js" + }, + "./har": { + "types": "./har/index.d.ts", + "import": "./har/index.js", + "require": "./har/index.js" + }, + "./storybook": { + "types": "./storybook/index.d.ts", + "import": "./storybook/index.js", + "require": "./storybook/index.js" + }, + "./utils": { + "types": "./utils/index.d.ts", + "import": "./utils/index.js", + "require": "./utils/index.js" + } + }, "scripts": { "prepare": "husky", "build": "tsc", diff --git a/storybook/index.ts b/storybook/index.ts new file mode 100644 index 0000000..339cfef --- /dev/null +++ b/storybook/index.ts @@ -0,0 +1,2 @@ +export type { Cases, CasesWithName, Scenario, ScenarioName } from './types'; +export { createSmokeScenarios } from './create-smoke-scenarios';