Skip to content

Instantly share code, notes, and snippets.

View craigtaub's full-sized avatar

Craig Taub craigtaub

View GitHub Profile
@craigtaub
craigtaub / Markdown reporter.md
Last active November 13, 2024 05:12
md-reporter.md

TOC

Add

should add numbers correctly.

equal(add(2, 3), 5);
Runner.prototype.hooks = function(name, callback) {
function next(suite) {
if (!suite) callback()
hook(name, () => {
next(suites.pop()) // run hooks for next suite
})
}
next()
}
Runner.prototype.runTest = function(fn) {
var self = this
var test = this.test
if (!test) return
try {
// 1. run the test
test.run(fn)
} catch (err) {
Runner.prototype.runTests = function(callback) {
function next() {
// grab next test
test = tests.shift()
// no tests left, run callback running next suite
if (!test) callback()
// run beforeEach hooks
hooks(HOOK_TYPE_BEFORE_EACH, () => {
runTest(err => {
if (err) {
Runner.prototype.hook = function (name, fn) {
// 1. for current suite, get hooks with name x
var hooks = this.suite.getHooks(name);
function next(i){
// 3. grab current hook
var hook = hooks[i];
// 4. executed all hooks under name x for suite
if (!hook) fn()
Runner.prototype.runSuite = function (suite, fn) {
this.emit(EVENT_SUITE_BEGIN, (this.suite = suite))
function done(errSuite) {
// 6. run all afterAll hooks
self.hook(HOOK_TYPE_AFTER_ALL, () => {
self.emit(EVENT_SUITE_END, suite);
fn(errSuite);
});
}
Runner.prototype.run = function(fn) {
var self = this
var rootSuite = this.suite
fn = fn || function() {}
function start() {
self.started = true
self.emit(Runner.constants.EVENT_RUN_BEGIN)
self.runSuite(rootSuite, function() {
self.emit(Runner.constants.EVENT_RUN_END)
Base.prototype.epilogue = function() {
var stats = this.stats
Base.consoleLog()
// passes
var fmt =
color("bright pass", " ") +
color("green", " %d passing") +
color("light", " (%s)")
function Spec(runner, options) {
Base.call(this, runner, options);
runner.on(Runner.constants.EVENT_RUN_BEGIN, function () {
Base.consoleLog();
});
// more ....
runner.on(Runner.constants.EVENT_TEST_PASS, function (test) {
// lib/stats-collector.js
function createStatsCollector(runner) {
var stats = {
suites: 0,
tests: 0,
passes: 0,
pending: 0,
failures: 0,
};