Skip to content

Instantly share code, notes, and snippets.

View stipsan's full-sized avatar

Cody Olsen stipsan

View GitHub Profile
@stipsan
stipsan / README.md
Last active July 31, 2018 11:07 — forked from paulirish/server-timing-demo.js
Demo of server timing values. visualized in chrome devtools.

To test this make sure you got npx installed (if you're on the latest NodeJS LTS version it's already installed): https://www.npmjs.com/package/npx

Then run npx https://gist.github.com/stipsan/3d803d3774d82aea080c50f6f832c0bc and open http://localhost:8082 to test it!

@stipsan
stipsan / index.jsx
Last active January 28, 2018 19:18
Easy react lifecycle hook debugging
import {Component} from 'react'
import {diff} from 'deep-object-diff'
const flattenObject = function(ob) {
const toReturn = {}
for (const i in ob) {
if (!ob.hasOwnProperty(i)) continue
if (typeof ob[i] == 'object') {
@stipsan
stipsan / README.md
Last active November 5, 2017 16:44
Publish to gh pages from circleci with zero config
@stipsan
stipsan / cli.js
Last active November 4, 2017 18:09
html-cli with lint-staged support
#!/usr/bin/env node
'use strict';
const path = require('path');
const getStdin = require('get-stdin');
const globby = require('globby');
const entries = require('lodash/entries');
const kebabCase = require('lodash/kebabCase');
const snakeCase = require('lodash/snakeCase');
const meow = require('meow');
@stipsan
stipsan / README.md
Last active February 5, 2018 11:05
fun test

Transform API Blueprints to TypeScript Definitions

How to use

Prerequisites: node v8, docker run is available and npx exists.

  1. In your terminal cd to the folder where your compiled.apib is.
  2. Execute docker run -i bugyik/apib2json < compiled.apib | npx https://gist.github.com/stipsan/77de06507d74442c82916477f2d59722 > api.d.ts. The first time it runs it might take a little time to download the docker image but subsequent runs should be quick.
  3. Load the generated typings 😉 perhaps using /// <reference path="../api.d.ts" />
  4. Then in your resolvers: const {body}: {body: RestEndpoints.GetUserResponse} = await got(endpoint)
  5. As you type body. vscode will autocomplete it for you with whatever that endpoint is offering.
@stipsan
stipsan / Field-test.jsx
Last active August 7, 2018 22:39
Testing with Jest: Tip #15
import renderer from 'react-test-renderer'
import Field from '../Field'
// this import is created by our mock, it is inteded to help with testing and
// don't exist in the real package
import { intl } from 'react-intl'
it('should render correctly', () => {
const component = renderer.create(<Field intl={intl} />)
expect(component.toJSON()).toMatchSnapshot()
@stipsan
stipsan / Viewport-test.jsx
Last active October 17, 2021 22:13
Testing with Jest: Tip #14
import renderer from 'react-test-renderer'
import Viewport from '../Viewport'
it('should render correctly', () => {
const target = {
innerHeight: 600,
innerWidth: 800,
addEventListener: jest.fn(),
removeEventListener: jest.fn()
}
@stipsan
stipsan / Canvas-test.jsx
Last active June 17, 2017 18:07
Testing with Jest: Tip #13
import renderer from 'react-test-renderer'
import Canvas from '../Canvas'
it('should render correctly', () => {
const component = renderer.create(<Form x={0} y={0} />)
expect(component.toJSON()).toMatchSnapshot()
const instance = component.getInstance()
const spy = jest.spyOn(instance, 'calculateGrid')
@stipsan
stipsan / Form-test.jsx
Last active June 16, 2017 09:52
Testing with Jest: Tip #12
import renderer from 'react-test-renderer'
import Form, { validate } from '../Form'
jest.mock('redux-form', () => ({
Field: 'Field',
reduxForm: options => {
// Wrap the component and return the new component, just like the real hoc does
return Form => props => {
// call the validate error to make sure errors are detected
options.validate({}, props)
@stipsan
stipsan / Notifications-test.jsx
Last active June 16, 2017 09:51
Testing with Jest: Tip #11
import renderer from 'react-test-renderer'
import NotificationsContainer from '../NotificationsContainer'
// we can just pass through the component since we pass dispatch prop directly
jest.mock('react-redux', () => component => component)
it('should render correctly', () => {
const dispatch = jest.fn()
const component = renderer.create(
<NotificationsContainer dispatch={dispatch} />