Skip to content

Commit

Permalink
Added support for ddescribe and iit for Jasmine2.0 branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiznool committed Aug 5, 2014
1 parent 8045968 commit 8d587e3
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/jasmine-node/jasmine-loader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 63 additions & 25 deletions lib/jasmine-node/jasmine/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/jasmine-loader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ executeSpecsInFolder = (options) ->
console.log error
throw error

jasmine.execute()
jasmine.executeFiltered()
return

module.exports = { executeSpecsInFolder, loadHelpersInFolder}
76 changes: 55 additions & 21 deletions src/jasmine/boot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand Down Expand Up @@ -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 = ->
Expand Down

0 comments on commit 8d587e3

Please sign in to comment.