guard-jasmine 1.19.2 → 2.0.0beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -234
  3. data/lib/generators/guard_jasmine/install_generator.rb +17 -0
  4. data/lib/generators/guard_jasmine/templates/Guardfile +9 -0
  5. data/lib/guard/jasmine.rb +18 -15
  6. data/lib/guard/jasmine/cli.rb +5 -5
  7. data/lib/guard/jasmine/formatter.rb +10 -0
  8. data/lib/guard/jasmine/inspector.rb +1 -2
  9. data/lib/guard/jasmine/phantomjs/guard-jasmine.js +54 -180
  10. data/lib/guard/jasmine/phantomjs/guard-reporter.js +187 -0
  11. data/lib/guard/jasmine/phantomjs/src/guard-jasmine.coffee +101 -0
  12. data/lib/guard/jasmine/phantomjs/src/guard-reporter.coffee +109 -0
  13. data/lib/guard/jasmine/phantomjs/test/guard-reporter_spec.coffee +41 -0
  14. data/lib/guard/jasmine/runner.rb +178 -268
  15. data/lib/guard/jasmine/server.rb +17 -3
  16. data/lib/guard/jasmine/util.rb +1 -7
  17. data/lib/guard/jasmine/version.rb +1 -1
  18. metadata +135 -26
  19. data/lib/guard/jasmine/phantomjs/guard-jasmine.coffee +0 -193
  20. data/lib/guard/jasmine/phantomjs/lib/console.js +0 -188
  21. data/lib/guard/jasmine/phantomjs/lib/junit_reporter.js +0 -224
  22. data/lib/guard/jasmine/phantomjs/lib/reporter.js +0 -144
  23. data/lib/guard/jasmine/phantomjs/lib/result.js +0 -155
  24. data/lib/guard/jasmine/phantomjs/src/console.coffee +0 -149
  25. data/lib/guard/jasmine/phantomjs/src/reporter.coffee +0 -139
  26. data/lib/guard/jasmine/phantomjs/src/result.coffee +0 -95
  27. data/lib/guard/jasmine/phantomjs/test/console_spec.coffee +0 -125
  28. data/lib/guard/jasmine/phantomjs/test/reporter_spec.coffee +0 -0
  29. data/lib/guard/jasmine/phantomjs/test/result_spec.coffee +0 -311
@@ -217,12 +217,10 @@ module Guard
217
217
  end
218
218
 
219
219
  if CLI.runner_available?(runner_options)
220
- result = ::Guard::Jasmine::Runner.run(paths, runner_options)
220
+ result = ::Guard::Jasmine::Runner.new(runner_options).run(paths)
221
221
  ::Guard::Jasmine::Server.stop
222
-
223
- Process.exit result.first ? 0 : 1
222
+ Process.exit result.empty? ? 0 : 1
224
223
  else
225
- ::Guard::Jasmine::Server.stop
226
224
  Process.exit 2
227
225
  end
228
226
 
@@ -231,8 +229,10 @@ module Guard
231
229
  end
232
230
 
233
231
  rescue => e
234
- ::Guard::UI.error e.message
232
+ ::Guard::UI.error "Something went wrong: #{e.message}"
235
233
  Process.exit 2
234
+ ensure
235
+ ::Guard::Jasmine::Server.stop
236
236
  end
237
237
 
238
238
  desc 'version', 'Show the Guard::Jasmine version'
@@ -48,6 +48,16 @@ module Guard
48
48
  ::Guard::UI.info(color(message, ';32'), options)
49
49
  end
50
50
 
51
+ # Print a yellow pending message to the console.
52
+ #
53
+ # @param [String] message the message to print
54
+ # @param [Hash] options the output options
55
+ # @option options [Boolean] :reset reset the UI
56
+ #
57
+ def spec_pending(message, options = { })
58
+ ::Guard::UI.info(color(message, ';33'), options)
59
+ end
60
+
51
61
  # Print a red spec failed message to the console.
52
62
  #
53
63
  # @param [String] message the message to print
@@ -20,7 +20,6 @@ module Guard
20
20
  def clean(paths, options)
21
21
  paths.uniq!
22
22
  paths.compact!
23
-
24
23
  if paths.include?(options[:spec_dir])
25
24
  paths = [options[:spec_dir]]
26
25
  else
@@ -38,7 +37,7 @@ module Guard
38
37
  # @return [Boolean] when the file valid
39
38
  #
40
39
  def jasmine_spec?(path)
41
- path =~ /_spec\.(js|coffee|js\.coffee)$/ && File.exists?(path)
40
+ path =~ /(?:_s|S)pec\.(js|coffee|js\.coffee)$/ && File.exists?(path)
42
41
  end
43
42
 
44
43
  end
@@ -1,246 +1,120 @@
1
1
  (function() {
2
- var currentSpecId, errors, fs, getXmlResults, jasmineAvailable, jasmineMissing, jasmineReady, logs, options, overloadPageEvaluate, page, replaceFunctionPlaceholders, resultsKey, setupWriteFileFunction, specsDone, specsReady, specsTimedout, waitFor;
3
-
4
- phantom.injectJs('lib/result.js');
2
+ var exitSuccessfully, jasmineAvailable, options, page, reportError, reporterMissing, reporterReady, specsDone, specsTimedout, waitFor;
5
3
 
6
4
  options = {
7
5
  url: phantom.args[0] || 'http://127.0.0.1:3000/jasmine',
8
- timeout: parseInt(phantom.args[1] || 10000),
9
- specdoc: phantom.args[2] || 'failure',
10
- focus: /true/i.test(phantom.args[3]),
11
- console: phantom.args[4] || 'failure',
12
- errors: phantom.args[5] || 'failure',
13
- junit: /true/i.test(phantom.args[6]),
14
- junit_consolidate: /true/i.test(phantom.args[7]),
15
- junit_save_path: phantom.args[8] || ''
6
+ timeout: parseInt(phantom.args[1] || 10000)
16
7
  };
17
8
 
18
9
  page = require('webpage').create();
19
10
 
20
- currentSpecId = -1;
21
-
22
- logs = {};
23
-
24
- errors = {};
25
-
26
- resultsKey = "__jr" + Math.ceil(Math.random() * 1000000);
27
-
28
- fs = require("fs");
29
-
30
- page.onError = function(msg, trace) {
31
- if (currentSpecId) {
32
- errors[currentSpecId] || (errors[currentSpecId] = []);
33
- return errors[currentSpecId].push({
34
- msg: msg,
35
- trace: trace
36
- });
37
- }
38
- };
39
-
40
- page.onConsoleMessage = function(msg, line, source) {
41
- var result;
42
-
43
- if (/^RUNNER_END$/.test(msg)) {
44
- result = page.evaluate(function() {
45
- return window.reporter.runnerResult;
46
- });
47
- console.log(JSON.stringify(new Result(result, logs, errors, options).process()));
48
- return page.evaluate(function() {
49
- return window.resultReceived = true;
50
- });
51
- } else if (/^SPEC_START: (\d+)$/.test(msg)) {
52
- return currentSpecId = Number(RegExp.$1);
53
- } else {
54
- logs[currentSpecId] || (logs[currentSpecId] = []);
55
- return logs[currentSpecId].push(msg);
56
- }
11
+ page.onError = function(message, trace) {
12
+ return reportError("Javascript error encountered on Jasmine test page: " + message, trace);
57
13
  };
58
14
 
59
15
  page.onInitialized = function() {
60
- var setupReporters;
61
-
62
- overloadPageEvaluate(page);
63
- setupWriteFileFunction(page, resultsKey, fs.separator);
64
- page.injectJs('lib/console.js');
65
- page.injectJs('lib/reporter.js');
66
- page.injectJs('lib/junit_reporter.js');
67
- setupReporters = function() {
16
+ page.injectJs('guard-reporter.js');
17
+ return page.evaluate(function() {
68
18
  return window.onload = function() {
69
- window.onload = null;
70
- window.resultReceived = false;
71
- window.reporter = new ConsoleReporter();
19
+ window.reporter = new GuardReporter();
72
20
  if (window.jasmine) {
73
- jasmine.getEnv().addReporter(new JUnitXmlReporter("%save_path%", "%consolidate%"));
74
- return jasmine.getEnv().addReporter(window.reporter);
21
+ return window.jasmine.getEnv().addReporter(window.reporter);
75
22
  }
76
23
  };
77
- };
78
- return page.evaluate(setupReporters, {
79
- save_path: options.junit_save_path,
80
- consolidate: options.junit_consolidate
81
- });
82
- };
83
-
84
- getXmlResults = function(page, key) {
85
- var getWindowObj;
86
-
87
- getWindowObj = function() {
88
- return window["%resultsObj%"] || {};
89
- };
90
- return page.evaluate(getWindowObj, {
91
- resultsObj: key
92
- });
93
- };
94
-
95
- replaceFunctionPlaceholders = function(fn, replacements) {
96
- var match, p;
97
-
98
- if (replacements && typeof replacements === 'object') {
99
- fn = fn.toString();
100
- for (p in replacements) {
101
- if (replacements.hasOwnProperty(p)) {
102
- match = new RegExp("%" + p + "%", "g");
103
- while (true) {
104
- fn = fn.replace(match, replacements[p]);
105
- if (fn.indexOf(match) === -1) {
106
- break;
107
- }
108
- }
109
- }
110
- }
111
- }
112
- return fn;
113
- };
114
-
115
- overloadPageEvaluate = function(page) {
116
- page._evaluate = page.evaluate;
117
- page.evaluate = function(fn, replacements) {
118
- return page._evaluate(replaceFunctionPlaceholders(fn, replacements));
119
- };
120
- return page;
121
- };
122
-
123
- setupWriteFileFunction = function(page, key, path_separator) {
124
- var saveData;
125
-
126
- saveData = function() {
127
- window["%resultsObj%"] = {};
128
- window.fs_path_separator = "%fs_path_separator%";
129
- return window.__phantom_writeFile = function(filename, text) {
130
- return window["%resultsObj%"][filename] = text;
131
- };
132
- };
133
- return page.evaluate(saveData, {
134
- resultsObj: key,
135
- fs_path_separator: path_separator
136
24
  });
137
25
  };
138
26
 
139
- page.open(options.url, function(status) {
140
- page.onLoadFinished = function() {};
27
+ page.onLoadFinished = function(status) {
141
28
  if (status !== 'success') {
142
- console.log(JSON.stringify({
143
- error: "Unable to access Jasmine specs at " + options.url
144
- }));
145
- return phantom.exit();
29
+ return reportError("Unable to access Jasmine specs at " + options.url + ", page returned status: " + status);
146
30
  } else {
147
- return waitFor(jasmineReady, jasmineAvailable, options.timeout, jasmineMissing);
31
+ return waitFor(reporterReady, jasmineAvailable, options.timeout, reporterMissing);
148
32
  }
149
- });
33
+ };
34
+
35
+ page.open(options.url);
150
36
 
151
- jasmineReady = function() {
37
+ reporterReady = function() {
152
38
  return page.evaluate(function() {
153
- return window.jasmine;
39
+ return window.jasmine && window.reporter;
154
40
  });
155
41
  };
156
42
 
157
43
  jasmineAvailable = function() {
158
- return waitFor(specsReady, specsDone, options.timeout, specsTimedout);
44
+ return waitFor(specsDone, exitSuccessfully, options.timeout, specsTimedout);
159
45
  };
160
46
 
161
- jasmineMissing = function() {
162
- var error, text;
163
-
47
+ reporterMissing = function() {
48
+ var text;
164
49
  text = page.evaluate(function() {
165
50
  var _ref;
166
-
167
51
  return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
168
52
  });
169
- if (text) {
170
- error = "The Jasmine reporter is not available!\n\n" + text;
171
- return console.log(JSON.stringify({
172
- error: error
173
- }));
174
- } else {
175
- return console.log(JSON.stringify({
176
- error: 'The Jasmine reporter is not available!'
177
- }));
178
- }
53
+ return reportError("The reporter is not available!\nPerhaps the url ( " + options.url + " ) is incorrect?\n\n" + text);
179
54
  };
180
55
 
181
- specsReady = function() {
182
- return page.evaluate(function() {
183
- return window.resultReceived;
56
+ specsDone = function() {
57
+ var result;
58
+ return result = page.evaluate(function() {
59
+ return window.reporter.resultComplete;
184
60
  });
185
61
  };
186
62
 
187
- specsTimedout = function() {
188
- var error, text;
63
+ exitSuccessfully = function() {
64
+ var results;
65
+ results = page.evaluate(function() {
66
+ return window.reporter.results();
67
+ });
68
+ console.log(JSON.stringify(results));
69
+ return phantom.exit();
70
+ };
189
71
 
72
+ specsTimedout = function() {
73
+ var text;
190
74
  text = page.evaluate(function() {
191
75
  var _ref;
192
-
193
76
  return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
194
77
  });
195
- if (text) {
196
- error = "Timeout waiting for the Jasmine test results!\n\n" + text;
197
- return console.log(JSON.stringify({
198
- error: error
199
- }));
200
- } else {
201
- return console.log(JSON.stringify({
202
- error: 'Timeout for the Jasmine test results!'
203
- }));
204
- }
205
- };
206
-
207
- specsDone = function() {
208
- var filename, output, xml_results;
209
-
210
- if (options.junit === true) {
211
- xml_results = getXmlResults(page, resultsKey);
212
- for (filename in xml_results) {
213
- if (xml_results.hasOwnProperty(filename) && (output = xml_results[filename]) && typeof output === 'string') {
214
- fs.write(filename, output, 'w');
215
- }
216
- }
217
- }
218
- return phantom.exit();
78
+ return reportError("Timeout waiting for the Jasmine test results!\n\n" + text);
219
79
  };
220
80
 
221
81
  waitFor = function(test, ready, timeout, timeoutFunction) {
222
82
  var condition, interval, start, wait;
223
-
224
83
  if (timeout == null) {
225
84
  timeout = 10000;
226
85
  }
227
- start = Date.now();
228
86
  condition = false;
229
87
  interval = void 0;
88
+ start = Date.now(0);
230
89
  wait = function() {
231
- if ((Date.now() - start < timeout) && !condition) {
90
+ if (!condition && (Date.now() - start < timeout)) {
232
91
  return condition = test();
233
92
  } else {
234
93
  clearInterval(interval);
235
94
  if (condition) {
236
95
  return ready();
237
96
  } else {
238
- timeoutFunction();
239
- return phantom.exit(1);
97
+ return timeoutFunction();
240
98
  }
241
99
  }
242
100
  };
243
101
  return interval = setInterval(wait, 250);
244
102
  };
245
103
 
104
+ reportError = function(msg, trace) {
105
+ var err;
106
+ if (trace == null) {
107
+ trace = [];
108
+ }
109
+ if (0 === trace.length) {
110
+ err = new Error();
111
+ trace = err.stack;
112
+ }
113
+ console.log(JSON.stringify({
114
+ error: msg,
115
+ trace: trace
116
+ }));
117
+ return phantom.exit(1);
118
+ };
119
+
246
120
  }).call(this);
@@ -0,0 +1,187 @@
1
+ (function() {
2
+ var ConsoleCapture, GuardReporter, extendObject;
3
+
4
+ extendObject = function(a, b) {
5
+ var key, value;
6
+ for (key in b) {
7
+ value = b[key];
8
+ if (b.hasOwnProperty(key)) {
9
+ a[key] = value;
10
+ }
11
+ }
12
+ return a;
13
+ };
14
+
15
+ ConsoleCapture = (function() {
16
+ var level, _i, _len, _ref;
17
+
18
+ ConsoleCapture.DOT_REPORTER_MATCH = /\[\d+m[F.]..0m/;
19
+
20
+ ConsoleCapture.levels = ['log', 'info', 'warn', 'error', 'debug'];
21
+
22
+ ConsoleCapture.original = console;
23
+
24
+ ConsoleCapture.original_levels = {};
25
+
26
+ _ref = ConsoleCapture.levels;
27
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
28
+ level = _ref[_i];
29
+ ConsoleCapture.original_levels[level] = console[level];
30
+ }
31
+
32
+ function ConsoleCapture() {
33
+ var _j, _len1, _ref1;
34
+ this.original = {};
35
+ this.captured = [];
36
+ _ref1 = ConsoleCapture.levels;
37
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
38
+ level = _ref1[_j];
39
+ this._reassign_level(level);
40
+ }
41
+ }
42
+
43
+ ConsoleCapture.prototype.revert = function() {
44
+ var _j, _len1, _ref1, _results;
45
+ _ref1 = ConsoleCapture.levels;
46
+ _results = [];
47
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
48
+ level = _ref1[_j];
49
+ _results.push(ConsoleCapture.original[level] = ConsoleCapture.original_levels[level]);
50
+ }
51
+ return _results;
52
+ };
53
+
54
+ ConsoleCapture.prototype._reassign_level = function(level) {
55
+ var my;
56
+ my = this;
57
+ return console[level] = function() {
58
+ var args;
59
+ args = Array.prototype.slice.call(arguments, 0);
60
+ if (args[0] && args[0].toString && args[0].toString().match(ConsoleCapture.DOT_REPORTER_MATCH)) {
61
+ return;
62
+ }
63
+ my.captured.push([level].concat(args));
64
+ return ConsoleCapture.original_levels[level].apply(ConsoleCapture.original, arguments);
65
+ };
66
+ };
67
+
68
+ return ConsoleCapture;
69
+
70
+ })();
71
+
72
+ GuardReporter = (function() {
73
+ function GuardReporter() {}
74
+
75
+ GuardReporter.STACK_MATCHER = new RegExp("__spec__\/(.*):([0-9]+)", "g");
76
+
77
+ GuardReporter.prototype.jasmineStarted = function() {
78
+ this.console = new ConsoleCapture();
79
+ this.startedAt = Date.now();
80
+ this.currentSuite = {
81
+ suites: []
82
+ };
83
+ return this.stack = [this.currentSuite];
84
+ };
85
+
86
+ GuardReporter.prototype.suiteStarted = function(suite) {
87
+ suite = extendObject({
88
+ specs: [],
89
+ suites: []
90
+ }, suite);
91
+ this.currentSuite.suites.push(suite);
92
+ this.currentSuite = suite;
93
+ return this.stack.push(suite);
94
+ };
95
+
96
+ GuardReporter.prototype.suiteDone = function(Suite) {
97
+ this.stack.pop();
98
+ return this.currentSuite = this.stack[this.stack.length - 1];
99
+ };
100
+
101
+ GuardReporter.prototype.jasmineDone = function() {
102
+ return this.resultComplete = true;
103
+ };
104
+
105
+ GuardReporter.prototype.specDone = function(spec) {
106
+ var error, failure, match, _i, _len, _ref;
107
+ this.resultReceived = true;
108
+ spec = extendObject({
109
+ logs: this.console.captured,
110
+ errors: []
111
+ }, spec);
112
+ _ref = spec.failedExpectations;
113
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
114
+ failure = _ref[_i];
115
+ error = extendObject({
116
+ trace: []
117
+ }, failure);
118
+ while (match = GuardReporter.STACK_MATCHER.exec(failure.stack)) {
119
+ error.trace.push({
120
+ file: match[1],
121
+ line: parseInt(match[2])
122
+ });
123
+ }
124
+ delete error.stack;
125
+ spec.errors.push(error);
126
+ }
127
+ delete spec.failedExpectations;
128
+ this.currentSuite.specs.push(spec);
129
+ this.resetConsoleLog();
130
+ return spec;
131
+ };
132
+
133
+ GuardReporter.prototype.resetConsoleLog = function() {
134
+ this.console.revert();
135
+ return this.console = new ConsoleCapture;
136
+ };
137
+
138
+ GuardReporter.prototype.eachSuite = function(suite) {
139
+ var suites, _i, _len, _ref;
140
+ suites = [].concat(suite.suites);
141
+ _ref = suite.suites;
142
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
143
+ suite = _ref[_i];
144
+ suites = suites.concat(this.eachSuite(suite));
145
+ }
146
+ return suites;
147
+ };
148
+
149
+ GuardReporter.prototype.results = function() {
150
+ var spec, stats, suite, _i, _j, _len, _len1, _ref, _ref1;
151
+ stats = {
152
+ time: (Date.now() - this.startedAt) / 1000,
153
+ specs: 0,
154
+ failed: 0,
155
+ pending: 0,
156
+ disabled: 0
157
+ };
158
+ _ref = this.eachSuite(this.stack[0]);
159
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
160
+ suite = _ref[_i];
161
+ stats.specs += suite.specs.length;
162
+ _ref1 = suite.specs;
163
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
164
+ spec = _ref1[_j];
165
+ if (void 0 !== stats[spec.status]) {
166
+ stats[spec.status] += 1;
167
+ }
168
+ }
169
+ }
170
+ return {
171
+ jasmine_version: typeof jasmine !== "undefined" && jasmine !== null ? jasmine.version : void 0,
172
+ stats: stats,
173
+ suites: this.stack[0].suites
174
+ };
175
+ };
176
+
177
+ return GuardReporter;
178
+
179
+ })();
180
+
181
+ if (typeof module !== 'undefined' && module.exports) {
182
+ module.exports = GuardReporter;
183
+ } else {
184
+ window.GuardReporter = GuardReporter;
185
+ }
186
+
187
+ }).call(this);