This file contains hidden or 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
const { Chrome } = require('navalia'); | |
const { toMatchImageSnapshot } = require('jest-image-snapshot'); | |
expect.extend({ toMatchImageSnapshot }); | |
describe('Visual Regressions', () => { | |
let chrome = null; | |
beforeEach(() => { | |
chrome = new Chrome(); |
This file contains hidden or 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
it('should not have visual regressions', () => { | |
...do something to generate an image... | |
expect(image).toMatchImageSnapshot(); | |
}); |
This file contains hidden or 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
import { toMatchImageSnapshot } from 'jest-image-snapshot'; | |
expect.extend({ toMatchImageSnapshot }); |
This file contains hidden or 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
const { Chrome } = require('navalia'); | |
const chrome = new Chrome(); | |
chrome | |
.goto('https://www.google.com/', { pageload: false }) | |
.evaluate(() => 'INSERT YOUR SCRIPT HERE') | |
// More stuff | |
.then((results) => { | |
console.log(results); |
This file contains hidden or 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
// Puppeteer | |
const puppeteer = require('puppeteer'); | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://example.com'); | |
await page.screenshot({path: 'example.png'}); | |
await browser.close(); |
This file contains hidden or 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
function getTitle() { | |
if (document.querySelector('meta[property="og:title"]')) { | |
return document.querySelector('meta[property="og:title"]').content; | |
} | |
if (document.querySelector('[itemprop="name"]')) { | |
return document.querySelector('[itemprop="name"]').text; | |
} | |
if (document.querySelector('title')) { |
This file contains hidden or 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
function getDescription() { | |
if (document.querySelector('meta[property="og:description"]')) { | |
return document.querySelector('meta[property="og:description"]').content; | |
} | |
if (document.querySelector('[itemprop="description"]')) { | |
return document.querySelector('[itemprop="description"]').text; | |
} | |
if (document.querySelector('meta[name="description"]')) { |
This file contains hidden or 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
const puppeteer = require('puppeteer'); | |
function getTitle() { | |
if (document.querySelector('meta[property="og:title"]')) { | |
return document.querySelector('meta[property="og:title"]').content; | |
} | |
if (document.querySelector('[itemprop="name"]')) { | |
return document.querySelector('[itemprop="name"]').text; | |
} | |
if (document.querySelector('title')) { |
This file contains hidden or 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
async function getImage(page) { | |
if (document.querySelector('meta[property="og:image"]')) { | |
return document.querySelector('meta[property="og:image"]').content; | |
} | |
if (document.querySelector('[itemprop="image"]')) { | |
return document.querySelector('[itemprop="image"]').text; | |
} | |
// Return null so we can handle it later | |
return null; | |
} |