guard-jasmine 2.0.0 → 2.0.1

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: 01546cd2d6366e46000c481b06b3adeaaaa2f1c7
4
- data.tar.gz: ba99f0a41f8880d28e1e0647a92e341fddd68ac6
3
+ metadata.gz: 653c1770a0ee0afde89d96bc6b55e89523f9e6a7
4
+ data.tar.gz: 9da1156f41c0da97723d2ab83b908b02b7588faf
5
5
  SHA512:
6
- metadata.gz: 1cb190cf4bf114ec1e05fce5884e16e7f92aac49d7ba54365c835092668cd1c9747176df8e45ec5822381d162974d3a6a16c9a70d7864834a6afb957366cae95
7
- data.tar.gz: a03f6e169a0c472094ad6856d824e06e3e93227cecb75a3a3ee62adccf51f6dacd0598d3cdc93ee034b1737eeb432282fd2e1feb6750f3dcbff1d46ee5f826af
6
+ metadata.gz: 19f799979a9d26cc253abffd4e5ddf34d3c95e56ac0443f5d79242a3d6659eb31bdea642445c1edc52e836925ab4440647dda3c743a2e348201731dbc84f16b1
7
+ data.tar.gz: 1bd4ab0e7aa91dd28e1f031fb113b2c95930a6b2bdcac7b9b8101a0494cda518f414565d9b800840402c34a4cc492dc29630cb1743be7e4d6380f9b2411e9b04
@@ -2,7 +2,7 @@ require 'rails/generators'
2
2
 
3
3
  module GuardJasmine
4
4
  class InstallGenerator < Rails::Generators::Base
5
- desc "Install a sample Guardfile for running Jasmine specs via GuardJasmine"
5
+ desc 'Install a sample Guardfile for running Jasmine specs via GuardJasmine'
6
6
 
7
7
  def self.source_root
8
8
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
@@ -10,8 +10,7 @@ module GuardJasmine
10
10
 
11
11
  # Generator Code. Remember this is just suped-up Thor so methods are executed in order
12
12
  def install
13
- template "Guardfile"
13
+ template 'Guardfile'
14
14
  end
15
-
16
15
  end
17
16
  end
@@ -2,8 +2,8 @@
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
4
  guard :jasmine do
5
- watch(%r{^spec/javascripts/.*(?:_s|S)pec\.(coffee|js)$})
6
- watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m|
7
- "spec/javascripts/jasmine/#{ m[1] }_spec.#{ m[2] }"
8
- }
5
+ watch(%r{^spec/javascripts/.*(?:_s|S)pec\.(coffee|js)$})
6
+ watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) do |m|
7
+ "spec/javascripts/jasmine/#{ m[1] }_spec.#{ m[2] }"
8
+ end
9
9
  end
@@ -1,15 +1,13 @@
1
1
  require 'net/http'
2
2
 
3
- require 'guard'
4
- require 'guard/plugin'
3
+ # Don't require "guard/plugin" here or in any other plugin's files
4
+ require 'guard/compat/plugin'
5
5
 
6
6
  module Guard
7
-
8
7
  # The Jasmine guard that gets notifications about the following
9
8
  # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_modifications`.
10
9
  #
11
10
  class Jasmine < Plugin
12
-
13
11
  require 'guard/jasmine/coverage'
14
12
  require 'guard/jasmine/inspector'
15
13
  require 'guard/jasmine/runner'
@@ -43,7 +41,7 @@ module Guard
43
41
  focus: true,
44
42
  coverage: false,
45
43
  coverage_html: false,
46
- coverage_html_dir: "./coverage",
44
+ coverage_html_dir: './coverage',
47
45
  coverage_summary: false,
48
46
  statements_threshold: 0,
49
47
  functions_threshold: 0,
@@ -88,17 +86,17 @@ module Guard
88
86
  # @option options [Symbol] :lines_threshold options for the statement lines threshold
89
87
  # @option options [Hash] :run_all options overwrite options when run all specs
90
88
  #
91
- def initialize(options = { })
89
+ def initialize(options = {})
92
90
  options[:server_mount] ||= defined?(JasmineRails) ? '/specs' : '/jasmine'
93
91
 
94
92
  options = DEFAULT_OPTIONS.merge(options)
95
93
 
96
- options[:spec_dir] ||= File.exists?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec'
94
+ options[:spec_dir] ||= File.exist?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec'
97
95
  options[:server] ||= :auto
98
96
  options[:server] = ::Guard::Jasmine::Server.detect_server(options[:spec_dir]) if options[:server] == :auto
99
97
  options[:port] ||= ::Guard::Jasmine::Server.choose_server_port(options)
100
98
  options[:jasmine_url] = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : options[:server_mount] }" unless options[:jasmine_url]
101
- options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc]
99
+ options[:specdoc] = :failure unless [:always, :never, :failure].include? options[:specdoc]
102
100
  options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin]
103
101
 
104
102
  self.run_all_options = options.delete(:run_all) || {}
@@ -107,7 +105,7 @@ module Guard
107
105
 
108
106
  self.last_run_failed = false
109
107
  self.last_failed_paths = []
110
- @runner = Runner.new( options.merge(self.run_all_options) )
108
+ @runner = Runner.new(options.merge(run_all_options))
111
109
  end
112
110
 
113
111
  # Gets called once when Guard starts.
@@ -119,9 +117,7 @@ module Guard
119
117
 
120
118
  Server.start(options) unless options[:server] == :none
121
119
 
122
- if Jasmine.runner_available?(options)
123
- run_all if options[:all_on_start]
124
- end
120
+ run_all if Jasmine.runner_available?(options) && options[:all_on_start]
125
121
  else
126
122
  throw :task_has_failed
127
123
  end
@@ -154,7 +150,7 @@ module Guard
154
150
  self.last_failed_paths = results.keys
155
151
  self.last_run_failed = !results.empty?
156
152
 
157
- throw :task_has_failed if self.last_run_failed
153
+ throw :task_has_failed if last_run_failed
158
154
  end
159
155
  # Gets called when watched paths and files have changes.
160
156
  #
@@ -162,8 +158,7 @@ module Guard
162
158
  # @raise [:task_has_failed] when run_on_modifications has failed
163
159
  #
164
160
  def run_on_modifications(paths)
165
-
166
- specs = options[:keep_failed] ? paths + self.last_failed_paths : paths
161
+ specs = options[:keep_failed] ? paths + last_failed_paths : paths
167
162
  specs = Inspector.clean(specs, options) if options[:clean]
168
163
 
169
164
  return false if specs.empty?
@@ -171,17 +166,15 @@ module Guard
171
166
  results = runner.run(specs)
172
167
 
173
168
  if results.empty?
174
- self.last_failed_paths = self.last_failed_paths - paths
175
- run_all if self.last_run_failed && options[:all_after_pass]
169
+ self.last_failed_paths = last_failed_paths - paths
170
+ run_all if last_run_failed && options[:all_after_pass]
176
171
  else
177
- self.last_failed_paths = self.last_failed_paths + results.keys
172
+ self.last_failed_paths = last_failed_paths + results.keys
178
173
  end
179
174
 
180
175
  self.last_run_failed = !results.empty?
181
176
 
182
- throw :task_has_failed if self.last_run_failed
177
+ throw :task_has_failed if last_run_failed
183
178
  end
184
-
185
179
  end
186
180
  end
187
-
@@ -1,5 +1,4 @@
1
1
  require 'thor'
2
- require 'guard/ui'
3
2
  require 'guard/jasmine/version'
4
3
  require 'guard/jasmine/runner'
5
4
  require 'guard/jasmine/formatter'
@@ -9,7 +8,6 @@ require 'guard/jasmine/server'
9
8
 
10
9
  module Guard
11
10
  class Jasmine
12
-
13
11
  # Small helper class to run the Jasmine runner_options once from the
14
12
  # command line. This can be useful to integrate guard-jasmine
15
13
  # into a continuous integration server.
@@ -119,7 +117,7 @@ module Guard
119
117
 
120
118
  method_option :coverage_html_dir,
121
119
  type: :string,
122
- default: "./coverage",
120
+ default: './coverage',
123
121
  desc: 'Where to save html coverage reports. Defaults to ./coverage. Implies --coverage-html'
124
122
 
125
123
  method_option :coverage_summary,
@@ -129,7 +127,7 @@ module Guard
129
127
 
130
128
  method_option :ignore_instrumentation,
131
129
  type: :string,
132
- default: "",
130
+ default: '',
133
131
  desc: 'Files matching this regex will not be instrumented (e.g. vendor)'
134
132
 
135
133
  method_option :statements_threshold,
@@ -175,7 +173,7 @@ module Guard
175
173
  def spec(*paths)
176
174
  runner_options = {}
177
175
  runner_options[:port] = options.port || CLI.find_free_server_port
178
- runner_options[:spec_dir] = options.spec_dir || (File.exists?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec')
176
+ runner_options[:spec_dir] = options.spec_dir || (File.exist?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec')
179
177
  runner_options[:line_number] = options.line_number
180
178
  runner_options[:server] = options.server.to_sym == :auto ? ::Guard::Jasmine::Server.detect_server(runner_options[:spec_dir]) : options.server.to_sym
181
179
  runner_options[:server_mount] = options.mount || (defined?(JasmineRails) ? '/specs' : '/jasmine')
@@ -190,8 +188,8 @@ module Guard
190
188
  runner_options[:errors] = [:always, :never, :failure].include?(options.errors.to_sym) ? options.errors.to_sym : :failure
191
189
  runner_options[:specdoc] = [:always, :never, :failure].include?(options.specdoc.to_sym) ? options.specdoc.to_sym : :always
192
190
  runner_options[:focus] = options.focus
193
- runner_options[:coverage] = options.coverage || options.coverage_html || options.coverage_summary || options.coverage_html_dir != "./coverage"
194
- runner_options[:coverage_html] = options.coverage_html || options.coverage_html_dir != "./coverage"
191
+ runner_options[:coverage] = options.coverage || options.coverage_html || options.coverage_summary || options.coverage_html_dir != './coverage'
192
+ runner_options[:coverage_html] = options.coverage_html || options.coverage_html_dir != './coverage'
195
193
  runner_options[:coverage_html_dir] = options.coverage_html_dir
196
194
  runner_options[:coverage_summary] = options.coverage_summary
197
195
  runner_options[:ignore_instrumentation] = options.ignore_instrumentation
@@ -207,8 +205,6 @@ module Guard
207
205
  runner_options[:junit_save_path] = options.junit_save_path
208
206
  runner_options[:is_cli] = true
209
207
 
210
- ::Guard::UI.options = ::Guard::UI.options.merge({ :template => ':message' })
211
-
212
208
  paths = [runner_options[:spec_dir]] if paths.empty?
213
209
 
214
210
  if CLI.phantomjs_bin_valid?(runner_options[:phantomjs_bin])
@@ -245,7 +241,6 @@ module Guard
245
241
  def version
246
242
  ::Guard::UI.info "Guard::Jasmine version #{ ::Guard::JasmineVersion::VERSION }"
247
243
  end
248
-
249
244
  end
250
245
  end
251
246
  end
@@ -15,32 +15,30 @@ class JasmineCoverage < Tilt::Template
15
15
 
16
16
  # Returns a coverage instrumented JavaScript file
17
17
  #
18
- def evaluate(context, locals)
18
+ def evaluate(_context, _locals)
19
19
  return data if !ENV['IGNORE_INSTRUMENTATION'].to_s.empty? && file =~ Regexp.new(ENV['IGNORE_INSTRUMENTATION'])
20
20
  return data unless JasmineCoverage.coverage_bin
21
21
  return data unless file.include?(JasmineCoverage.app_asset_path)
22
22
 
23
23
  Dir.mktmpdir do |path|
24
24
  filename = File.basename(file)
25
- input = File.join(path, filename).sub /\.js.+/, '.js'
25
+ input = File.join(path, filename).sub(/\.js.+/, '.js')
26
26
 
27
27
  File.write input, data
28
28
 
29
- result = %x[#{JasmineCoverage.coverage_bin} instrument --embed-source #{input.shellescape}]
29
+ result = `#{JasmineCoverage.coverage_bin} instrument --embed-source #{input.shellescape}`
30
30
 
31
- raise "Could not generate coverage instrumented file for #{ file }" unless $?.exitstatus == 0
31
+ fail "Could not generate coverage instrumented file for #{ file }" unless $CHILD_STATUS.exitstatus == 0
32
32
 
33
33
  result.gsub input, file
34
-
35
34
  end
36
35
  end
37
36
 
38
- private
39
-
40
37
  # Get the absolute path to the projects assets path `/app/assets`.
41
38
  #
42
39
  # @return [String] the path to the Rails assets
43
40
  #
41
+ # @private
44
42
  def self.app_asset_path
45
43
  @app_asset_path ||= File.join(Rails.root, 'app', 'assets')
46
44
  end
@@ -49,13 +47,13 @@ class JasmineCoverage < Tilt::Template
49
47
  #
50
48
  # @return [String] the path
51
49
  #
50
+ # @private
52
51
  def self.coverage_bin
53
52
  @coverage_bin ||= which 'istanbul'
54
53
  end
55
-
56
54
  end
57
55
 
58
- if ENV['COVERAGE'] == 'true' and defined?(Rails)
56
+ if ENV['COVERAGE'] == 'true' && defined?(Rails)
59
57
 
60
58
  # Guard::Jasmine engine to register coverage instrumented
61
59
  # Jasmine spec files.
@@ -1,20 +1,18 @@
1
1
  module Guard
2
2
  class Jasmine
3
-
4
3
  # The Guard::Jasmine formatter collects console and
5
4
  # system notification methods and enhances them with
6
5
  # some color information.
7
6
  #
8
7
  module Formatter
9
8
  class << self
10
-
11
9
  # Print an info message to the console.
12
10
  #
13
11
  # @param [String] message the message to print
14
12
  # @param [Hash] options the output options
15
13
  # @option options [Boolean] :reset reset the UI
16
14
  #
17
- def info(message, options = { })
15
+ def info(message, options = {})
18
16
  ::Guard::UI.info(message, options)
19
17
  end
20
18
 
@@ -24,7 +22,7 @@ module Guard
24
22
  # @param [Hash] options the output options
25
23
  # @option options [Boolean] :reset reset the UI
26
24
  #
27
- def debug(message, options = { })
25
+ def debug(message, options = {})
28
26
  ::Guard::UI.debug(message, options)
29
27
  end
30
28
 
@@ -34,7 +32,7 @@ module Guard
34
32
  # @param [Hash] options the output options
35
33
  # @option options [Boolean] :reset reset the UI
36
34
  #
37
- def error(message, options = { })
35
+ def error(message, options = {})
38
36
  ::Guard::UI.error(color(message, ';31'), options)
39
37
  end
40
38
 
@@ -44,7 +42,7 @@ module Guard
44
42
  # @param [Hash] options the output options
45
43
  # @option options [Boolean] :reset reset the UI
46
44
  #
47
- def success(message, options = { })
45
+ def success(message, options = {})
48
46
  ::Guard::UI.info(color(message, ';32'), options)
49
47
  end
50
48
 
@@ -54,7 +52,7 @@ module Guard
54
52
  # @param [Hash] options the output options
55
53
  # @option options [Boolean] :reset reset the UI
56
54
  #
57
- def spec_pending(message, options = { })
55
+ def spec_pending(message, options = {})
58
56
  ::Guard::UI.info(color(message, ';33'), options)
59
57
  end
60
58
 
@@ -63,7 +61,7 @@ module Guard
63
61
  # @param [String] message the message to print
64
62
  # @param [Hash] options the output options
65
63
  #
66
- def spec_failed(message, options = { })
64
+ def spec_failed(message, options = {})
67
65
  ::Guard::UI.info(color(message, ';31'), options)
68
66
  end
69
67
 
@@ -72,7 +70,7 @@ module Guard
72
70
  # @param [String] message the message to print
73
71
  # @param [Hash] options the output options
74
72
  #
75
- def suite_name(message, options = { })
73
+ def suite_name(message, options = {})
76
74
  ::Guard::UI.info(color(message, ';33'), options)
77
75
  end
78
76
 
@@ -83,7 +81,7 @@ module Guard
83
81
  # @option options [Symbol, String] :image the image to use, either :failed, :pending or :success, or an image path
84
82
  # @option options [String] :title the title of the system notification
85
83
  #
86
- def notify(message, options = { })
84
+ def notify(message, options = {})
87
85
  ::Guard::Notifier.notify(message, options)
88
86
  end
89
87
 
@@ -97,7 +95,6 @@ module Guard
97
95
  def color(text, color_code)
98
96
  ::Guard::UI.send(:color_enabled?) ? "\e[0#{ color_code }m#{ text }\e[0m" : text
99
97
  end
100
-
101
98
  end
102
99
  end
103
100
  end
@@ -1,6 +1,5 @@
1
1
  module Guard
2
2
  class Jasmine
3
-
4
3
  # The inspector verifies if the changed paths are valid
5
4
  # for Guard::Jasmine. Please note that request to {.clean}
6
5
  # paths keeps the current valid files cached until {.clear} is
@@ -8,7 +7,6 @@ module Guard
8
7
  #
9
8
  module Inspector
10
9
  class << self
11
-
12
10
  # Clean the changed paths and return only valid
13
11
  # Jasmine specs in either JavaScript or CoffeeScript.
14
12
  #
@@ -37,9 +35,8 @@ module Guard
37
35
  # @return [Boolean] when the file valid
38
36
  #
39
37
  def jasmine_spec?(path)
40
- path =~ /(?:_s|S)pec\.(js|coffee|js\.coffee)$/ && File.exists?(path)
38
+ path =~ /(?:_s|S)pec\.(js|coffee|js\.coffee)$/ && File.exist?(path)
41
39
  end
42
-
43
40
  end
44
41
  end
45
42
  end
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- var exitSuccessfully, jasmineAvailable, options, page, reportError, reporterMissing, reporterReady, specsDone, specsTimedout, waitFor;
2
+ var exitSuccessfully, jasmineAvailable, options, page, phantomExit, reportError, reporterMissing, reporterReady, specsDone, specsTimedout, waitFor;
3
3
 
4
4
  options = {
5
5
  url: phantom.args[0] || 'http://127.0.0.1:3000/jasmine',
@@ -60,13 +60,20 @@
60
60
  });
61
61
  };
62
62
 
63
+ phantomExit = function(exitCode) {
64
+ page.close();
65
+ return setTimeout(function() {
66
+ return phantom.exit(exitCode);
67
+ }, 0);
68
+ };
69
+
63
70
  exitSuccessfully = function() {
64
71
  var results;
65
72
  results = page.evaluate(function() {
66
73
  return window.reporter.results();
67
74
  });
68
75
  console.log(JSON.stringify(results));
69
- return phantom.exit();
76
+ return phantomExit();
70
77
  };
71
78
 
72
79
  specsTimedout = function() {
@@ -75,7 +82,8 @@
75
82
  var _ref;
76
83
  return (_ref = document.getElementsByTagName('body')[0]) != null ? _ref.innerText : void 0;
77
84
  });
78
- return reportError("Timeout waiting for the Jasmine test results!\n\n" + text);
85
+ reportError("Timeout waiting for the Jasmine test results!\n\n" + text);
86
+ return phantomExit(1);
79
87
  };
80
88
 
81
89
  waitFor = function(test, ready, timeout, timeoutFunction) {
@@ -114,7 +122,7 @@
114
122
  error: msg,
115
123
  trace: trace
116
124
  }));
117
- return phantom.exit(1);
125
+ return phantomExit(1);
118
126
  };
119
127
 
120
128
  }).call(this);
@@ -55,21 +55,31 @@ specsDone = ->
55
55
  result = page.evaluate ->
56
56
  window.reporter.resultComplete
57
57
 
58
+ # Workaround for https://github.com/ariya/phantomjs/issues/12697 since
59
+ # it doesn't seem like there will be another 1.9.x release fixing this
60
+ phantomExit = (exitCode)->
61
+ page.close()
62
+ setTimeout( ->
63
+ phantom.exit(exitCode)
64
+ ,0)
65
+
66
+
58
67
  # We should end up here. Logs the results as JSON and exits
59
68
  exitSuccessfully = ->
60
69
  results = page.evaluate -> window.reporter.results()
61
70
  console.log JSON.stringify( results )
62
- phantom.exit()
71
+ phantomExit()
63
72
 
64
73
 
65
74
  # Error message for when specs time out
66
75
  specsTimedout = ->
67
- text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
68
- reportError """
76
+ text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
77
+ reportError """
69
78
  Timeout waiting for the Jasmine test results!
70
79
 
71
80
  #{ text }
72
81
  """
82
+ return phantomExit(1)
73
83
 
74
84
  # Wait until the test condition is true or a timeout occurs.
75
85
  #
@@ -98,4 +108,4 @@ reportError = (msg, trace=[])->
98
108
  err = new Error();
99
109
  trace = err.stack
100
110
  console.log JSON.stringify({ error: msg, trace: trace })
101
- phantom.exit(1)
111
+ return phantomExit(1)