From 8d587e35f9914f0b9c7597881595ba09503b3deb Mon Sep 17 00:00:00 2001 From: Tom Spencer Date: Tue, 5 Aug 2014 19:21:48 +0100 Subject: [PATCH] Added support for ddescribe and iit for Jasmine2.0 branch. --- lib/jasmine-node/jasmine-loader.js | 2 +- lib/jasmine-node/jasmine/boot.js | 88 +++++++++++++++++++++--------- src/jasmine-loader.coffee | 2 +- src/jasmine/boot.coffee | 76 +++++++++++++++++++------- 4 files changed, 120 insertions(+), 48 deletions(-) diff --git a/lib/jasmine-node/jasmine-loader.js b/lib/jasmine-node/jasmine-loader.js index 6f86a56..93c5887 100644 --- a/lib/jasmine-node/jasmine-loader.js +++ b/lib/jasmine-node/jasmine-loader.js @@ -173,7 +173,7 @@ throw error; } } - jasmine.execute(); + jasmine.executeFiltered(); }; module.exports = { diff --git a/lib/jasmine-node/jasmine/boot.js b/lib/jasmine-node/jasmine/boot.js index 2032a3f..d312e6a 100755 --- a/lib/jasmine-node/jasmine/boot.js +++ b/lib/jasmine-node/jasmine/boot.js @@ -8,7 +8,7 @@ junitReporter = require('../junit-reporter'); boot = function(jasmineRequire, clockCallback) { - var clockInstaller, clockUninstaller, env, extend, jasmine, jasmineInterface; + var clockInstaller, clockUninstaller, env, extend, focuseSpec, focuseSuite, focusedSpecs, focusedSuites, insideFocusedSuite, jasmine, jasmineInterface, wrapSpecFunc; jasmine = jasmineRequire.core(jasmineRequire); /* @@ -30,6 +30,52 @@ jasmine.TerminalReporter = nodeReporters.TerminalReporter; jasmine.JUnitReporter = junitReporter.JUnitReporter; jasmine.GrowlReporter = growlReporter; + focusedSuites = []; + focusedSpecs = []; + insideFocusedSuite = false; + focuseSpec = function(env, description, body) { + var spec; + spec = env.it(description, body); + focusedSpecs.push(spec.id); + return spec; + }; + focuseSuite = function(env, description, body) { + var suite; + if (insideFocusedSuite) { + return env.describe(description, body); + } + insideFocusedSuite = true; + suite = env.describe(description, body); + insideFocusedSuite = false; + focusedSuites.push(suite.id); + return suite; + }; + wrapSpecFunc = function(func) { + var spec, wrappedDone, wrappedFunc; + spec = { + done: false, + doneFunc: function() {}, + returned: false + }; + wrappedFunc = func; + wrappedDone = function() { + spec.done = true; + if (spec.returned) { + return spec.doneFunc(); + } + }; + if (func.length > 0) { + wrappedFunc = function(done) { + spec.doneFunc = done; + func.call(this, wrappedDone); + spec.returned = true; + if (spec.done) { + return spec.doneFunc(); + } + }; + } + return wrappedFunc; + }; /* *# The Global Interface @@ -40,34 +86,17 @@ describe: function(description, specDefinitions) { return env.describe(description, specDefinitions); }, + ddescribe: function(description, specDefinitions) { + return focuseSuite(env, description, specDefinitions); + }, xdescribe: function(description, specDefinitions) { return env.xdescribe(description, specDefinitions); }, it: function(desc, func) { - var spec, wrappedDone, wrappedFunc; - spec = { - done: false, - doneFunc: function() {}, - returned: false - }; - wrappedFunc = func; - wrappedDone = function() { - spec.done = true; - if (spec.returned) { - return spec.doneFunc(); - } - }; - if (func.length > 0) { - wrappedFunc = function(done) { - spec.doneFunc = done; - func.call(this, wrappedDone); - spec.returned = true; - if (spec.done) { - return spec.doneFunc(); - } - }; - } - return env.it(desc, wrappedFunc); + return env.it(desc, wrapSpecFunc(func)); + }, + iit: function(desc, func) { + return focuseSpec(env, desc, wrapSpecFunc(func)); }, xit: function(desc, func) { return env.xit(desc, func); @@ -94,6 +123,15 @@ */ extend(global, jasmineInterface); global.jasmine = jasmine; + env.executeFiltered = function() { + if (focusedSpecs.length) { + return env.execute(focusedSpecs); + } else if (focusedSuites.length) { + return env.execute(focusedSuites); + } else { + return env.execute(); + } + }; clockInstaller = jasmine.currentEnv_.clock.install; clockUninstaller = jasmine.currentEnv_.clock.uninstall; jasmine.currentEnv_.clock.install = function() { diff --git a/src/jasmine-loader.coffee b/src/jasmine-loader.coffee index 9593c24..faee211 100644 --- a/src/jasmine-loader.coffee +++ b/src/jasmine-loader.coffee @@ -152,7 +152,7 @@ executeSpecsInFolder = (options) -> console.log error throw error - jasmine.execute() + jasmine.executeFiltered() return module.exports = { executeSpecsInFolder, loadHelpersInFolder} diff --git a/src/jasmine/boot.coffee b/src/jasmine/boot.coffee index 07b5cc4..5ab5355 100644 --- a/src/jasmine/boot.coffee +++ b/src/jasmine/boot.coffee @@ -23,6 +23,47 @@ boot = (jasmineRequire, clockCallback) -> jasmine.JUnitReporter = junitReporter.JUnitReporter jasmine.GrowlReporter = growlReporter + # Focussed spec and suite holders + focusedSuites = [] + focusedSpecs = [] + insideFocusedSuite = false + + focuseSpec = (env, description, body) -> + spec = env.it description, body + focusedSpecs.push spec.id + spec + + focuseSuite = (env, description, body) -> + return env.describe(description, body) if insideFocusedSuite + insideFocusedSuite = true + suite = env.describe(description, body) + insideFocusedSuite = false + focusedSuites.push suite.id + suite + + wrapSpecFunc = (func) -> + spec = + done: false + doneFunc: -> return + returned: false + wrappedFunc = func + wrappedDone = -> + spec.done = true + if spec.returned + return spec.doneFunc() + return + + if func.length > 0 + wrappedFunc = (done) -> + spec.doneFunc = done + func.call(@, wrappedDone) + spec.returned = true + if spec.done + return spec.doneFunc() + return + + wrappedFunc + ### ## The Global Interface * @@ -32,32 +73,17 @@ boot = (jasmineRequire, clockCallback) -> describe: (description, specDefinitions) -> return env.describe description, specDefinitions + ddescribe: (description, specDefinitions) -> + return focuseSuite env, description, specDefinitions + xdescribe: (description, specDefinitions) -> return env.xdescribe description, specDefinitions it: (desc, func) -> - spec = - done: false - doneFunc: -> return - returned: false - wrappedFunc = func - wrappedDone = -> - spec.done = true - if spec.returned - return spec.doneFunc() - return - - if func.length > 0 - wrappedFunc = (done) -> - spec.doneFunc = done - func.call(@, wrappedDone) - spec.returned = true - if spec.done - return spec.doneFunc() - return + return env.it desc, wrapSpecFunc(func) - - return env.it desc, wrappedFunc + iit: (desc, func) -> + return focuseSpec env, desc, wrapSpecFunc(func) xit: (desc, func) -> return env.xit desc, func @@ -89,6 +115,14 @@ boot = (jasmineRequire, clockCallback) -> extend global, jasmineInterface global.jasmine = jasmine + env.executeFiltered = -> + if focusedSpecs.length + env.execute focusedSpecs + else if focusedSuites.length + env.execute focusedSuites + else + env.execute() + clockInstaller = jasmine.currentEnv_.clock.install clockUninstaller = jasmine.currentEnv_.clock.uninstall jasmine.currentEnv_.clock.install = ->