UNPKG

lawl-spec-reporter

Version:

Spec reporter for jasmine, based on jasmine-spec-reporter, outputs in LolSpeak

208 lines (175 loc) 5.29 kB
// Generated by CoffeeScript 1.9.2 (function() { var FakeEnv, Spec, Suite, Test, addMatchers, equalOrMatch, typeIsArray; require('colors'); String.prototype.__defineGetter__('stripTime', function() { return this.replace(/(\d+\.?\d*|\.\d+) SECZ/, '{time}'); }); typeIsArray = Array.isArray || function(value) { return {}.toString.call(value) === '[object Array]'; }; equalOrMatch = function(actual, expected) { return expected === actual || (expected.test && expected.test(actual)); }; addMatchers = function() { return beforeEach(function() { return jasmine.addMatchers({ contains: function() { return { compare: function(actual, sequence) { var i, j; if (!typeIsArray(sequence)) { sequence = [sequence]; } i = 0; while (i < actual.length - sequence.length + 1) { j = 0; while (j < sequence.length && equalOrMatch(actual[i + j], sequence[j])) { j++; } if (j === sequence.length) { return { pass: true }; } i++; } return { pass: false }; } }; } }); }); }; Test = (function() { function Test(reporter, testFn1) { this.reporter = reporter; this.testFn = testFn1; this.init(); this.run(); } Test.prototype.init = function() { var logInSummary; this.outputs = []; this.summary = []; logInSummary = false; return console.log = (function(_this) { return function(stuff) { stuff = stuff.stripColors.stripTime; if (/^(EXECUTD|\*\*\*\*\*\*\*)/.test(stuff)) { logInSummary = true; } if (!logInSummary) { return _this.outputs.push(stuff); } else { return _this.summary.push(stuff); } }; })(this); }; Test.prototype.run = function() { var env, k, len, ref, suite; env = new FakeEnv(this.testFn); this.reporter.jasmineStarted(); if (this.hasOnlyOneSuite(this.testFn)) { this.execSuite(env.queue[0]); } else { ref = env.queue; for (k = 0, len = ref.length; k < len; k++) { suite = ref[k]; this.reporter.suiteStarted(suite); this.execSuite(suite); this.reporter.suiteDone(suite); } } return this.reporter.jasmineDone(); }; Test.prototype.execSuite = function(suite) { var item, k, len, ref, results; ref = suite.queue; results = []; for (k = 0, len = ref.length; k < len; k++) { item = ref[k]; if (this.isSpec(item)) { this.reporter.specStarted(item); results.push(this.reporter.specDone(item)); } else { this.reporter.suiteStarted(item); this.execSuite(item); results.push(this.reporter.suiteDone(item)); } } return results; }; Test.prototype.isSpec = function(it) { return it.queue === void 0; }; Test.prototype.hasOnlyOneSuite = function(testFn) { return (testFn.toString().match(/describe/g) || []).length === 1; }; return Test; })(); FakeEnv = (function() { function FakeEnv(fn) { this.queue = []; fn.apply(this); } FakeEnv.prototype.describe = function(description, fn) { return this.queue.push(new Suite(description, description, fn)); }; return FakeEnv; })(); Suite = (function() { function Suite(description1, fullName, fn) { this.description = description1; this.fullName = fullName; this.queue = []; fn.apply(this); } Suite.prototype.describe = function(description, fn) { return this.queue.push(new Suite(description, this.fullName + ' ' + description, fn)); }; Suite.prototype.it = function(description, fn) { return this.queue.push(new Spec(description, this.fullName + ' ' + description, fn)); }; Suite.prototype.xit = function(description, fn) { var spec; spec = new Spec(description, this.fullName + ' ' + description, fn); spec.status = 'pending'; return this.queue.push(spec); }; return Suite; })(); Spec = (function() { function Spec(description1, fullName, fn) { this.description = description1; this.fullName = fullName; this.status = ''; this.failedExpectations = []; fn.apply(this); } Spec.prototype.passed = function(message) { if (message == null) { message = ''; } return this.status = 'passed'; }; Spec.prototype.failed = function(message) { if (message == null) { message = ''; } this.status = 'failed'; return this.failedExpectations.push({ message: message, stack: 'Error: Expectation\n{Stacktrace}', passed: false }); }; return Spec; })(); global.Test = Test; global.addMatchers = addMatchers; }).call(this); //# sourceMappingURL=test-helper.js.map