JSFiddle - React, Tailwind, and code Playground

by danShumway

JavaScript

const GLOBAL = 'Distilled'; //TODO: what's the point of `const` here other than nerd cred and locking out old browsers?
const STATUS = Object.freeze({
    PASSED : 'passed',
    FAILED : 'failed',
    PENDING : 'pending',
    SKIPPED : 'skipped',
});
const ENVIRONMENTS = Object.freeze({
    NODE : 'node',
    BROWSER : 'browser',
});
const REPORTERS = Object.freeze({
    default : (function () {
        var buffer = '';
        var log = function (message) {
            if (environment === ENVIRONMENTS.NODE) {
                process.stdout.write(message);
            } else if (console.clear) {
                buffer = buffer + message;
                console.clear();
                console.log(buffer);
            } else {
                consoe.log(message);
            }
        };

        var failPath = function(group) {
            if (group.parent == null) { return '()'; }
            return failPath(group.parent) + '(' + group.label + ')';
        };

        return function (group) {
            if (group.parent == null) { return; }
            if (group.status === STATUS.PASSED) {
                log('.');
            } else {
                log('X');
                log('\n\n' + failPath(group) + ' failed!');

                if(group.error) {
                    if (typeof group.error.expected !== 'undefined') {
                        log('\nExpected: ' + group.error.expected);
                        log('\nActual: ' + group.error.actual);
                    }

                    log('\n' + group.error.stack);
                }

                log('\n\n');

                if(environment === ENVIRONMENTS.NODE) {
                    process.exitCode = 1;
                }
            }
        };
    }()),
});

var environment = (function () {
    if (typeof process !== 'undefined') {
        return ENVIRONMENTS.NODE;
    } else if (typeof window !== 'undefined') {
        return ENVIRONMENTS.BROWSER;
    }

    //TODO detect promise...