Skip to content

Instantly share code, notes, and snippets.

View gdborton's full-sized avatar
:shipit:

Gary Borton gdborton

:shipit:
View GitHub Profile
@gdborton
gdborton / src-slash-index.js
Last active February 13, 2018 20:50
200KB exploration
import ReactDOM from 'react-dom';
@gdborton
gdborton / test.sh
Created November 15, 2017 01:28
Webpack 3 vs 4 test script
# Clear out the babel-loader cache, and the happypack cache.
rm -rf ./node_modules; npm install --silent;
rm -rf ./tmp
echo 'webpack@3.8.1'
NODE_ENV=production time npm run webpack:compile
# Clear out the babel-loader cache, and the happypack cache.
rm -rf ./node_modules; npm install;
rm -rf ./tmp
@gdborton
gdborton / ast-comparison.js
Last active November 15, 2017 09:21
Script used to compare acorn.parse on source vs JSON.parse on existing ASTs
const fs = require('fs');
const glob = require('glob');
const acorn = require('acorn-dynamic-import').default;
const sourceFiles = glob.sync('../location/*.source.json');
const astFiles = glob.sync('../location/*.ast.json');
const filesToParse = sourceFiles.map(fileLocation => {
return JSON.parse(fs.readFileSync(fileLocation, 'utf8'));
@gdborton
gdborton / some-test_spec.js
Created June 2, 2017 18:42
Converted Test File
import { expect } from 'chai';
// how a test might have been written Mocha.
describe('addition', () => {
context('a sane universe', () => {
test('one plus two equals three', () => {
expect(1 + 2).to.equal(3);
});
});
});
@gdborton
gdborton / spec_helper_jest.js
Created June 1, 2017 19:41
original chai-enzyme setup
import chai from 'chai';
import chaiEnzyme from 'chai-enzyme';
chai.use(chaiEnzyme());
@gdborton
gdborton / spec_helper_jest.js
Last active June 1, 2017 19:42
chai-enzyme delayed loading example
import chai from 'chai';
// This is not really a mock, but jest prevents out of scope
// variables unless prefixed with "mock".
const mockChai = chai;
let mockSetup = false;
// Here we're "mocking" enzyme, so that we can delay loading of
// the utility functions until emzyme is imported in tests.
jest.mock('enzyme', () => {
const actualEnzyme = require.requireActual('enzyme');
if (!mockSetup) {
@gdborton
gdborton / spec_helper_jest.js
Created May 19, 2017 20:41
This bit of code essentially bridges the Mocha/Jest api so that Jest can be used in place of Mocha.
// There are other differences between Jest and Mocha,
// but these were the functions being used at Airbnb.
global.context = describe;
global.before = beforeAll;
global.after = afterEach;
@gdborton
gdborton / spec_helper_jest.js
Last active May 19, 2017 20:31
Reducing flake in JavaScript tests.
/**
* This set of beforeEach/afterEach functions serve to prevent code from
* being accidentally run outside of a test's context.
*
* Basically we catch all intervals and timeouts set during a test, and
* then clear them when the test is done running.
*/
const setTimeouts = [];
const setIntervals = [];
const originalSetTimeout = setTimeout;
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
class BetterCreep extends Creep {
constructor(creep) {
this._creep = creep;
}
work() {
this._creep.moveTo();
}
}