Skip to content

Instantly share code, notes, and snippets.

View gidztech's full-sized avatar
😊
Does my code spark joy?

Gideon Pyzer gidztech

😊
Does my code spark joy?
View GitHub Profile
@gidztech
gidztech / index.js
Last active December 30, 2018 13:01
Interact with the DevTools UI while inspecting a page with Puppeteer (Hack)
// Use Puppeteer to interact with the DevTools UI while inspecting a page
// This is a complete hack, but it allows you to interact with the DevTools UI using Puppeteer.
// In this example, I'm able to install Adblock Plus and navigate to the extension's tab
// Author: Gideon Pyzer (https://www.gideonpyzer.com)
const puppeteer = require('puppeteer');
(async() => {
// launch with devtools, which enables debugging capabilities
describe('Panel tests', async () => {
beforeAll(async () => {
await runSetup();
});
describe('Simple mode', async () => {
it('should have a title and body', async () => {
... omitted functional tests ...
});
@gidztech
gidztech / jest-image-snapshot-example.js
Created June 25, 2018 16:30
jest image snapshot example
it('renders correctly', async () => {
const page = await browser.newPage();
await page.goto('https://localhost:3000');
const image = await page.screenshot();
expect(image).toMatchImageSnapshot();
});
@gidztech
gidztech / muppeteer-example-config.js
Last active June 25, 2018 16:29
muppeteer example config
const ConfigureLauncher = require('muppeteer');
const launcher = await ConfigureLauncher({
testPathPattern: 'tests/**/*.test.js'
reportDir: 'tests/report',
componentTestUrlFactory:
({name}) => `http://${IP}:${PORT}/${name}`,
visualThreshold: 0.05,
useDocker: true,
dockerChromeVersion: '67.0.3396.79',
@gidztech
gidztech / muppeteer-example.js
Last active January 12, 2019 15:12
muppeteer example
describeComponent({ name: 'Panel' }, () => {
describe('Simple mode', async () => {
it('should have a title and body', async () => {
... omitted functional tests ...
});
it('should position the title and body correctly', async () => {
await assert.visual(panelContainer);
});
});
describe('Icon mode', async () => {

console.fancyTable

I was answering a StackOverflow question, where someone asked whether you could style console.table statements, as you can do with console.log. It turns out that there's no styling capabilities.

I worked on a really hacky solution to get around this by allowing you to use console.log to style objects in a table like fashion. There were several limitations, such as not being able to set width and height properties. My workaround was to pad each object's property values with spaces to have equal number of characters.

The Code