UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

149 lines (103 loc) 4.04 kB
// wrapper !function () { var currentTest var actionsLog = [] var idsToTest = {} var doneById = {} var isLive = false var SiestaReporter = { processAction : function (action) { if (isLive) action() else actionsLog.push(action) }, jasmineStarted: function (suiteInfo) { this.processAction(function () { currentTest.diag('Launching Jasmine test suite, total specs: ' + suiteInfo.totalSpecsDefined) }) }, suiteStarted: function (result) { this.processAction(function () { var currentCopy = currentTest var subTest = currentCopy.getSubTest({ name : result.description, run : function (t) { t.waitFor({ method : function () { return Boolean(doneById[ result.id ]) }, desc : "Suite " + result.description + " has failed to complete within " + t.defaultTimeout + "ms", callback : function () { var doneSpec = idsToTest[ result.id ] var failedExp = result.failedExpectations for (var i = 0; i < failedExp.length; i++) { doneSpec.fail(failedExp[ i ].message, failedExp[ i ].stack) } } }) }, specType : 'describe', timeout : 10 * 60 * 1000 }) currentTest = subTest idsToTest[ result.id ] = subTest currentCopy.launchSubTest(subTest) }) }, specStarted: function (result) { this.processAction(function () { var currentCopy = currentTest var subTest = currentCopy.getSubTest({ name : result.description, run : function (t) { t.waitFor({ method : function () { return Boolean(doneById[ result.id ]) }, desc : "Spec " + result.description + " has failed to complete within " + t.defaultTimeout + "ms", callback : function () { var doneSpec = idsToTest[ result.id ] var failedExp = result.failedExpectations for (var i = 0; i < failedExp.length; i++) { doneSpec.fail(failedExp[ i ].message, failedExp[ i ].stack) } if (!failedExp.length && result.passedExpectations.length) doneSpec.pass(result.passedExpectations.length + " expectations passed") } }) }, specType : 'it', timeout : 10 * 60 * 1000 }) currentTest = subTest idsToTest[ result.id ] = subTest currentCopy.launchSubTest(subTest) }) }, specDone : function (result) { doneById[ result.id ] = result this.processAction(function () { var doneSpec = idsToTest[ result.id ] currentTest = doneSpec.parent }) }, suiteDone: function (result) { doneById[ result.id ] = result this.processAction(function () { var doneSpec = idsToTest[ result.id ] currentTest = doneSpec.parent }) }, jasmineDone: function () { }, importResults : function (t) { currentTest = t for (var i = 0; i < actionsLog.length; i++) { actionsLog[ i ]() } isLive = true } } if (window.jasmine) { jasmine.currentEnv_.addReporter(SiestaReporter) jasmine.SiestaReporter = SiestaReporter } // wrapper }();