-
Notifications
You must be signed in to change notification settings - Fork 171
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
5 changed files
with
211 additions
and
1,445 deletions.
There are no files selected for viewing
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,4 @@ | ||
version: 2 | ||
discovery: | ||
allowed-hostnames: | ||
- assets.ubuntu.com |
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 |
---|---|---|
@@ -1,34 +1,28 @@ | ||
const PercyScript = require('@percy/script'); | ||
|
||
const PORT = process.env.PORT || 8101; | ||
|
||
PercyScript.run(async (page, percySnapshot) => { | ||
module.exports = async () => { | ||
const {default: GetSiteUrls} = await import('get-site-urls'); | ||
let links = await GetSiteUrls(`http://localhost:${PORT}/`); | ||
let urls = []; | ||
|
||
links = links.found | ||
// only snapshot examples, not the whole site | ||
.filter((url) => url.includes('/docs/examples/')) | ||
// remove standalone examples listing from screenshots | ||
.filter((url) => !url.match(/examples\/standalone$/)); | ||
|
||
// disable JS requests to prevent CodePen from rendering examples | ||
await page.setRequestInterception(true); | ||
page.on('request', (request) => { | ||
if (request.resourceType() === 'script') request.abort(); | ||
else request.continue(); | ||
}); | ||
|
||
for (var i = 0; i < links.length; i++) { | ||
const url = links[i]; | ||
await page.goto(url); | ||
|
||
// ensure the page has loaded before capturing a snapshot | ||
await page.waitFor('body'); | ||
|
||
// create percy snapshot with path as a name | ||
const path = new URL(url).pathname.replace(/\/?$/, '/'); | ||
const isResponsive = path.indexOf('responsive') >= 0; | ||
await percySnapshot(path, {widths: isResponsive ? [375, 800, 1280] : [375, 1280]}); | ||
|
||
urls.push({ | ||
url: url, | ||
name: path, | ||
widths: isResponsive ? [375, 800, 1280] : [375, 1280], | ||
}); | ||
} | ||
}); | ||
|
||
return urls; | ||
}; |
Oops, something went wrong.