noredink-ui/script/percy-tests.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-01-22 03:49:18 +03:00
const expect = require('expect');
const puppeteer = require('puppeteer');
const httpServer = require('http-server');
const percySnapshot = require('@percy/puppeteer');
const platform = require('os').platform();
// We need to change the args passed to puppeteer based on the platform they're using
const puppeteerArgs = /^win/.test(platform) ? [] : ['--single-process'];
const PORT = process.env.PORT_NUMBER || 8000;
describe('Visual tests', function () {
this.timeout(30000);
let page;
let server;
let browser;
before(async () => {
server = httpServer.createServer({ root: `${__dirname}/../public` });
server.listen(PORT);
browser = await puppeteer.launch({
headless: true,
timeout: 10000,
args: puppeteerArgs
});
});
after(() => {
server.close();
});
2019-11-15 14:16:10 +03:00
const defaultProcessing = async (name, location) => {
await page.goto(location)
2022-01-22 03:52:25 +03:00
await page.waitFor(`#${name.replace(".", "-")}`)
2022-01-22 03:49:18 +03:00
await percySnapshot(page, name)
console.log(`Snapshot complete for ${name}`)
}
2022-01-22 03:49:18 +03:00
const specialProcessing = {
'Modal': async (name, location) => {
2022-01-22 03:49:18 +03:00
await page.goto(location)
await page.waitFor(`#${name}`)
2020-09-09 02:13:30 +03:00
await page.click('#launch-modal')
await page.waitFor('[role="dialog"]')
2022-01-22 03:49:18 +03:00
await percySnapshot(page, 'Full Info Modal')
await page.click('[aria-label="Close modal"]')
2020-09-09 02:13:30 +03:00
await page.select('select', 'warning')
await page.click('#launch-modal')
await page.waitFor('[role="dialog"]')
2022-01-22 03:49:18 +03:00
await percySnapshot(page, 'Full Warning Modal')
await page.click('[aria-label="Close modal"]')
2022-01-22 03:52:25 +03:00
}
}
2022-01-22 03:49:18 +03:00
it('All', async function () {
page = await browser.newPage();
await page.goto(`http://localhost:${PORT}`);
await page.$('#maincontent');
await percySnapshot(page, this.test.fullTitle());
page.close();
2020-09-09 22:46:24 +03:00
});
2022-01-22 03:49:18 +03:00
it('Doodads', async function () {
page = await browser.newPage();
await page.goto(`http://localhost:${PORT}`);
await page.$('#maincontent');
let links = await page.evaluate(() => {
let nodes = Array.from(document.querySelectorAll("[data-nri-description='doodad-link']"));
return nodes.map(node => [node.text, node.href])
})
await links.reduce((acc, [name, location]) => {
return acc.then(() => {
let handler = specialProcessing[name] || defaultProcessing
return handler(name, location)
}
)
}, Promise.resolve())
})
});