@letsrunit/playwright 0.1.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letsrunit/playwright",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Playwright extensions and utilities for letsrunit",
5
5
  "keywords": [
6
6
  "testing",
@@ -11,16 +11,25 @@
11
11
  "license": "MIT",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/letsrunit/letsrunit.git",
14
+ "url": "https://github.com/letsrunit-hq/letsrunit.git",
15
15
  "directory": "packages/playwright"
16
16
  },
17
- "bugs": "https://github.com/letsrunit/letsrunit/issues",
18
- "homepage": "https://github.com/letsrunit/letsrunit#readme",
19
- "private": false,
17
+ "bugs": "https://github.com/letsrunit-hq/letsrunit/issues",
18
+ "homepage": "https://github.com/letsrunit-hq/letsrunit#readme",
20
19
  "type": "module",
21
- "main": "./dist/index.js",
20
+ "main": "./src/index.ts",
22
21
  "publishConfig": {
23
- "access": "public"
22
+ "access": "public",
23
+ "main": "./dist/index.js",
24
+ "module": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js",
30
+ "default": "./dist/index.js"
31
+ }
32
+ }
24
33
  },
25
34
  "files": [
26
35
  "dist",
@@ -56,12 +65,13 @@
56
65
  "@types/jsdom": "^27.0.0",
57
66
  "vitest": "^4.0.17"
58
67
  },
59
- "module": "./dist/index.js",
60
- "types": "./dist/index.d.ts",
68
+ "module": "./src/index.ts",
69
+ "types": "./src/index.ts",
61
70
  "exports": {
62
71
  ".": {
63
- "types": "./dist/index.d.ts",
64
- "import": "./dist/index.js"
72
+ "types": "./src/index.ts",
73
+ "import": "./src/index.ts",
74
+ "default": "./src/index.ts"
65
75
  }
66
76
  }
67
77
  }
@@ -1,5 +1,4 @@
1
- import { isArray, isDate, isRange } from '@letsrunit/utils';
2
- import { uniqueItem } from '@letsrunit/utils/src/array';
1
+ import { isArray, isDate, isRange, uniqueItem } from '@letsrunit/utils';
3
2
  import type { Locator } from '@playwright/test';
4
3
  import { formatDate, formatDateForInput, getMonthNames } from '../utils/date';
5
4
  import { waitForAnimationsToFinish } from '../wait';
@@ -1,5 +1,4 @@
1
- import { isRange, type Scalar } from '@letsrunit/utils';
2
- import { diffArray } from '@letsrunit/utils/src/array';
1
+ import { diffArray, isRange, type Scalar } from '@letsrunit/utils';
3
2
  import type { Locator } from '@playwright/test';
4
3
  import type { Loc, SetOptions, Value } from './types';
5
4
 
package/src/screenshot.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import { hashKey } from '@letsrunit/utils';
2
- import type { Page, PageScreenshotOptions } from '@playwright/test';
2
+ import type { LocatorScreenshotOptions, Page, PageScreenshotOptions } from '@playwright/test';
3
+
4
+ export async function screenshotElement(page: Page, selector: string, options?: LocatorScreenshotOptions): Promise<File> {
5
+ const buffer = await page.locator(selector).first().screenshot(options);
6
+ const filename = await hashKey('screenshot-{hash}.png', buffer);
7
+
8
+ return new File([new Uint8Array(buffer)], filename, { type: 'image/png' });
9
+ }
3
10
 
4
11
  export async function screenshot(page: Page, options?: PageScreenshotOptions): Promise<File> {
5
12
  const buffer = options?.mask?.length ? await screenshotWithMask(page, options) : await page.screenshot(options);
package/src/scrub-html.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  // - Collapses whitespace in text nodes (but NOT inside <pre>/<code>)
7
7
  // - Does NOT change tag names, does NOT unwrap containers, does NOT reorder content
8
8
 
9
- import { memoize } from '@letsrunit/utils/src/memoize';
9
+ import { memoize } from '@letsrunit/utils';
10
10
  import type { Page } from '@playwright/test';
11
11
  import stringify from 'fast-json-stable-stringify';
12
12
  import { JSDOM } from 'jsdom';
package/src/wait.ts CHANGED
@@ -136,7 +136,7 @@ export async function waitAfterInteraction(
136
136
  return;
137
137
  }
138
138
 
139
- if (kind === 'button' && (await target.isDisabled())) {
139
+ if (kind === 'button' && (await target.isDisabled({ timeout: 1_000 }).catch(() => false))) {
140
140
  // Buttons often disable during in-flight work, or disappear on success.
141
141
  await Promise.race([
142
142
  waitUntilEnabled(page, target, settleTimeout).catch(() => {}),
@@ -153,16 +153,17 @@ export async function waitAfterInteraction(
153
153
  /* ---------- helpers ---------- */
154
154
 
155
155
  async function elementKind(target: Locator): Promise<'link' | 'button' | 'other'> {
156
- const role = await target.getAttribute('role').catch(() => null);
156
+ const PROBE = 1_000;
157
+ const role = await target.getAttribute('role', { timeout: PROBE }).catch(() => null);
157
158
  if (role === 'link') return 'link';
158
159
  if (role === 'button') return 'button';
159
160
 
160
- const tag = await target.evaluate((el) => el.tagName.toLowerCase()).catch(() => '');
161
+ const tag = await target.evaluate((el) => el.tagName.toLowerCase(), null, { timeout: PROBE }).catch(() => '');
161
162
  if (tag === 'a') return 'link';
162
163
 
163
164
  if (tag === 'button') return 'button';
164
165
  if (tag === 'input') {
165
- const type = await target.getAttribute('type').catch(() => null);
166
+ const type = await target.getAttribute('type', { timeout: PROBE }).catch(() => null);
166
167
  if (type === 'button' || type === 'submit' || type === 'reset') return 'button';
167
168
  }
168
169