Skip to content

Commit f88a5d4

Browse files
committed
Added support for ddescribe and iit for Jasmine2.0 branch.
1 parent 46ade47 commit f88a5d4

File tree

4 files changed

+120
-48
lines changed

4 files changed

+120
-48
lines changed

lib/jasmine-node/jasmine-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/jasmine-node/jasmine/boot.js

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
junitReporter = require('../junit-reporter');
99

1010
boot = function(jasmineRequire, clockCallback) {
11-
var clockInstaller, clockUninstaller, env, extend, jasmine, jasmineInterface;
11+
var clockInstaller, clockUninstaller, env, extend, focuseSpec, focuseSuite, focusedSpecs, focusedSuites, insideFocusedSuite, jasmine, jasmineInterface, wrapSpecFunc;
1212
jasmine = jasmineRequire.core(jasmineRequire);
1313

1414
/*
@@ -30,6 +30,52 @@
3030
jasmine.TerminalReporter = nodeReporters.TerminalReporter;
3131
jasmine.JUnitReporter = junitReporter.JUnitReporter;
3232
jasmine.GrowlReporter = growlReporter;
33+
focusedSuites = [];
34+
focusedSpecs = [];
35+
insideFocusedSuite = false;
36+
focuseSpec = function(env, description, body) {
37+
var spec;
38+
spec = env.it(description, body);
39+
focusedSpecs.push(spec.id);
40+
return spec;
41+
};
42+
focuseSuite = function(env, description, body) {
43+
var suite;
44+
if (insideFocusedSuite) {
45+
return env.describe(description, body);
46+
}
47+
insideFocusedSuite = true;
48+
suite = env.describe(description, body);
49+
insideFocusedSuite = false;
50+
focusedSuites.push(suite.id);
51+
return suite;
52+
};
53+
wrapSpecFunc = function(func) {
54+
var spec, wrappedDone, wrappedFunc;
55+
spec = {
56+
done: false,
57+
doneFunc: function() {},
58+
returned: false
59+
};
60+
wrappedFunc = func;
61+
wrappedDone = function() {
62+
spec.done = true;
63+
if (spec.returned) {
64+
return spec.doneFunc();
65+
}
66+
};
67+
if (func.length > 0) {
68+
wrappedFunc = function(done) {
69+
spec.doneFunc = done;
70+
func.call(this, wrappedDone);
71+
spec.returned = true;
72+
if (spec.done) {
73+
return spec.doneFunc();
74+
}
75+
};
76+
}
77+
return wrappedFunc;
78+
};
3379

3480
/*
3581
*# The Global Interface
@@ -40,34 +86,17 @@
4086
describe: function(description, specDefinitions) {
4187
return env.describe(description, specDefinitions);
4288
},
89+
ddescribe: function(description, specDefinitions) {
90+
return focuseSuite(env, description, specDefinitions);
91+
},
4392
xdescribe: function(description, specDefinitions) {
4493
return env.xdescribe(description, specDefinitions);
4594
},
4695
it: function(desc, func) {
47-
var spec, wrappedDone, wrappedFunc;
48-
spec = {
49-
done: false,
50-
doneFunc: function() {},
51-
returned: false
52-
};
53-
wrappedFunc = func;
54-
wrappedDone = function() {
55-
spec.done = true;
56-
if (spec.returned) {
57-
return spec.doneFunc();
58-
}
59-
};
60-
if (func.length > 0) {
61-
wrappedFunc = function(done) {
62-
spec.doneFunc = done;
63-
func.call(this, wrappedDone);
64-
spec.returned = true;
65-
if (spec.done) {
66-
return spec.doneFunc();
67-
}
68-
};
69-
}
70-
return env.it(desc, wrappedFunc);
96+
return env.it(desc, wrapSpecFunc(func));
97+
},
98+
iit: function(desc, func) {
99+
return focuseSpec(env, desc, wrapSpecFunc(func));
71100
},
72101
xit: function(desc, func) {
73102
return env.xit(desc, func);
@@ -94,6 +123,15 @@
94123
*/
95124
extend(global, jasmineInterface);
96125
global.jasmine = jasmine;
126+
env.executeFiltered = function() {
127+
if (focusedSpecs.length) {
128+
return env.execute(focusedSpecs);
129+
} else if (focusedSuites.length) {
130+
return env.execute(focusedSuites);
131+
} else {
132+
return env.execute();
133+
}
134+
};
97135
clockInstaller = jasmine.currentEnv_.clock.install;
98136
clockUninstaller = jasmine.currentEnv_.clock.uninstall;
99137
jasmine.currentEnv_.clock.install = function() {

src/jasmine-loader.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ executeSpecsInFolder = (options) ->
152152
console.log error
153153
throw error
154154

155-
jasmine.execute()
155+
jasmine.executeFiltered()
156156
return
157157

158158
module.exports = { executeSpecsInFolder, loadHelpersInFolder}

src/jasmine/boot.coffee

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,47 @@ boot = (jasmineRequire, clockCallback) ->
2323
jasmine.JUnitReporter = junitReporter.JUnitReporter
2424
jasmine.GrowlReporter = growlReporter
2525

26+
# Focussed spec and suite holders
27+
focusedSuites = []
28+
focusedSpecs = []
29+
insideFocusedSuite = false
30+
31+
focuseSpec = (env, description, body) ->
32+
spec = env.it description, body
33+
focusedSpecs.push spec.id
34+
spec
35+
36+
focuseSuite = (env, description, body) ->
37+
return env.describe(description, body) if insideFocusedSuite
38+
insideFocusedSuite = true
39+
suite = env.describe(description, body)
40+
insideFocusedSuite = false
41+
focusedSuites.push suite.id
42+
suite
43+
44+
wrapSpecFunc = (func) ->
45+
spec =
46+
done: false
47+
doneFunc: -> return
48+
returned: false
49+
wrappedFunc = func
50+
wrappedDone = ->
51+
spec.done = true
52+
if spec.returned
53+
return spec.doneFunc()
54+
return
55+
56+
if func.length > 0
57+
wrappedFunc = (done) ->
58+
spec.doneFunc = done
59+
func.call(@, wrappedDone)
60+
spec.returned = true
61+
if spec.done
62+
return spec.doneFunc()
63+
return
64+
65+
wrappedFunc
66+
2667
###
2768
## The Global Interface
2869
*
@@ -32,32 +73,17 @@ boot = (jasmineRequire, clockCallback) ->
3273
describe: (description, specDefinitions) ->
3374
return env.describe description, specDefinitions
3475

76+
ddescribe: (description, specDefinitions) ->
77+
return focuseSuite env, description, specDefinitions
78+
3579
xdescribe: (description, specDefinitions) ->
3680
return env.xdescribe description, specDefinitions
3781

3882
it: (desc, func) ->
39-
spec =
40-
done: false
41-
doneFunc: -> return
42-
returned: false
43-
wrappedFunc = func
44-
wrappedDone = ->
45-
spec.done = true
46-
if spec.returned
47-
return spec.doneFunc()
48-
return
49-
50-
if func.length > 0
51-
wrappedFunc = (done) ->
52-
spec.doneFunc = done
53-
func.call(@, wrappedDone)
54-
spec.returned = true
55-
if spec.done
56-
return spec.doneFunc()
57-
return
83+
return env.it desc, wrapSpecFunc(func)
5884

59-
60-
return env.it desc, wrappedFunc
85+
iit: (desc, func) ->
86+
return focuseSpec env, desc, wrapSpecFunc(func)
6187

6288
xit: (desc, func) ->
6389
return env.xit desc, func
@@ -89,6 +115,14 @@ boot = (jasmineRequire, clockCallback) ->
89115
extend global, jasmineInterface
90116
global.jasmine = jasmine
91117

118+
env.executeFiltered = ->
119+
if focusedSpecs.length
120+
env.execute focusedSpecs
121+
else if focusedSuites.length
122+
env.execute focusedSuites
123+
else
124+
env.execute()
125+
92126
clockInstaller = jasmine.currentEnv_.clock.install
93127
clockUninstaller = jasmine.currentEnv_.clock.uninstall
94128
jasmine.currentEnv_.clock.install = ->

0 commit comments

Comments
 (0)