@letsrunit/playwright 0.17.1 → 0.18.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.17.1",
3
+ "version": "0.18.0",
4
4
  "description": "Playwright extensions and utilities for letsrunit",
5
5
  "keywords": [
6
6
  "testing",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "packageManager": "yarn@4.10.3",
44
44
  "dependencies": {
45
- "@letsrunit/utils": "0.17.1",
45
+ "@letsrunit/utils": "0.18.0",
46
46
  "@playwright/test": "^1.57.0",
47
47
  "case": "^1.6.3",
48
48
  "diff": "^8.0.3",
package/src/scrub-html.ts CHANGED
@@ -32,7 +32,7 @@ export type ScrubHtmlOptions = {
32
32
  /** Limit lists to max items: -1 mean no limit. Default: -1 */
33
33
  limitLists?: number;
34
34
  /** Strip utility-framework classes (Tailwind, Bootstrap, UnoCSS, Windi) from class
35
- * attributes. Removes the attribute entirely when all classes are stripped. Default: false */
35
+ * attributes. Removes the attribute entirely when all classes are stripped. Default: true */
36
36
  dropUtilityClasses?: boolean;
37
37
  };
38
38
 
@@ -51,7 +51,7 @@ function getDefaults(contentLength: number): Required<ScrubHtmlOptions> {
51
51
  dropComments: true,
52
52
  replaceBrInHeadings: true,
53
53
  limitLists: contentLength >= HTML_LIMIT_LISTS_THRESHOLD ? 20 : -1,
54
- dropUtilityClasses: false,
54
+ dropUtilityClasses: true,
55
55
  };
56
56
  }
57
57
 
@@ -350,10 +350,25 @@ const UTILITY_STANDALONE = new Set([
350
350
  'sr-only', 'not-sr-only', 'clearfix', 'row', 'col',
351
351
  ]);
352
352
 
353
+ const SPACING_ALPHA_VALUES = new Set(['auto', 'px']);
354
+
355
+ function isSpacingUtility(token: string): boolean {
356
+ const match = token.match(/^-?([mp][xytblrse]?)-(.*)$/i);
357
+ if (!match) return false;
358
+
359
+ const value = match[2];
360
+ if (!value) return false;
361
+
362
+ if (/^[0-9./[\]-]+$/.test(value)) return true;
363
+ if (SPACING_ALPHA_VALUES.has(value.toLowerCase())) return true;
364
+ return false;
365
+ }
366
+
353
367
  function isUtilityClass(token: string): boolean {
354
368
  if (UTILITY_VARIANT_RE.test(token)) return true;
355
369
  const base = token.startsWith('-') ? token.slice(1) : token;
356
370
  if (UTILITY_STANDALONE.has(base)) return true;
371
+ if (/^-?[mp][xytblrse]?-/i.test(token)) return isSpacingUtility(token);
357
372
  return UTILITY_PREFIX_RE.test(token);
358
373
  }
359
374
 
package/src/snapshot.ts CHANGED
@@ -6,7 +6,7 @@ import type { Snapshot } from './types';
6
6
  import { waitForDomIdle } from './wait';
7
7
 
8
8
  export type SnapshotOptions = {
9
- /** Strip utility-framework classes (Tailwind, Bootstrap, UnoCSS, Windi) from the captured HTML. */
9
+ /** Strip utility-framework classes (Tailwind, Bootstrap, UnoCSS, Windi) from the captured HTML. Default: true. */
10
10
  dropUtilityClasses?: boolean;
11
11
  };
12
12
 
@@ -16,7 +16,9 @@ export async function snapshot(page: Page, opts: SnapshotOptions = {}): Promise<
16
16
 
17
17
  const [url, html, file] = await Promise.all([page.url(), getContentWithMarkedHidden(page), screenshot(page)]);
18
18
 
19
- const finalHtml = opts.dropUtilityClasses
19
+ const dropUtilityClasses = opts.dropUtilityClasses ?? true;
20
+
21
+ const finalHtml = dropUtilityClasses
20
22
  ? await realScrubHtml({ html, url }, {
21
23
  dropHidden: false, dropHead: false, dropSvg: false, pickMain: false,
22
24
  stripAttributes: 0, normalizeWhitespace: false, dropComments: false,