Skip to content

Instantly share code, notes, and snippets.

View janhesters's full-sized avatar
📈
Learning.

Jan Hesters janhesters

📈
Learning.
View GitHub Profile
@janhesters
janhesters / package.json
Created September 26, 2020 12:32
Package.json scripts.
"format": "echo 'Linting ...' && npm run -s lint --fix && echo 'Lint complete.'",
"lint": "eslint --ignore-path .gitignore .",
"test": "NODE_ENV=test riteway -r @babel/register 'src/**/*.test.js'",
"watch": "watch 'clear && npm run -s test | tap-nirvana && npm run -s format' src"
@janhesters
janhesters / .babelrc.json
Created September 26, 2020 12:31
Configure Babel.
{
"env": {
"test": {
"plugins": [
[
"module-resolver",
{
"root": [
"."
],
@janhesters
janhesters / .prettierrc.json
Created September 26, 2020 12:30
Configure Prettier
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
@janhesters
janhesters / .eslintrc.json
Created September 26, 2020 12:29
Configure ESLint.
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
@janhesters
janhesters / jsconfig.json
Created September 26, 2020 12:28
Absolute imports.
{
"compilerOptions": {
"baseUrl": "./src"
}
}
@janhesters
janhesters / selector-tests.js
Created September 26, 2020 08:57
Selector tests and setup with root reducer and actions array.
// root-reducer.js
const rootReducer = combineReducers({ /* ... */ });
const rootState = rootReducer(undefined, {});
export { rootReducer, rootState };
// in counter-reducer.test.js
import { rootReducer, rootState } from 'redux/root-reducer.js';
import { setOffset } from 'features/offset/offset-reducer.js';
@janhesters
janhesters / create-populated-state-usage.js
Created September 26, 2020 08:55
Setup with populated state factory function.
{
const summand = 1;
const state = createPopulatedState();
assert({
given: 'state with a count and an increment by action',
should: 'increment the count by the payload',
actual: reducer(state, incrementBy(summand)),
expected: createPopulatedState({ count: 42 /* , ... rest untouched */ }),
});
@janhesters
janhesters / exporting-initial-state-bad.js
Created September 26, 2020 08:49
Avoid exporting your initial state.
// 👇 Avoid exporting your initial state 🚫
export const initialState = {
wrongKey: 'foo',
correctKey: 'wrong value'
/* missing keys ... */
};
assert({
given: 'no arguments',
should: 'return the valid initial state',
@janhesters
janhesters / unit-testing-reducers.js
Created September 26, 2020 08:46
Reducer with unit tests.
import { combineReducers } from 'redux';
import { describe } from 'riteway';
const slice = 'count';
const initial = {
count: 0,
};
const incrementBy = payload => ({ type: incrementBy.type, payload });
incrementBy.type = `${slice}/incrementBy`;
@janhesters
janhesters / master.yml
Last active August 27, 2020 09:17
A GitHub workflow example for conventional commits.
name: Master - Build and Deploy
on:
push:
branches:
- master
jobs:
re-check:
strategy:
fail-fast: false
matrix: