@argos-ci/browser
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -0,4 +1,7 @@ | ||
type PrepareForScreenshotOptions = { | ||
fullPage?: boolean; | ||
}; | ||
declare const ArgosGlobal: { | ||
waitForStability: () => boolean; | ||
prepareForScreenshot: () => void; | ||
prepareForScreenshot: (options?: PrepareForScreenshotOptions) => void; | ||
getColorScheme: () => "dark" | "light"; | ||
@@ -5,0 +8,0 @@ getMediaType: () => "print" | "screen"; |
@@ -46,3 +46,3 @@ (function () { | ||
/** | ||
* | ||
* Inject global styles in the DOM. | ||
*/ function injectGlobalStyles(document) { | ||
@@ -53,7 +53,30 @@ const style = document.createElement("style"); | ||
} | ||
const checkIsHTMLElement = (element)=>{ | ||
return "style" in element; | ||
}; | ||
/** | ||
* Stabilize sticky and fixed elements. | ||
*/ function stabilizeElementPositions(document) { | ||
const window = document.defaultView; | ||
if (!window) return; | ||
const elements = Array.from(document.querySelectorAll("*")); | ||
elements.forEach((element)=>{ | ||
if (!checkIsHTMLElement(element)) return; | ||
const style = window.getComputedStyle(element); | ||
const position = style.position; | ||
if (position === "fixed") { | ||
element.style.position = "absolute"; | ||
} else if (position === "sticky") { | ||
element.style.position = "relative"; | ||
} | ||
}); | ||
} | ||
/** | ||
* Prepare the document for a screenshot. | ||
*/ function prepareForScreenshot(document) { | ||
*/ function prepareForScreenshot(document, { fullPage } = {}) { | ||
injectGlobalStyles(document); | ||
disableSpellCheck(document); | ||
if (fullPage) { | ||
stabilizeElementPositions(document); | ||
} | ||
} | ||
@@ -110,3 +133,3 @@ /** | ||
waitForStability: ()=>waitForStability(document), | ||
prepareForScreenshot: ()=>prepareForScreenshot(document), | ||
prepareForScreenshot: (options = {})=>prepareForScreenshot(document, options), | ||
getColorScheme: ()=>getColorScheme(window), | ||
@@ -113,0 +136,0 @@ getMediaType: ()=>getMediaType(window) |
{ | ||
"name": "@argos-ci/browser", | ||
"description": "Browser utilities to stabilize visual testing.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": "Smooth Code", | ||
@@ -48,3 +48,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "f864cced9e48669efab2a35fde612570600b94a7" | ||
"gitHead": "0cdfcea5b55b54a44228d03919168b25e5dec70f" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11858
324