JSFiddle - React, Tailwind, and code Playground

by Daniel Lizik

JavaScript

(function(global, appName, factory) {
  'use strict';

  if (global.module && typeof global.module.exports === 'object')
    return module.exports = factory;
  if (global.define && typeof global.define === 'function')
    return define(appName, [factory]);
  return global[appName] = factory;

})(this, 'bicycle', (function(lib) {

  function Suite(describe) {
    this.describe = describe;
    this.specs = [];
    return this;
  }

  Suite.prototype.it = function(behavior, fn) {
    this.specs.push({it: behavior, assertions: []});
    fn.call(this);
    return this;
  };

  function executor(fn) {
    var self = this;
    return function() {
      //will always reference the current spec of all the assertions in the same callback
      var curr = this.specs[this.specs.length - 1];
      var args = Array.prototype.slice.call(arguments).map(a => a);
      var result = {args: args};
      try {
        result.result = fn.apply(this, args);
      }
      catch(e) {
        result.result = e.message;
      }
      curr.assertions.push(result);
    }
  }

  //recursively setup prototype methods from lib via executor
  (function setup(obj, branch) {
    for (var p in obj) {
      if (typeof obj[p] === 'object') {
        branch[p] = {};
        branch[p].prototype = branch;
        setup(obj[p], branch[p]);
      }
      else if (typeof obj[p] === 'function')
        branch[p] = executor.call(Suite, obj[p]);
    }
  })(lib, Suite.prototype);

  return {
    Suite: Suite
  };

})(

  {
    assert: {
      equals: function(a, b) {
        var args = Array.prototype.slice.call(arguments);
        if (!a || !b)
          throw new Error('missing argument: expecting 2, got ' + arguments.length);
        if (a !== b)
          throw new Error('arguments do not equal one another');
        return true;
      },
      deepEquals: function(a, b) {

      }
    },
    expectLength: function(a, b) {
      if (a.length !== b)
        throw new Error('b does not match a length where b...