js-test-driver-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/README +40 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/js_test_driver.rb +5 -1
- data/lib/js_test_driver/config.rb +84 -7
- data/lib/js_test_driver/html_fixture.rb +40 -0
- data/lib/js_test_driver/runner.rb +21 -3
- data/test/fixtures/a.html +1 -0
- data/test/fixtures/b.html +1 -0
- data/test/fixtures/baz/a.html +1 -0
- data/test/fixtures/c.html +1 -0
- data/test/fixtures/foo/a.html +1 -0
- data/test/fixtures/foo/bar/a.html +1 -0
- data/test/fixtures/hello.txt +1 -0
- data/test/test_helper.rb +19 -0
- data/test/unit/config_test.rb +75 -2
- data/test/unit/html_fixture_test.rb +70 -0
- data/vendor/VERSIONS +3 -0
- data/vendor/jasmine-jstd-adapter/MIT.LICENSE +22 -0
- data/vendor/jasmine-jstd-adapter/README.md +25 -0
- data/vendor/jasmine-jstd-adapter/jsTestDriver.conf +6 -0
- data/vendor/jasmine-jstd-adapter/lib/jasmine/jasmine-0.11.1.js +2343 -0
- data/vendor/jasmine-jstd-adapter/lib/jstestdriver/JsTestDriver.jar +0 -0
- data/vendor/jasmine-jstd-adapter/server.sh +1 -0
- data/vendor/jasmine-jstd-adapter/src-test/tests.js +89 -0
- data/vendor/jasmine-jstd-adapter/src/JasmineAdapter.js +111 -0
- data/vendor/jasmine-jstd-adapter/test.sh +1 -0
- data/vendor/jasmine/Gemfile +6 -0
- data/vendor/jasmine/MIT.LICENSE +20 -0
- data/vendor/jasmine/README.markdown +28 -0
- data/vendor/jasmine/Rakefile +178 -0
- data/vendor/jasmine/cruise_config.rb +21 -0
- data/vendor/jasmine/example/SpecRunner.html +27 -0
- data/vendor/jasmine/example/spec/PlayerSpec.js +58 -0
- data/vendor/jasmine/example/spec/SpecHelper.js +9 -0
- data/vendor/jasmine/example/src/Player.js +22 -0
- data/vendor/jasmine/example/src/Song.js +7 -0
- data/vendor/jasmine/images/fail-16.png +0 -0
- data/vendor/jasmine/images/fail.png +0 -0
- data/vendor/jasmine/images/go-16.png +0 -0
- data/vendor/jasmine/images/go.png +0 -0
- data/vendor/jasmine/images/pending-16.png +0 -0
- data/vendor/jasmine/images/pending.png +0 -0
- data/vendor/jasmine/images/question-bk.png +0 -0
- data/vendor/jasmine/images/questionbk-16.png +0 -0
- data/vendor/jasmine/images/spinner.gif +0 -0
- data/vendor/jasmine/lib/jasmine-html.js +182 -0
- data/vendor/jasmine/lib/jasmine.css +166 -0
- data/vendor/jasmine/lib/jasmine.js +2421 -0
- data/vendor/jasmine/lib/json2.js +478 -0
- data/vendor/jasmine/spec/runner.html +80 -0
- data/vendor/jasmine/spec/suites/BaseSpec.js +27 -0
- data/vendor/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
- data/vendor/jasmine/spec/suites/EnvSpec.js +158 -0
- data/vendor/jasmine/spec/suites/ExceptionsSpec.js +107 -0
- data/vendor/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
- data/vendor/jasmine/spec/suites/MatchersSpec.js +795 -0
- data/vendor/jasmine/spec/suites/MockClockSpec.js +38 -0
- data/vendor/jasmine/spec/suites/MultiReporterSpec.js +45 -0
- data/vendor/jasmine/spec/suites/NestedResultsSpec.js +54 -0
- data/vendor/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
- data/vendor/jasmine/spec/suites/QueueSpec.js +23 -0
- data/vendor/jasmine/spec/suites/ReporterSpec.js +56 -0
- data/vendor/jasmine/spec/suites/RunnerSpec.js +267 -0
- data/vendor/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
- data/vendor/jasmine/spec/suites/SpecSpec.js +124 -0
- data/vendor/jasmine/spec/suites/SpySpec.js +201 -0
- data/vendor/jasmine/spec/suites/SuiteSpec.js +120 -0
- data/vendor/jasmine/spec/suites/TrivialReporterSpec.js +235 -0
- data/vendor/jasmine/spec/suites/UtilSpec.js +40 -0
- data/vendor/jasmine/spec/suites/WaitsForBlockSpec.js +87 -0
- data/vendor/jasmine/src/Block.js +22 -0
- data/vendor/jasmine/src/Env.js +264 -0
- data/vendor/jasmine/src/JsApiReporter.js +102 -0
- data/vendor/jasmine/src/Matchers.js +354 -0
- data/vendor/jasmine/src/MultiReporter.js +35 -0
- data/vendor/jasmine/src/NestedResults.js +80 -0
- data/vendor/jasmine/src/PrettyPrinter.js +122 -0
- data/vendor/jasmine/src/Queue.js +99 -0
- data/vendor/jasmine/src/Reporter.js +31 -0
- data/vendor/jasmine/src/Runner.js +77 -0
- data/vendor/jasmine/src/Spec.js +242 -0
- data/vendor/jasmine/src/Suite.js +82 -0
- data/vendor/jasmine/src/WaitsBlock.js +13 -0
- data/vendor/jasmine/src/WaitsForBlock.js +52 -0
- data/vendor/jasmine/src/base.js +589 -0
- data/vendor/jasmine/src/html/TrivialReporter.js +182 -0
- data/vendor/jasmine/src/html/jasmine.css +166 -0
- data/vendor/jasmine/src/mock-timeout.js +183 -0
- data/vendor/jasmine/src/util.js +67 -0
- data/vendor/jasmine/src/version.json +5 -0
- metadata +102 -5
- data/test/unit/jsTestDriver.conf +0 -2
@@ -0,0 +1,182 @@
|
|
1
|
+
jasmine.TrivialReporter = function(doc) {
|
2
|
+
this.document = doc || document;
|
3
|
+
this.suiteDivs = {};
|
4
|
+
this.logRunningSpecs = false;
|
5
|
+
};
|
6
|
+
|
7
|
+
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
|
8
|
+
var el = document.createElement(type);
|
9
|
+
|
10
|
+
for (var i = 2; i < arguments.length; i++) {
|
11
|
+
var child = arguments[i];
|
12
|
+
|
13
|
+
if (typeof child === 'string') {
|
14
|
+
el.appendChild(document.createTextNode(child));
|
15
|
+
} else {
|
16
|
+
if (child) { el.appendChild(child); }
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
for (var attr in attrs) {
|
21
|
+
if (attr == "className") {
|
22
|
+
el[attr] = attrs[attr];
|
23
|
+
} else {
|
24
|
+
el.setAttribute(attr, attrs[attr]);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
return el;
|
29
|
+
};
|
30
|
+
|
31
|
+
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
|
32
|
+
var showPassed, showSkipped;
|
33
|
+
|
34
|
+
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
|
35
|
+
this.createDom('div', { className: 'banner' },
|
36
|
+
this.createDom('div', { className: 'logo' },
|
37
|
+
"Jasmine",
|
38
|
+
this.createDom('span', { className: 'version' }, runner.env.versionString())),
|
39
|
+
this.createDom('div', { className: 'options' },
|
40
|
+
"Show ",
|
41
|
+
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
|
42
|
+
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
|
43
|
+
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
|
44
|
+
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
|
45
|
+
)
|
46
|
+
),
|
47
|
+
|
48
|
+
this.runnerDiv = this.createDom('div', { className: 'runner running' },
|
49
|
+
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
|
50
|
+
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
|
51
|
+
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
|
52
|
+
);
|
53
|
+
|
54
|
+
this.document.body.appendChild(this.outerDiv);
|
55
|
+
|
56
|
+
var suites = runner.suites();
|
57
|
+
for (var i = 0; i < suites.length; i++) {
|
58
|
+
var suite = suites[i];
|
59
|
+
var suiteDiv = this.createDom('div', { className: 'suite' },
|
60
|
+
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
|
61
|
+
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
|
62
|
+
this.suiteDivs[suite.id] = suiteDiv;
|
63
|
+
var parentDiv = this.outerDiv;
|
64
|
+
if (suite.parentSuite) {
|
65
|
+
parentDiv = this.suiteDivs[suite.parentSuite.id];
|
66
|
+
}
|
67
|
+
parentDiv.appendChild(suiteDiv);
|
68
|
+
}
|
69
|
+
|
70
|
+
this.startedAt = new Date();
|
71
|
+
|
72
|
+
var self = this;
|
73
|
+
showPassed.onchange = function(evt) {
|
74
|
+
if (evt.target.checked) {
|
75
|
+
self.outerDiv.className += ' show-passed';
|
76
|
+
} else {
|
77
|
+
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
showSkipped.onchange = function(evt) {
|
82
|
+
if (evt.target.checked) {
|
83
|
+
self.outerDiv.className += ' show-skipped';
|
84
|
+
} else {
|
85
|
+
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
|
86
|
+
}
|
87
|
+
};
|
88
|
+
};
|
89
|
+
|
90
|
+
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
|
91
|
+
var results = runner.results();
|
92
|
+
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
|
93
|
+
this.runnerDiv.setAttribute("class", className);
|
94
|
+
//do it twice for IE
|
95
|
+
this.runnerDiv.setAttribute("className", className);
|
96
|
+
var specs = runner.specs();
|
97
|
+
var specCount = 0;
|
98
|
+
for (var i = 0; i < specs.length; i++) {
|
99
|
+
if (this.specFilter(specs[i])) {
|
100
|
+
specCount++;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
|
104
|
+
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
|
105
|
+
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
|
106
|
+
|
107
|
+
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
|
108
|
+
};
|
109
|
+
|
110
|
+
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
|
111
|
+
var results = suite.results();
|
112
|
+
var status = results.passed() ? 'passed' : 'failed';
|
113
|
+
if (results.totalCount == 0) { // todo: change this to check results.skipped
|
114
|
+
status = 'skipped';
|
115
|
+
}
|
116
|
+
this.suiteDivs[suite.id].className += " " + status;
|
117
|
+
};
|
118
|
+
|
119
|
+
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
|
120
|
+
if (this.logRunningSpecs) {
|
121
|
+
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
|
122
|
+
}
|
123
|
+
};
|
124
|
+
|
125
|
+
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
|
126
|
+
var results = spec.results();
|
127
|
+
var status = results.passed() ? 'passed' : 'failed';
|
128
|
+
if (results.skipped) {
|
129
|
+
status = 'skipped';
|
130
|
+
}
|
131
|
+
var specDiv = this.createDom('div', { className: 'spec ' + status },
|
132
|
+
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
|
133
|
+
this.createDom('a', {
|
134
|
+
className: 'description',
|
135
|
+
href: '?spec=' + encodeURIComponent(spec.getFullName()),
|
136
|
+
title: spec.getFullName()
|
137
|
+
}, spec.description));
|
138
|
+
|
139
|
+
|
140
|
+
var resultItems = results.getItems();
|
141
|
+
var messagesDiv = this.createDom('div', { className: 'messages' });
|
142
|
+
for (var i = 0; i < resultItems.length; i++) {
|
143
|
+
var result = resultItems[i];
|
144
|
+
|
145
|
+
if (result.type == 'log') {
|
146
|
+
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
|
147
|
+
} else if (result.type == 'expect' && result.passed && !result.passed()) {
|
148
|
+
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
|
149
|
+
|
150
|
+
if (result.trace.stack) {
|
151
|
+
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
if (messagesDiv.childNodes.length > 0) {
|
157
|
+
specDiv.appendChild(messagesDiv);
|
158
|
+
}
|
159
|
+
|
160
|
+
this.suiteDivs[spec.suite.id].appendChild(specDiv);
|
161
|
+
};
|
162
|
+
|
163
|
+
jasmine.TrivialReporter.prototype.log = function() {
|
164
|
+
var console = jasmine.getGlobal().console;
|
165
|
+
if (console && console.log) console.log.apply(console, arguments);
|
166
|
+
};
|
167
|
+
|
168
|
+
jasmine.TrivialReporter.prototype.getLocation = function() {
|
169
|
+
return this.document.location;
|
170
|
+
};
|
171
|
+
|
172
|
+
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
|
173
|
+
var paramMap = {};
|
174
|
+
var params = this.getLocation().search.substring(1).split('&');
|
175
|
+
for (var i = 0; i < params.length; i++) {
|
176
|
+
var p = params[i].split('=');
|
177
|
+
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
|
178
|
+
}
|
179
|
+
|
180
|
+
if (!paramMap["spec"]) return true;
|
181
|
+
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
|
182
|
+
};
|
@@ -0,0 +1,166 @@
|
|
1
|
+
body {
|
2
|
+
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
|
3
|
+
}
|
4
|
+
|
5
|
+
|
6
|
+
.jasmine_reporter a:visited, .jasmine_reporter a {
|
7
|
+
color: #303;
|
8
|
+
}
|
9
|
+
|
10
|
+
.jasmine_reporter a:hover, .jasmine_reporter a:active {
|
11
|
+
color: blue;
|
12
|
+
}
|
13
|
+
|
14
|
+
.run_spec {
|
15
|
+
float:right;
|
16
|
+
padding-right: 5px;
|
17
|
+
font-size: .8em;
|
18
|
+
text-decoration: none;
|
19
|
+
}
|
20
|
+
|
21
|
+
.jasmine_reporter {
|
22
|
+
margin: 0 5px;
|
23
|
+
}
|
24
|
+
|
25
|
+
.banner {
|
26
|
+
color: #303;
|
27
|
+
background-color: #fef;
|
28
|
+
padding: 5px;
|
29
|
+
}
|
30
|
+
|
31
|
+
.logo {
|
32
|
+
float: left;
|
33
|
+
font-size: 1.1em;
|
34
|
+
padding-left: 5px;
|
35
|
+
}
|
36
|
+
|
37
|
+
.logo .version {
|
38
|
+
font-size: .6em;
|
39
|
+
padding-left: 1em;
|
40
|
+
}
|
41
|
+
|
42
|
+
.runner.running {
|
43
|
+
background-color: yellow;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
.options {
|
48
|
+
text-align: right;
|
49
|
+
font-size: .8em;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
.suite {
|
56
|
+
border: 1px outset gray;
|
57
|
+
margin: 5px 0;
|
58
|
+
padding-left: 1em;
|
59
|
+
}
|
60
|
+
|
61
|
+
.suite .suite {
|
62
|
+
margin: 5px;
|
63
|
+
}
|
64
|
+
|
65
|
+
.suite.passed {
|
66
|
+
background-color: #dfd;
|
67
|
+
}
|
68
|
+
|
69
|
+
.suite.failed {
|
70
|
+
background-color: #fdd;
|
71
|
+
}
|
72
|
+
|
73
|
+
.spec {
|
74
|
+
margin: 5px;
|
75
|
+
padding-left: 1em;
|
76
|
+
clear: both;
|
77
|
+
}
|
78
|
+
|
79
|
+
.spec.failed, .spec.passed, .spec.skipped {
|
80
|
+
padding-bottom: 5px;
|
81
|
+
border: 1px solid gray;
|
82
|
+
}
|
83
|
+
|
84
|
+
.spec.failed {
|
85
|
+
background-color: #fbb;
|
86
|
+
border-color: red;
|
87
|
+
}
|
88
|
+
|
89
|
+
.spec.passed {
|
90
|
+
background-color: #bfb;
|
91
|
+
border-color: green;
|
92
|
+
}
|
93
|
+
|
94
|
+
.spec.skipped {
|
95
|
+
background-color: #bbb;
|
96
|
+
}
|
97
|
+
|
98
|
+
.messages {
|
99
|
+
border-left: 1px dashed gray;
|
100
|
+
padding-left: 1em;
|
101
|
+
padding-right: 1em;
|
102
|
+
}
|
103
|
+
|
104
|
+
.passed {
|
105
|
+
background-color: #cfc;
|
106
|
+
display: none;
|
107
|
+
}
|
108
|
+
|
109
|
+
.failed {
|
110
|
+
background-color: #fbb;
|
111
|
+
}
|
112
|
+
|
113
|
+
.skipped {
|
114
|
+
color: #777;
|
115
|
+
background-color: #eee;
|
116
|
+
display: none;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
/*.resultMessage {*/
|
121
|
+
/*white-space: pre;*/
|
122
|
+
/*}*/
|
123
|
+
|
124
|
+
.resultMessage span.result {
|
125
|
+
display: block;
|
126
|
+
line-height: 2em;
|
127
|
+
color: black;
|
128
|
+
}
|
129
|
+
|
130
|
+
.resultMessage .mismatch {
|
131
|
+
color: black;
|
132
|
+
}
|
133
|
+
|
134
|
+
.stackTrace {
|
135
|
+
white-space: pre;
|
136
|
+
font-size: .8em;
|
137
|
+
margin-left: 10px;
|
138
|
+
max-height: 5em;
|
139
|
+
overflow: auto;
|
140
|
+
border: 1px inset red;
|
141
|
+
padding: 1em;
|
142
|
+
background: #eef;
|
143
|
+
}
|
144
|
+
|
145
|
+
.finished-at {
|
146
|
+
padding-left: 1em;
|
147
|
+
font-size: .6em;
|
148
|
+
}
|
149
|
+
|
150
|
+
.show-passed .passed,
|
151
|
+
.show-skipped .skipped {
|
152
|
+
display: block;
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
#jasmine_content {
|
157
|
+
position:fixed;
|
158
|
+
right: 100%;
|
159
|
+
}
|
160
|
+
|
161
|
+
.runner {
|
162
|
+
border: 1px solid gray;
|
163
|
+
display: block;
|
164
|
+
margin: 5px 0;
|
165
|
+
padding: 2px 0 2px 10px;
|
166
|
+
}
|
@@ -0,0 +1,183 @@
|
|
1
|
+
// Mock setTimeout, clearTimeout
|
2
|
+
// Contributed by Pivotal Computer Systems, www.pivotalsf.com
|
3
|
+
|
4
|
+
jasmine.FakeTimer = function() {
|
5
|
+
this.reset();
|
6
|
+
|
7
|
+
var self = this;
|
8
|
+
self.setTimeout = function(funcToCall, millis) {
|
9
|
+
self.timeoutsMade++;
|
10
|
+
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false);
|
11
|
+
return self.timeoutsMade;
|
12
|
+
};
|
13
|
+
|
14
|
+
self.setInterval = function(funcToCall, millis) {
|
15
|
+
self.timeoutsMade++;
|
16
|
+
self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true);
|
17
|
+
return self.timeoutsMade;
|
18
|
+
};
|
19
|
+
|
20
|
+
self.clearTimeout = function(timeoutKey) {
|
21
|
+
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
|
22
|
+
};
|
23
|
+
|
24
|
+
self.clearInterval = function(timeoutKey) {
|
25
|
+
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
|
26
|
+
};
|
27
|
+
|
28
|
+
};
|
29
|
+
|
30
|
+
jasmine.FakeTimer.prototype.reset = function() {
|
31
|
+
this.timeoutsMade = 0;
|
32
|
+
this.scheduledFunctions = {};
|
33
|
+
this.nowMillis = 0;
|
34
|
+
};
|
35
|
+
|
36
|
+
jasmine.FakeTimer.prototype.tick = function(millis) {
|
37
|
+
var oldMillis = this.nowMillis;
|
38
|
+
var newMillis = oldMillis + millis;
|
39
|
+
this.runFunctionsWithinRange(oldMillis, newMillis);
|
40
|
+
this.nowMillis = newMillis;
|
41
|
+
};
|
42
|
+
|
43
|
+
jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) {
|
44
|
+
var scheduledFunc;
|
45
|
+
var funcsToRun = [];
|
46
|
+
for (var timeoutKey in this.scheduledFunctions) {
|
47
|
+
scheduledFunc = this.scheduledFunctions[timeoutKey];
|
48
|
+
if (scheduledFunc != jasmine.undefined &&
|
49
|
+
scheduledFunc.runAtMillis >= oldMillis &&
|
50
|
+
scheduledFunc.runAtMillis <= nowMillis) {
|
51
|
+
funcsToRun.push(scheduledFunc);
|
52
|
+
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
if (funcsToRun.length > 0) {
|
57
|
+
funcsToRun.sort(function(a, b) {
|
58
|
+
return a.runAtMillis - b.runAtMillis;
|
59
|
+
});
|
60
|
+
for (var i = 0; i < funcsToRun.length; ++i) {
|
61
|
+
try {
|
62
|
+
var funcToRun = funcsToRun[i];
|
63
|
+
this.nowMillis = funcToRun.runAtMillis;
|
64
|
+
funcToRun.funcToCall();
|
65
|
+
if (funcToRun.recurring) {
|
66
|
+
this.scheduleFunction(funcToRun.timeoutKey,
|
67
|
+
funcToRun.funcToCall,
|
68
|
+
funcToRun.millis,
|
69
|
+
true);
|
70
|
+
}
|
71
|
+
} catch(e) {
|
72
|
+
}
|
73
|
+
}
|
74
|
+
this.runFunctionsWithinRange(oldMillis, nowMillis);
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) {
|
79
|
+
this.scheduledFunctions[timeoutKey] = {
|
80
|
+
runAtMillis: this.nowMillis + millis,
|
81
|
+
funcToCall: funcToCall,
|
82
|
+
recurring: recurring,
|
83
|
+
timeoutKey: timeoutKey,
|
84
|
+
millis: millis
|
85
|
+
};
|
86
|
+
};
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @namespace
|
90
|
+
*/
|
91
|
+
jasmine.Clock = {
|
92
|
+
defaultFakeTimer: new jasmine.FakeTimer(),
|
93
|
+
|
94
|
+
reset: function() {
|
95
|
+
jasmine.Clock.assertInstalled();
|
96
|
+
jasmine.Clock.defaultFakeTimer.reset();
|
97
|
+
},
|
98
|
+
|
99
|
+
tick: function(millis) {
|
100
|
+
jasmine.Clock.assertInstalled();
|
101
|
+
jasmine.Clock.defaultFakeTimer.tick(millis);
|
102
|
+
},
|
103
|
+
|
104
|
+
runFunctionsWithinRange: function(oldMillis, nowMillis) {
|
105
|
+
jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis);
|
106
|
+
},
|
107
|
+
|
108
|
+
scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) {
|
109
|
+
jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring);
|
110
|
+
},
|
111
|
+
|
112
|
+
useMock: function() {
|
113
|
+
if (!jasmine.Clock.isInstalled()) {
|
114
|
+
var spec = jasmine.getEnv().currentSpec;
|
115
|
+
spec.after(jasmine.Clock.uninstallMock);
|
116
|
+
|
117
|
+
jasmine.Clock.installMock();
|
118
|
+
}
|
119
|
+
},
|
120
|
+
|
121
|
+
installMock: function() {
|
122
|
+
jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer;
|
123
|
+
},
|
124
|
+
|
125
|
+
uninstallMock: function() {
|
126
|
+
jasmine.Clock.assertInstalled();
|
127
|
+
jasmine.Clock.installed = jasmine.Clock.real;
|
128
|
+
},
|
129
|
+
|
130
|
+
real: {
|
131
|
+
setTimeout: jasmine.getGlobal().setTimeout,
|
132
|
+
clearTimeout: jasmine.getGlobal().clearTimeout,
|
133
|
+
setInterval: jasmine.getGlobal().setInterval,
|
134
|
+
clearInterval: jasmine.getGlobal().clearInterval
|
135
|
+
},
|
136
|
+
|
137
|
+
assertInstalled: function() {
|
138
|
+
if (!jasmine.Clock.isInstalled()) {
|
139
|
+
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
|
140
|
+
}
|
141
|
+
},
|
142
|
+
|
143
|
+
isInstalled: function() {
|
144
|
+
return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer;
|
145
|
+
},
|
146
|
+
|
147
|
+
installed: null
|
148
|
+
};
|
149
|
+
jasmine.Clock.installed = jasmine.Clock.real;
|
150
|
+
|
151
|
+
//else for IE support
|
152
|
+
jasmine.getGlobal().setTimeout = function(funcToCall, millis) {
|
153
|
+
if (jasmine.Clock.installed.setTimeout.apply) {
|
154
|
+
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
|
155
|
+
} else {
|
156
|
+
return jasmine.Clock.installed.setTimeout(funcToCall, millis);
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
jasmine.getGlobal().setInterval = function(funcToCall, millis) {
|
161
|
+
if (jasmine.Clock.installed.setInterval.apply) {
|
162
|
+
return jasmine.Clock.installed.setInterval.apply(this, arguments);
|
163
|
+
} else {
|
164
|
+
return jasmine.Clock.installed.setInterval(funcToCall, millis);
|
165
|
+
}
|
166
|
+
};
|
167
|
+
|
168
|
+
jasmine.getGlobal().clearTimeout = function(timeoutKey) {
|
169
|
+
if (jasmine.Clock.installed.clearTimeout.apply) {
|
170
|
+
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
|
171
|
+
} else {
|
172
|
+
return jasmine.Clock.installed.clearTimeout(timeoutKey);
|
173
|
+
}
|
174
|
+
};
|
175
|
+
|
176
|
+
jasmine.getGlobal().clearInterval = function(timeoutKey) {
|
177
|
+
if (jasmine.Clock.installed.clearTimeout.apply) {
|
178
|
+
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
|
179
|
+
} else {
|
180
|
+
return jasmine.Clock.installed.clearInterval(timeoutKey);
|
181
|
+
}
|
182
|
+
};
|
183
|
+
|