An exploration of the different render methods available in react-enzyme.
View to-promise.js
const _ = require("highland"); | |
const { Readable } = require("stream"); | |
const wrapAsync = require("./wrap-async"); | |
const sleep = (duration) => | |
new Promise((resolve) => setTimeout(resolve, duration)); | |
class Counter extends Readable { | |
constructor(opt) { | |
super(opt); |
View box.css
.box { | |
display: block; | |
background: red; | |
width: 200px; | |
height: 200px; | |
opacity: 1; | |
} | |
.box-hidden { | |
display: none; |
View server.js
const express = require('express'); | |
console.log(process.version); | |
const app = express(); | |
app.get('/hello', (req, res) => { | |
console.log('HANDLING REQUEST'); | |
res.setHeader('content-type', 'application/json'); | |
res.flushHeaders(); // `flushHeaders` to prevent http client from retrying and therefore invoking this handler multiple times. |
View benchmark.js
// Originally from fast-memoize; updated to include `mem` and test multiple and non-primitive arguments. | |
const ora = require("ora"); | |
const Table = require("cli-table2"); | |
const debug = require("logdown")(); | |
const lruMemoize = require("lru-memoize").default; | |
const iMemoized = require("iMemoized"); | |
const Benchmark = require("benchmark"); | |
const underscore = require("underscore").memoize; | |
const lodash = require("lodash").memoize; |
View test.js
const work = () => { | |
for (let i = 0; i < 1000000; i++) {} | |
}; | |
const start = process.hrtime.bigint(); | |
work(); | |
const end = process.hrtime.bigint(); | |
console.log( | |
`Benchmark took ${Number(end - start) / 1000 / 1000 / 1000} seconds` | |
); |
View closest.ts
const closest = (values: number[], val: number) => { | |
if (!values.length) { | |
throw new VError( | |
{ info: { values, val } }, | |
'Expected values to contain at least one value' | |
); | |
} | |
return values.reduce( | |
(acc, currVal) => | |
Math.abs(acc.delta) > Math.abs(currVal - val) |
View index.js
// node --max-old-space-size=100 --expose-gc index.js | |
const prettyBytes = require('pretty-bytes'); | |
const forceGC = () => { | |
if (global.gc) { | |
global.gc(); | |
} else { | |
console.warn('No GC hook! Start your program as `node --expose-gc file.js`.'); | |
} |
View index.html
<!doctype html> | |
<html class="no-js" lang=""> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="x-ua-compatible" content="ie=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
<style> | |
* { |
NewerOlder