-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { join } = require("path"); | ||
|
||
const { render } = require("../../utils/render"); | ||
const { getDocumentScrollWidth } = require("../../utils/playwright"); | ||
|
||
/** Base custom checks */ | ||
module.exports = async ({ page, moduleName, config }) => { | ||
const moduleConfig = config.modulesConfig[moduleName]; | ||
const violations = []; | ||
|
||
for (const { name: deviceName, options: deviceOptions } of config.devices) { | ||
await page.setViewportSize(deviceOptions.viewport); | ||
|
||
if (moduleConfig["horizontal-content-overflow"]) { | ||
// check for horizontal overflows | ||
const documentScrollWidth = await getDocumentScrollWidth(page); | ||
if (documentScrollWidth > deviceOptions.viewport.width) { | ||
violations.push({ | ||
icon: "icon-severity-moderate", | ||
title: `Horizontal content overflow on ${deviceName}`, | ||
description: `Device width: <strong>${deviceOptions.viewport.width}</strong>. Document scroll width: <strong>${documentScrollWidth}</strong>.`, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
const issueCount = violations.length; | ||
const html = render(join(__dirname, "template.njk"), { | ||
issueCount, | ||
violations, | ||
}); | ||
return { issueCount, html }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% set anchorId = "module-base" %} | ||
<h2 id="{{ anchorId }}">{% include "../../includes/anchor-link.njk" %} base</h2> | ||
|
||
<ul> | ||
<li> | ||
<strong class="{{ 'text-danger' if issueCount > 0 }}">{{ issueCount }} violation(s)</strong> | ||
</li> | ||
</ul> | ||
|
||
{% for violation in violations %} | ||
<section> | ||
<h3><svg class="icon icon-severity {{ violation.icon }}" role="img" aria-hidden="true"><use xlink:href="#{{ violation.icon }}"></use></svg> {{ violation.title }}</h3> | ||
<p>{{ violation.description | safe }}</p> | ||
</section> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
getDocumentScrollWidth: (page) => | ||
// eslint-disable-next-line no-undef | ||
page.evaluate(() => window.document.documentElement.scrollWidth, {}), | ||
}; |