Skip to content

Instantly share code, notes, and snippets.

View theKashey's full-sized avatar
🤔
what's happening?

Anton Korzunov theKashey

🤔
what's happening?
View GitHub Profile
@theKashey
theKashey / preoxyquire.js
Created December 12, 2017 02:17
"Proxyquire" inside the Jest
// anywhere
import proxyquire from '....../proxyquire.js'
// proxyquire.js
// use rewiremock to mock proxyquire
import rewiremock, { addPlugin, plugins, overrideEntryPoint } from 'rewiremock';
import stackTrace from 'stack-trace';
rewiremock.requireActual('babel-register');
@theKashey
theKashey / .yarnrc
Last active November 5, 2023 06:08
using yarn 2 plugin to run "postinstall script"
#....
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
- .yarn/plugins/ts-referent-plugin.cjs ### ⬅️ ⬅️ ⬅️ ⬅️
@theKashey
theKashey / prefetchWorker.js
Created October 11, 2019 02:24
cloudflare HTTP(not HTML!) prefetch
// see cloudflare workers - https://workers.cloudflare.com
addEventListener('fetch', event => {
event.respondWith(fetchAndStream(event.request))
})
async function fetchAndStream(request) {
let streamResponse = fetch(request); // dont await, as majority of CF examples do
let { readable, writable } = new TransformStream()
@theKashey
theKashey / plugin.ts
Created May 22, 2021 08:21
Node Workers based Webpack StartServerPlugin
import { Worker } from "worker_threads";
import type { Compiler, compilation, Plugin } from "webpack";
interface Options {
name: string;
require?: string[];
keyboard?: boolean;
}
body {
padding-right: {ScrollBarWidth}px;
}
import { useState, useEffect } from 'react';
type UseResizeObserverCallback = (ref: Element) => void;
type ResizeObserverCallback = (
entries: IResizeObserverEntry[],
observer: ResizeObserver,
) => void;
interface IResizeObserverEntry {
@theKashey
theKashey / .babelrc
Last active August 1, 2020 09:46
storybook rewiremock
...
"plugins": [
"rewiremock/babel", // babel plugin is required to use "Jest-style" mocking
]
...
@theKashey
theKashey / scroll-memory.js
Created July 3, 2020 23:22
scroll-memory
import React from "react";
import { withRouter } from "react-router-dom";
import { getPageScroll, scrollTo } from "./utils";
const ScrollContext = React.createContext(new Map());
const getLocationKey = location => `${location.pathname}?${location.search}`;
const ScrollMemory = ({ children, history: _history, location }) => {
import test from 'ava';
import sinon from 'sinon';
// ^ uses a real FS
// nothing before would be mocked
import rewiremock from 'rewiremock/node';
import mockfs from 'mock-fs';
import mountfs from 'mountfs';
import fs from 'fs';
@theKashey
theKashey / story-machine.js
Created April 30, 2020 07:07
kills-state
const initial = {};
const fetchMachine = Machine({
id: 'panel',
initial: 'waiting',
context: initial,
states: {
waiting: {
// always reset to initial context
entry: assign(() => null),
on: {