@letsrunit/playwright 0.12.0 → 0.13.1

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.12.0",
3
+ "version": "0.13.1",
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.12.0",
45
+ "@letsrunit/utils": "0.13.1",
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
@@ -176,8 +176,9 @@ export async function realScrubHtml(
176
176
  opts: ScrubHtmlOptions = {},
177
177
  ): Promise<string> {
178
178
  const o = { ...getDefaults(html.length), ...opts };
179
+ const htmlForDom = preStripHtmlForJSDOM(html, o.dropHead);
179
180
 
180
- const dom = new JSDOM(html, { url });
181
+ const dom = new JSDOM(htmlForDom, { url });
181
182
  const doc = dom.window.document;
182
183
 
183
184
  if (o.pickMain) pickMain(doc);
@@ -250,6 +251,16 @@ function pickMain(doc: Document): boolean {
250
251
  return true;
251
252
  }
252
253
 
254
+ function preStripHtmlForJSDOM(html: string, dropHead: boolean): string {
255
+ let out = html;
256
+ if (dropHead) out = out.replace(/<head\b[\s\S]*?<\/head>/gi, '');
257
+
258
+ // Prevent jsdom/cssom import-rule recursion while preserving body semantics.
259
+ out = out.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, '');
260
+ out = out.replace(/<link\b[^>]*\brel\s*=\s*["']?stylesheet["']?[^>]*>/gi, '');
261
+ return out;
262
+ }
263
+
253
264
  function dropInfraAndSvg(doc: Document, dropSvg: boolean) {
254
265
  const toDrop = [...ALWAYS_DROP, dropSvg ? 'svg' : ''].filter(Boolean).join(',');
255
266
  if (!toDrop) return;