Skip to content

Instantly share code, notes, and snippets.

@MatejBransky
Last active January 12, 2023 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatejBransky/7e614dee54e0499eb4c5d23aba5325e0 to your computer and use it in GitHub Desktop.
Save MatejBransky/7e614dee54e0499eb4c5d23aba5325e0 to your computer and use it in GitHub Desktop.
general notes

Notes

mvp

blogs

enterprise

uncategorized

helpers

tools

how to develop

language specific

frameworks / libraries

interesting

learning

  • Patterns For Large-Scale JavaScript Application Architecture

  • OOP principles in React

  • DDD

  • DAO pattern

  • repository pattern

  • styled-components

  • MobX vs GraphQL Apollo

  • GraphQL/Apollo

  • Formik vs react-hook-form

  • Lodash

  • long polling (better WebSockets)

  • deep vs flat fodler structures

  • Jenkins

  • HashiCorp's suite (Terraform, Nomad, Vault, Consul), Sensu (scalable monitoring framework)

  • ELK stack

class BasePage {
private retryCount = 0;
/**
* Waits until the callback successfully resolves.
* @param cb async operation to retry if it fails
* @param retries xax count of retries
*
* @example
* await this.until(async () => {
* await this.sidebar.locator(`"${screenTitle}"`).click()
* await this.page
* .locator('[data-testid=title]', { hasText: screenTitle })
* .waitFor({ timeout: 1000 })
* })
*/
async until(cb: () => Promise<any>, retries = 3) {
try {
const output = await cb();
this.retryCount = 0;
return output;
} catch (e) {
if (this.retryCount < retries) {
this.retryCount++;
await this.until(cb, retries);
} else {
throw e;
}
}
}
}
/// <reference types="webpack-env" />
import { initMock } from "./browser";
export async function initMockWithDevConfig() {
/**
* get devConfig.ts and devConfig.local.ts files
* https://webpack.js.org/api/module-methods/#requirecontext
*
* Note: needs to be statically analyzable
* https://github.com/webpack/webpack/issues/4772#issuecomment-296798125
*/
const requireContext = require.context(
"../../../", // directory
false, // don't include subdirectories
/devConfig(\.local)?\.ts/, // filter
"lazy" // generates a lazy-loadable chunk for each import()ed module
);
/**
* 1. load each module (statically analyzable => required)
* 2. group it with fileName: ['devConfig.ts', module]
* 3. return object:
* {
* 'devConfig.ts': module,
* 'devConfig.local.ts': module
* }
*/
const modules = Object.fromEntries(
await Promise.all(
requireContext.keys().map((fileName) =>
// load module => ['devConfig.ts', module]
requireContext(fileName).then((mod: any) => [
fileName.split("/").pop(),
mod,
])
)
)
);
const { devConfig } =
modules["devConfig.local.ts"] || modules["devConfig.ts"];
const msw = initMock(devConfig);
await msw.worker.start({
// suppress warnings about unhandled requests
onUnhandledRequest: "bypass",
});
return msw;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment