Skip to content

Instantly share code, notes, and snippets.

@Robdel12
Last active November 14, 2019 16:45
Show Gist options
  • Save Robdel12/85025052e1917c191bb98b0253412a34 to your computer and use it in GitHub Desktop.
Save Robdel12/85025052e1917c191bb98b0253412a34 to your computer and use it in GitHub Desktop.
const PercyScript = require('@percy/script');
const fs = require('fs');
const path = require('path');
const directories = [
path.resolve(__dirname, '../src/components/elements'),
path.resolve(__dirname, '../src/components/patterns'),
path.resolve(__dirname, '../src/components/templates'),
];
let urls = [];
for (const directory of directories) {
fs.readdir(directory, async function(err, components) {
if (err) {
// eslint-disable-next-line
console.log('Unable to scan directory: ' + err);
}
for (const component of components) {
if (component.includes('.md') && component !== 'README.md') {
const name = component.replace('.md', '');
urls.push(`http://localhost:7070/#!/${name}`);
}
}
});
}
PercyScript.run(async (page, percySnapshot) => {
for (const url of urls) {
await page.goto(url);
await percySnapshot(name);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment