Skip to content

Instantly share code, notes, and snippets.

View pahund's full-sized avatar

Patrick Hund pahund

View GitHub Profile
@pahund
pahund / unit-tests.sh
Created May 25, 2017 08:16
Bash script to run Mocha unit tests using a setup file
#!/usr/bin/env bash
mocha \
--compilers js:./test/setup.js \
--recursive \
'./test/**/*Test.js'
@pahund
pahund / setup.js
Last active May 25, 2017 08:11
Using css-modules-require-hook for testing React components styled with Sass
const hook = require('css-modules-require-hook');
const sass = require('node-sass');
hook({
extensions: ['.scss'],
preprocessCss(css, filepath) {
const result = sass.renderSync({
data: css,
includePaths: [path.resolve(filepath, '..')]
});
@pahund
pahund / gist:a416ea0c34bff4f6a885c69b2fd48e25
Last active May 9, 2017 12:09
Command to rename tests – DO NOT TRY THIS AT HOME!1!
find . -name "*Test.js" -exec rename 's/Test.js$/.test.js/' '{}' \;
@pahund
pahund / unit-tests.sh
Created May 9, 2017 09:37
Command to run a suite of Mocha unit tests using Babel for transpiration
mocha \
--compilers js:node_modules/babel-register,js:./test/setup.js \
--recursive \
--colors \
--timeout 10000 \
--grep "$1" \
'./test/**/*Test.js'
@pahund
pahund / index.js
Created February 16, 2017 14:44
Code excerpts from universal-react-router4 – client/index.js
render((
<BrowserRouter>
<App gists={window.__gists__} />
</BrowserRouter>
), document.getElementById('app'));
@pahund
pahund / App.js
Created February 16, 2017 11:37
Code exerpts from universal-react-router4 – App.js
export default ({ gists }) => (
<div>
<Sidebar>
{
gists ? gists.map(gist => (
<SidebarItem key={gist.id}>
<Link to={`/g/${gist.id}`}>
{gist.description || '[no description]'}
</Link>
</SidebarItem>
@pahund
pahund / index.js
Last active February 16, 2017 11:37
Code exerpts from universal-react-router4 – server/index.js
const routes = [
'/',
'/g/:gistId'
];
app.get('*', (req, res) => {
const match = routes.reduce((acc, route) => matchPath(req.url, route, { exact: true }) || acc, null);
if (!match) {
res.status(404).send(render(<NoMatch />));
return;
@pahund
pahund / enzymeSimulateTest.js
Last active May 1, 2016 09:37
This test is derived from the example for simulate from the Enzyme documentation. It fails with an "Invariant Violation" exception, which I suspect to be a bug
/**
* enzymeSimulateTest.js
*
* @author <a href="mailto:[email protected]">Patrick Hund</a>
* @since 29 Apr 2016
*/
import React, { Component } from "react";
import { mount } from "enzyme";
import { expect } from "chai";
@pahund
pahund / gist:90153e352dcf40eee49e
Created December 21, 2015 17:21
electron stacktrace
[8883:1221/181921:FATAL:url_request_context.cc(107)] Check failed: false. Leaked 1 URLRequest(s). First URL: http://10.44.74.1/testproxy/integra214.pac.
0 Electron Framework 0x0000000102539053 _ZN4base8internal30DstRangeRelationToSrcRangeImplIilLNS0_21IntegerRepresentationE1ELS2_1ELNS0_26NumericRangeRepresentationE0EE5CheckEl + 391907
1 Electron Framework 0x000000010254ef9a _ZN4base8internal30DstRangeRelationToSrcRangeImplIilLNS0_21IntegerRepresentationE1ELS2_1ELNS0_26NumericRangeRepresentationE0EE5CheckEl + 481834
2 Electron Framework 0x0000000103c32d7d _CTFontManagerUnregisterFontForData + 13223693
3 Electron Framework 0x0000000103c32b49 _CTFontManagerUnregisterFontForData + 13223129
4 Electron Framework 0x0000000103c32dce _CTFontManagerUnregisterFontForData + 13223774
5 Electron Framework 0x000000010242a382 _ZNK4base14DefaultDeleterIN3net17URLRequestContextEEclEPS2_ + 18
6 Electron Framework
@pahund
pahund / start.js
Created October 21, 2015 14:30
Gulp task for running app in local development mode using nodemon
/**
* start.js
*
* A Gulp task that starts the local development server and the watchers.
*
* @author <a href="mailto:[email protected]">Patrick Hund</a>
* @since 22 Jun 2015
*/
import gutil from "gulp-util";
import path from "path";