| const minute = 60; | |
| const hour = minute * 60; | |
| const day = hour * 24; | |
| const week = day * 7; | |
| const month = day * 30; | |
| const year = day * 365; | |
| /** | |
| * Convert a date to a relative time string, such as | |
| * "a minute ago", "in 2 hours", "yesterday", "3 months ago", etc. |
The ESM standard is considered stable in NodeJS and well supported by a lot of modern JavaScript tools.
ESLint does a good job validating and fixing ESM code (as long as you don't use top-level await, coming in ESLint v8). Make sure to enable the latest ECMA features in the ESLint config.
- .eslint.json
{| import { useCustomElement } from "./useCustomElement"; | |
| // My regular react app that is using a web component / | |
| // custom element inside it. | |
| // Notice that we have some handlers, some state, etc. | |
| function Component() { | |
| const [txt, setTxt] = React.useState("init") | |
| function handleClick() { | |
| setTxt("clicked") | |
| } |
| import * as path from 'path' | |
| import ts from 'typescript' | |
| function build( | |
| override: { | |
| compilerOptions?: ts.CompilerOptions | |
| include?: string[] | |
| exclude?: string[] | |
| files?: string[] | |
| extends?: string |
Thanks to React hooks you have now happily turned all your classes into functional components.
Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.
There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.
| { | |
| "comment": "This is the settings file for the SVGO Compressor Plugin. For more info, please check <https://github.com/BohemianCoding/svgo-compressor>", | |
| "pretty": true, | |
| "indent": 2, | |
| "floatPrecision": 3, | |
| "plugins": [ | |
| { | |
| "name": "removeDoctype", | |
| "enabled": true | |
| }, |
| import React, { useState, useEffect, createContext, useContext } from "react"; | |
| import { render } from "react-dom"; | |
| import { BehaviorSubject, isObservable } from "rxjs"; | |
| const Context = createContext(); | |
| const Provider = Context.Provider; | |
| const useStream = initialState => { | |
| let source = isObservable(initialState) | |
| ? initialState |
This is a walkthrough of how to set up Visual Regression Testing with Jest for an application created with create-react-app.
The following walkthrough uses React as an example, but the approach should work for any modern frontend library! I assume it can be used with Angular, Vue, Cycle.js and more.
This gist walks you through a create-react-app application as an example of how to set up Visual Regression Testing in Jest using libraries I wrote recently which enable this: jsdom-screenshot, jest-transform-css and jest-transform-file.
