Skip to content

Instantly share code, notes, and snippets.

View joelgriffith's full-sized avatar
💻
Turns out I'm really good at computers

Joel Griffith joelgriffith

💻
Turns out I'm really good at computers
View GitHub Profile
@joelgriffith
joelgriffith / navalia-suite.js
Created July 11, 2017 18:14
Test suite with Navalia and parallelization
const { Navalia } = require('navalia');
const navalia = new Navalia();
describe('My Page', () => {
afterAll(() => {
return navalia.kill();
});
it.concurrent('should have a username input', () => {
@joelgriffith
joelgriffith / visual-regression.js
Created July 19, 2017 22:58
Visual Regression Testing in Navali
const { Chrome } = require('navalia');
const { toMatchImageSnapshot } = require('jest-image-snapshot');
expect.extend({ toMatchImageSnapshot });
describe('Visual Regressions', () => {
let chrome = null;
beforeEach(() => {
chrome = new Chrome();
@joelgriffith
joelgriffith / jest-image-snapshot.js
Created July 20, 2017 15:23
Assertions using jest-image-snapshots!
it('should not have visual regressions', () => {
...do something to generate an image...
expect(image).toMatchImageSnapshot();
});
@joelgriffith
joelgriffith / jest-image-snapshot-setup.js
Created July 20, 2017 15:29
Setting up jest-image-snapshot
import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
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);
@joelgriffith
joelgriffith / headless-libraries.js
Last active September 20, 2017 04:03
Compares headless libraries
// 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();
@joelgriffith
joelgriffith / title.js
Last active January 15, 2018 23:17
Find website titles (title, OpenGraph, schema.org)
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')) {
@joelgriffith
joelgriffith / description.js
Created January 15, 2018 23:16
Get's a site description
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"]')) {
@joelgriffith
joelgriffith / browserless-cnn-title.js
Created January 15, 2018 23:35
Get the title from CNN
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')) {
@joelgriffith
joelgriffith / get-image.js
Last active January 15, 2018 23:47
Get site image
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;
}