-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjasmine-focus.js
90 lines (75 loc) · 2.29 KB
/
jasmine-focus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function() {
if (! jasmineRequire) {
throw "jasmine library does not exist in global namespace!";
}
jasmineRequire.enableFocusTagging = function(jasmine){
var env = jasmine.getEnv();
var focusedSuites = [];
var focusedSpecs = [];
var insideFocusedSuite = false;
var focusSpec = function(env, description, body) {
var spec = env.it(description, body);
focusedSpecs.push(spec.id);
return spec;
};
var focusSuite = function(env, description, body) {
if (insideFocusedSuite) {
return env.describe(description, body);
}
insideFocusedSuite = true;
var suite = env.describe(description, body);
insideFocusedSuite = false
focusedSuites.push(suite.id);
return suite;
};
env.executeFiltered = function() {
if (focusedSpecs.length) {
env.execute(focusedSpecs);
} else if (focusedSuites.length) {
env.execute(focusedSuites);
} else {
env.execute();
}
};
focusMethods = {
describe: function(description, tagsOrSpecDefinitions, specDefinitions) {
if (tagsOrSpecDefinitions instanceof Function) {
return env.describe(description, tagsOrSpecDefinitions);
} else {
if (tagsOrSpecDefinitions.focus) {
return focusSuite(env, description, specDefinitions)
}
}
},
it: function(desc, tagsOrFunc, func) {
if (tagsOrFunc instanceof Function) {
return env.it(desc, tagsOrFunc);
} else {
if (tagsOrFunc.focus) {
return focusSpec(env, desc, func);
}
}
},
fdescribe: function(description, specDefinitions) {
return focusSuite(env, description, specDefinitions);
},
fit: function(desc, func) {
return focusSpec(env, desc, func);
}
};
globals = [];
if (typeof global !== "undefined" && global !== null) {
globals.push(global);
}
if (typeof window !== "undefined" && window !== null) {
globals.push(window);
}
for (methodName in focusMethods) {
methodBody = focusMethods[methodName];
for (_i = 0, _len = globals.length; _i < _len; _i++) {
object = globals[_i];
object[methodName] = methodBody;
}
}
}
})();