guard-jasmine 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53193032b63dd7b6271957ed84d4f210e480c555
4
- data.tar.gz: 397ee318b045ae2c7afb655bf16024a4e3e05d34
3
+ metadata.gz: 60fc1ca74efcf8df719d1d9943044e0ad59d51a3
4
+ data.tar.gz: 24ef532486b920209d34741b4c7bce58b5ef8c53
5
5
  SHA512:
6
- metadata.gz: f6eaa3b8cd54eaa1630ca2725faa439210b717e5716db767f99b0d94c34bb53672e73776404210f6f8d54d73a7d07f38d0491f8f42d8bae3f25a35e193950a6f
7
- data.tar.gz: a35aeebd262c0c02d6cbd588bb2d27222986a0e6133ec0cf5907a19c7ad87276e7a1ec606a7de8171e902266f81ef4ae09ed258861fc048522dd0a53f22cc317
6
+ metadata.gz: d62f8ea0aed0bbd2e856c1c7a9cf50fb43b9d8f9a92ca7a936a74136b7011c72b185955ccda13e07f9eadc4939c6eef02cda1278d71b6128dafa916116f725d5
7
+ data.tar.gz: b5466cd09a10167866e6fa4c9ee439cb7afee8c420799b7747e182003b64faab1c910af3ba8e8165bfe06cf4213364ce64b616794088c3374ed9d5352c8fa059
data/README.md CHANGED
@@ -643,9 +643,9 @@ Options:
643
643
  # Default: spec/javascripts
644
644
  -u, [--url=URL] # The url of the Jasmine test runner_options
645
645
  # Default: nil
646
- -t, [--timeout=N] # The maximum time in milliseconds to wait for the spec
646
+ -t, [--timeout=N] # The maximum time in seconds to wait for the spec
647
647
  # runner to finish
648
- # Default: 10000
648
+ # Default: 10
649
649
  [--console=CONSOLE] # Whether to show console.log statements in the spec runner,
650
650
  # either `always`, `never` or `failure`
651
651
  # Default: failure
data/lib/guard/jasmine.rb CHANGED
@@ -25,6 +25,7 @@ module Guard
25
25
  server: :auto,
26
26
  server_env: ENV['RAILS_ENV'] || 'development',
27
27
  server_timeout: 60,
28
+ server_mount: '/jasmine',
28
29
  port: nil,
29
30
  rackup_config: nil,
30
31
  jasmine_url: nil,
@@ -91,7 +92,7 @@ module Guard
91
92
  options[:port] ||= Jasmine.find_free_server_port
92
93
  options[:server] ||= :auto
93
94
  options[:server] = ::Guard::Jasmine::Server.detect_server(options[:spec_dir]) if options[:server] == :auto
94
- options[:jasmine_url] = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : '/jasmine' }" unless options[:jasmine_url]
95
+ options[:jasmine_url] = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : options[:server_mount] }" unless options[:jasmine_url]
95
96
  options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc]
96
97
  options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin]
97
98
 
@@ -170,6 +170,8 @@ module Guard
170
170
  runner_options[:hide_success] = true
171
171
  runner_options[:max_error_notify] = 0
172
172
 
173
+ ::Guard::UI.options = ::Guard::UI.options.merge({ :template => ':message' })
174
+
173
175
  paths = [runner_options[:spec_dir]] if paths.empty?
174
176
 
175
177
  if CLI.phantomjs_bin_valid?(runner_options[:phantomjs_bin])
@@ -5,7 +5,7 @@ phantom.injectJs 'lib/result.js'
5
5
  # Set default values
6
6
  options =
7
7
  url: phantom.args[0] || 'http://127.0.0.1:3000/jasmine'
8
- timeout: parseInt(phantom.args[1] || 5000)
8
+ timeout: parseInt(phantom.args[1] || 10000)
9
9
  specdoc: phantom.args[2] || 'failure'
10
10
  focus: /true/i.test phantom.args[3]
11
11
  console: phantom.args[4] || 'failure'
@@ -53,75 +53,92 @@ page.onInitialized = ->
53
53
  page.evaluate ->
54
54
  # Attach the console reporter when the document is ready.
55
55
  window.onload = ->
56
+ window.onload = null
56
57
  window.resultReceived = false
57
58
  window.reporter = new ConsoleReporter()
58
- jasmine.getEnv().addReporter(window.reporter)
59
+ if window.jasmine
60
+ jasmine.getEnv().addReporter(window.reporter)
59
61
 
60
62
  # Open web page and run the Jasmine test runner
61
63
  #
62
64
  page.open options.url, (status) ->
63
65
  # Avoid that a failed iframe load breaks the runner, see https://github.com/netzpirat/guard-jasmine/pull/19
64
66
  page.onLoadFinished = ->
65
-
66
67
  if status isnt 'success'
67
68
  console.log JSON.stringify({ error: "Unable to access Jasmine specs at #{ options.url }" })
68
69
  phantom.exit()
69
70
  else
70
- runnerAvailable = page.evaluate -> window.jasmine
71
+ waitFor jasmineReady, jasmineAvailable, options.timeout, jasmineMissing
71
72
 
72
- if runnerAvailable
73
- done = -> phantom.exit()
74
- waitFor specsReady, done, options.timeout
75
- else
76
- text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
77
73
 
78
- if text
79
- error = """
80
- The Jasmine reporter is not available!
74
+ # Test if the jasmine has been loaded
75
+ #
76
+ jasmineReady = ->
77
+ page.evaluate -> window.jasmine
81
78
 
82
- #{ text }
83
- """
84
- console.log JSON.stringify({ error: error })
85
- else
86
- console.log JSON.stringify({ error: 'The Jasmine reporter is not available!' })
79
+ # Start specs after they are have been loaded
80
+ #
81
+ jasmineAvailable = ->
82
+ waitFor specsReady, specsDone, options.timeout, specsTimedout
87
83
 
88
- phantom.exit(1)
84
+ # Error message for when jasmine never loaded asynchronously
85
+ #
86
+ jasmineMissing = ->
87
+ text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
88
+
89
+ if text
90
+ error = """
91
+ The Jasmine reporter is not available!
92
+
93
+ #{ text }
94
+ """
95
+ console.log JSON.stringify({ error: error })
96
+ else
97
+ console.log JSON.stringify({ error: 'The Jasmine reporter is not available!' })
89
98
 
90
99
  # Test if the specs have finished.
91
100
  #
92
101
  specsReady = ->
93
102
  page.evaluate -> window.resultReceived
94
103
 
104
+ # Error message for when specs time out
105
+ #
106
+ specsTimedout = ->
107
+ text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
108
+ if text
109
+ error = """
110
+ Timeout waiting for the Jasmine test results!
111
+
112
+ #{ text }
113
+ """
114
+ console.log JSON.stringify({ error: error })
115
+ else
116
+ console.log JSON.stringify({ error: 'Timeout for the Jasmine test results!' })
117
+
118
+ specsDone = ->
119
+ phantom.exit()
120
+
95
121
  # Wait until the test condition is true or a timeout occurs.
96
122
  #
97
123
  # @param [Function] test the test that returns true if condition is met
98
124
  # @param [Function] ready the action when the condition is fulfilled
99
125
  # @param [Number] timeout the max amount of time to wait in milliseconds
100
126
  #
101
- waitFor = (test, ready, timeout = 5000) ->
102
- start = new Date().getTime()
103
- condition = false
127
+ waitFor = (test, ready, timeout = 10000, timeoutFunction) ->
128
+ start = Date.now()
129
+ condition = false
130
+ interval = undefined
131
+
132
+ wait = ->
133
+ if (Date.now() - start < timeout) and not condition
134
+ condition = test()
135
+ else
136
+ clearInterval interval
104
137
 
105
- wait = ->
106
- if (new Date().getTime() - start < timeout) and not condition
107
- condition = test()
138
+ if condition
139
+ ready()
108
140
  else
109
- if not condition
110
- text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
111
-
112
- if text
113
- error = """
114
- Timeout waiting for the Jasmine test results!
115
-
116
- #{ text }
117
- """
118
- console.log JSON.stringify({ error: error })
119
- else
120
- console.log JSON.stringify({ error: 'Timeout waiting for the Jasmine test results!' })
121
-
122
- phantom.exit(1)
123
- else
124
- ready()
125
- clearInterval interval
141
+ timeoutFunction()
142
+ phantom.exit(1)
126
143
 
127
- interval = setInterval wait, 250
144
+ interval = setInterval wait, 250
@@ -1,11 +1,11 @@
1
1
  (function() {
2
- var currentSpecId, errors, logs, options, page, specsReady, waitFor;
2
+ var currentSpecId, errors, jasmineAvailable, jasmineMissing, jasmineReady, logs, options, page, specsDone, specsReady, specsTimedout, waitFor;
3
3
 
4
4
  phantom.injectJs('lib/result.js');
5
5
 
6
6
  options = {
7
7
  url: phantom.args[0] || 'http://127.0.0.1:3000/jasmine',
8
- timeout: parseInt(phantom.args[1] || 5000),
8
+ timeout: parseInt(phantom.args[1] || 10000),
9
9
  specdoc: phantom.args[2] || 'failure',
10
10
  focus: /true/i.test(phantom.args[3]),
11
11
  console: phantom.args[4] || 'failure',
@@ -32,6 +32,7 @@
32
32
 
33
33
  page.onConsoleMessage = function(msg, line, source) {
34
34
  var result;
35
+
35
36
  if (/^RUNNER_END$/.test(msg)) {
36
37
  result = page.evaluate(function() {
37
38
  return window.reporter.runnerResult;
@@ -53,15 +54,17 @@
53
54
  page.injectJs('lib/reporter.js');
54
55
  return page.evaluate(function() {
55
56
  return window.onload = function() {
57
+ window.onload = null;
56
58
  window.resultReceived = false;
57
59
  window.reporter = new ConsoleReporter();
58
- return jasmine.getEnv().addReporter(window.reporter);
60
+ if (window.jasmine) {
61
+ return jasmine.getEnv().addReporter(window.reporter);
62
+ }
59
63
  };
60
64
  });
61
65
  };
62
66
 
63
67
  page.open(options.url, function(status) {
64
- var done, error, runnerAvailable, text;
65
68
  page.onLoadFinished = function() {};
66
69
  if (status !== 'success') {
67
70
  console.log(JSON.stringify({
@@ -69,71 +72,89 @@
69
72
  }));
70
73
  return phantom.exit();
71
74
  } else {
72
- runnerAvailable = page.evaluate(function() {
73
- return window.jasmine;
74
- });
75
- if (runnerAvailable) {
76
- done = function() {
77
- return phantom.exit();
78
- };
79
- return waitFor(specsReady, done, options.timeout);
80
- } else {
81
- text = page.evaluate(function() {
82
- var _ref;
83
- return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
84
- });
85
- if (text) {
86
- error = "The Jasmine reporter is not available!\n\n" + text;
87
- console.log(JSON.stringify({
88
- error: error
89
- }));
90
- } else {
91
- console.log(JSON.stringify({
92
- error: 'The Jasmine reporter is not available!'
93
- }));
94
- }
95
- return phantom.exit(1);
96
- }
75
+ return waitFor(jasmineReady, jasmineAvailable, options.timeout, jasmineMissing);
97
76
  }
98
77
  });
99
78
 
79
+ jasmineReady = function() {
80
+ return page.evaluate(function() {
81
+ return window.jasmine;
82
+ });
83
+ };
84
+
85
+ jasmineAvailable = function() {
86
+ return waitFor(specsReady, specsDone, options.timeout, specsTimedout);
87
+ };
88
+
89
+ jasmineMissing = function() {
90
+ var error, text;
91
+
92
+ text = page.evaluate(function() {
93
+ var _ref;
94
+
95
+ return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
96
+ });
97
+ if (text) {
98
+ error = "The Jasmine reporter is not available!\n\n" + text;
99
+ return console.log(JSON.stringify({
100
+ error: error
101
+ }));
102
+ } else {
103
+ return console.log(JSON.stringify({
104
+ error: 'The Jasmine reporter is not available!'
105
+ }));
106
+ }
107
+ };
108
+
100
109
  specsReady = function() {
101
110
  return page.evaluate(function() {
102
111
  return window.resultReceived;
103
112
  });
104
113
  };
105
114
 
106
- waitFor = function(test, ready, timeout) {
115
+ specsTimedout = function() {
116
+ var error, text;
117
+
118
+ text = page.evaluate(function() {
119
+ var _ref;
120
+
121
+ return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
122
+ });
123
+ if (text) {
124
+ error = "Timeout waiting for the Jasmine test results!\n\n" + text;
125
+ return console.log(JSON.stringify({
126
+ error: error
127
+ }));
128
+ } else {
129
+ return console.log(JSON.stringify({
130
+ error: 'Timeout for the Jasmine test results!'
131
+ }));
132
+ }
133
+ };
134
+
135
+ specsDone = function() {
136
+ return phantom.exit();
137
+ };
138
+
139
+ waitFor = function(test, ready, timeout, timeoutFunction) {
107
140
  var condition, interval, start, wait;
141
+
108
142
  if (timeout == null) {
109
- timeout = 5000;
143
+ timeout = 10000;
110
144
  }
111
- start = new Date().getTime();
145
+ start = Date.now();
112
146
  condition = false;
147
+ interval = void 0;
113
148
  wait = function() {
114
- var error, text;
115
- if ((new Date().getTime() - start < timeout) && !condition) {
149
+ if ((Date.now() - start < timeout) && !condition) {
116
150
  return condition = test();
117
151
  } else {
118
- if (!condition) {
119
- text = page.evaluate(function() {
120
- var _ref;
121
- return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
122
- });
123
- if (text) {
124
- error = "Timeout waiting for the Jasmine test results!\n\n" + text;
125
- console.log(JSON.stringify({
126
- error: error
127
- }));
128
- } else {
129
- console.log(JSON.stringify({
130
- error: 'Timeout waiting for the Jasmine test results!'
131
- }));
132
- }
133
- return phantom.exit(1);
152
+ clearInterval(interval);
153
+ if (condition) {
154
+ return ready();
134
155
  } else {
135
- ready();
136
- return clearInterval(interval);
156
+ timeoutFunction();
157
+ return phantom.exit(1);
137
158
  }
138
159
  }
139
160
  };
@@ -3,32 +3,37 @@
3
3
  __slice = [].slice;
4
4
 
5
5
  Console = (function() {
6
-
7
6
  function Console(console) {
8
7
  var log;
8
+
9
9
  log = console.log;
10
10
  console.log = function() {
11
11
  var args;
12
+
12
13
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
13
14
  return log.call(console, Console.format.apply(Console, args));
14
15
  };
15
16
  console.info = function() {
16
17
  var args;
18
+
17
19
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
18
20
  return log.call(console, "INFO: " + (Console.format.apply(Console, args)));
19
21
  };
20
22
  console.warn = function() {
21
23
  var args;
24
+
22
25
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
23
26
  return log.call(console, "WARN: " + (Console.format.apply(Console, args)));
24
27
  };
25
28
  console.error = function() {
26
29
  var args;
30
+
27
31
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
28
32
  return log.call(console, "ERROR: " + (Console.format.apply(Console, args)));
29
33
  };
30
34
  console.debug = function() {
31
35
  var args;
36
+
32
37
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
33
38
  return log.call(console, "DEBUG: " + (Console.format.apply(Console, args)));
34
39
  };
@@ -39,6 +44,7 @@
39
44
  Console.format = function() {
40
45
  var arg, args, result, _i, _len,
41
46
  _this = this;
47
+
42
48
  args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
43
49
  result = [];
44
50
  if (typeof args[0] === 'string' && /%[sdifo]/gi.test(args[0])) {
@@ -56,6 +62,7 @@
56
62
 
57
63
  Console.inspect = function(object, type) {
58
64
  var match, result;
65
+
59
66
  switch (type) {
60
67
  case '%s':
61
68
  result = String(object);
@@ -93,6 +100,7 @@
93
100
 
94
101
  Console.pp = function(object, depth) {
95
102
  var key, result, type, value, _i, _len;
103
+
96
104
  if (depth == null) {
97
105
  depth = 0;
98
106
  }
@@ -2,7 +2,6 @@
2
2
  var ConsoleReporter;
3
3
 
4
4
  ConsoleReporter = (function() {
5
-
6
5
  function ConsoleReporter() {}
7
6
 
8
7
  ConsoleReporter.prototype.runnerResult = {
@@ -27,6 +26,7 @@
27
26
 
28
27
  ConsoleReporter.prototype.reportSpecResults = function(spec) {
29
28
  var messages, result, specResult, _base, _i, _len, _name, _ref;
29
+
30
30
  if (!spec.results().skipped) {
31
31
  specResult = {
32
32
  id: spec.id,
@@ -52,6 +52,7 @@
52
52
 
53
53
  ConsoleReporter.prototype.reportSuiteResults = function(suite) {
54
54
  var parent, suiteResult, _base, _ref;
55
+
55
56
  if (!suite.results().skipped) {
56
57
  suiteResult = {
57
58
  id: suite.id,
@@ -77,6 +78,7 @@
77
78
 
78
79
  ConsoleReporter.prototype.reportRunnerResults = function(runner) {
79
80
  var end, runtime;
81
+
80
82
  runtime = (new Date().getTime() - this.startTime) / 1000;
81
83
  this.runnerResult['passed'] = runner.results().failedCount === 0;
82
84
  this.runnerResult['stats'] = {
@@ -99,6 +101,7 @@
99
101
 
100
102
  ConsoleReporter.prototype.addNestedSuites = function(suiteResult) {
101
103
  var suite, _i, _len, _ref, _results;
104
+
102
105
  if (this.nestedSuiteResults[suiteResult.id]) {
103
106
  _ref = this.nestedSuiteResults[suiteResult.id];
104
107
  _results = [];
@@ -113,6 +116,7 @@
113
116
 
114
117
  ConsoleReporter.prototype.removeEmptySuites = function(suiteResult) {
115
118
  var suite, suites, _i, _len, _ref;
119
+
116
120
  suites = [];
117
121
  _ref = suiteResult.suites;
118
122
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -1,9 +1,7 @@
1
- // Generated by CoffeeScript 1.3.3
2
1
  (function() {
3
2
  var Result;
4
3
 
5
4
  Result = (function() {
6
-
7
5
  function Result(result, logs, errors, options) {
8
6
  this.result = result;
9
7
  this.logs = logs != null ? logs : {};
@@ -13,8 +11,10 @@
13
11
 
14
12
  Result.prototype.addLogs = function(suite) {
15
13
  var id, s, spec;
14
+
16
15
  suite.suites = (function() {
17
16
  var _i, _len, _ref, _results;
17
+
18
18
  _ref = suite.suites;
19
19
  _results = [];
20
20
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -26,6 +26,7 @@
26
26
  if (suite.specs) {
27
27
  suite.specs = (function() {
28
28
  var _i, _len, _ref, _results;
29
+
29
30
  _ref = suite.specs;
30
31
  _results = [];
31
32
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -46,8 +47,10 @@
46
47
 
47
48
  Result.prototype.addErrors = function(suite) {
48
49
  var id, s, spec;
50
+
49
51
  suite.suites = (function() {
50
52
  var _i, _len, _ref, _results;
53
+
51
54
  _ref = suite.suites;
52
55
  _results = [];
53
56
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -59,6 +62,7 @@
59
62
  if (suite.specs) {
60
63
  suite.specs = (function() {
61
64
  var _i, _len, _ref, _results;
65
+
62
66
  _ref = suite.specs;
63
67
  _results = [];
64
68
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -77,8 +81,9 @@
77
81
  return suite;
78
82
  };
79
83
 
80
- Result.prototype.addGlobalErrors = function(suite) {
84
+ Result.prototype.addGlobalError = function(suite) {
81
85
  var b, err, errMsg, globalErrors, noSpecs, noSuites, _i, _len, _ref;
86
+
82
87
  noSuites = !suite.suites || suite.suites.length === 0;
83
88
  noSpecs = !suite.specs || suite.specs.length === 0;
84
89
  globalErrors = this.errors[-1] && this.errors[-1].length !== 0;
@@ -97,8 +102,10 @@
97
102
 
98
103
  Result.prototype.cleanResult = function(suite) {
99
104
  var s, spec, _i, _len, _ref;
105
+
100
106
  suite.suites = (function() {
101
107
  var _i, _len, _ref, _results;
108
+
102
109
  _ref = suite.suites;
103
110
  _results = [];
104
111
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -125,7 +132,7 @@
125
132
  }
126
133
  if (this.options.errors !== 'never') {
127
134
  this.addErrors(this.result);
128
- this.addGlobalErrors(this.result);
135
+ this.addGlobalError(this.result);
129
136
  }
130
137
  this.cleanResult(this.result);
131
138
  return this.result;
@@ -1,6 +1,6 @@
1
1
  module Guard
2
2
  module JasmineVersion
3
3
  # Guard::Jasmine version that is used for the Gem specification
4
- VERSION = '1.16.0'
4
+ VERSION = '1.17.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-jasmine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.0
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Kessler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-27 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: 1.3.6
149
149
  requirements: []
150
150
  rubyforge_project: guard-jasmine
151
- rubygems_version: 2.0.3
151
+ rubygems_version: 2.0.2
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Guard gem for headless testing with Jasmine