Skip to content

Instantly share code, notes, and snippets.

View craigtaub's full-sized avatar

Craig Taub craigtaub

View GitHub Profile
Mocha.prototype.run = function (fn) {
var suite = this.suite;
var options = this.options;
options.files = this.files;
var runner = new Runner(suite, options.delay);
createStatsCollector(runner);
var reporter = new this._reporter(runner, options);
const noop = () => "";
function done(failures) {
Mocha.prototype.loadFilesAsync = async function () {
var self = this;
var suite = this.suite;
for (let file of this.files) {
// preload
suite.emit(Suite.constants.EVENT_FILE_PRE_REQUIRE, global, file, self);
// load
file = path.resolve(file);
const result = await require(file);
async function runMocha(mocha, options) {
const { spec = [] } = options;
// if options.watch watchRun()
// singleRun
// collectFiles and lookupFiles here
mocha.files = spec;
await mocha.loadFilesAsync();
return mocha.run(exitMochaLater);
function Mocha(options) {
this.files = [];
this.options = options;
// lib/context.js. empty context
function Context() {}
// root suite
this.suite = new Suite("", new Context(), true);
this.ui(options.ui).reporter(options.reporter);
bdd: function bddInterface(suite) {
var suites = [suite];
suite.on(Suite.constants.EVENT_FILE_PRE_REQUIRE, function (
context,
file,
mocha
) {
var common = Mocha.interfaces.common(suites, context, mocha);
// lib cli/cli.js main()
const argv = process.argv.slice(2);
// lib/cli/options loadOptions()
var args = yargsParser.detailed(argv).argv;
args._ = Array.from(new Set(args._));
yargs()
.scriptName("our_mocha")
.command(commands.run)
.fail((msg, err, yargs) => {
const builder = (yargs) => {
// cli/run.js builder()
return yargs
.options({
config: {
config: true,
description: "Path to config file",
},
reporter: {
default: defaults.reporter,
@craigtaub
craigtaub / ssr architecture
Last active May 18, 2020 14:52
SSR architecture
1. User requests (dns lookup etc)
2. Server receives request
- Express
- Returns below in 0.25ms.
<html>
<script google-analytics>
<body>
<div>hey there</div>
<script app.js>
// Process program
ast.program.body.map(stnmt => {
switch (stnmt.type) {
case "FunctionDeclaration":
stnmt.params.map(arg => {
// Does arg has a type annotation?
if (arg.typeAnnotation) {
const argType = arg.typeAnnotation.typeAnnotation.type;
// Is type annotation valid
const isValid = typeChecks.annotationCheck(argType);
const errors = [];
const ANNOTATED_TYPES = {
NumberTypeAnnotation: "number",
GenericTypeAnnotation: true
};
// Logic for type checks
const typeChecks = {
expression: (declarationFullType, callerFullArg) => {