Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

remove spellcheck #12

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fixtures/dummy.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ <h3>Image</h3>
<div class="hint">Hint: the image should be loaded.</div>
<img id="image" src="https://placebear.com/500/600" />

<h3>Input</h3>
<div class="hint">Hint: spellcheck should be disabled</div>
<input value="an orrange carrot" autofocus />

<h3>Paragraph</h3>
<div class="hint">
Hint: the font should be loaded and the scrollbar hidden.
Expand Down
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const GLOBAL_STYLES = `
font-family: monospace !important;
opacity: 0 !important;
}

[data-visual-test="removed"] {
display: none !important;
}
Expand All @@ -42,6 +42,15 @@ function waitForImagesLoading() {
return allImages.every((img) => img.complete);
}

// Disable spellcheck to avoid red underlines
function disableSpellCheck() {
const query =
"[contenteditable]:not([contenteditable=false]):not([spellcheck=false]), input:not([spellcheck=false]), textarea:not([spellcheck=false])";
const inputs = document.querySelectorAll(query);
inputs.forEach((input) => input.setAttribute("spellcheck", "false"));
return true;
}

type LocatorOptions = Parameters<Page["locator"]>[1];

type ScreenshotOptions<
Expand Down Expand Up @@ -78,10 +87,11 @@ export async function argosScreenshot(
// Wait for all busy elements to be loaded
await page.waitForSelector('[aria-busy="true"]', { state: "hidden" });

// Wait for all images and fonts to be loaded
// Code injection to improve the screenshot stability
await Promise.all([
page.waitForFunction(waitForImagesLoading),
page.waitForFunction(waitForFontLoading),
page.waitForFunction(disableSpellCheck),
]);

await handle.screenshot({
Expand Down