jasmine 3.2.0 → 3.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ function ChromeHeadlessReporter() {
2
+ this.jasmineDone = function(details) {
3
+ console.log('jasmine_done', JSON.stringify(details));
4
+ };
5
+
6
+ this.specDone = function(results) {
7
+ console.log('jasmine_spec_result', JSON.stringify([].concat(results)));
8
+ };
9
+
10
+ this.suiteDone = function(results) {
11
+ console.log('jasmine_suite_result',JSON.stringify([].concat(results)));
12
+ };
13
+ }
14
+
15
+ jasmine.getEnv().addReporter(new ChromeHeadlessReporter());
@@ -59,7 +59,11 @@ namespace :jasmine do
59
59
  config = Jasmine.config
60
60
  port = config.port(:server)
61
61
  server = Jasmine::Server.new(port, Jasmine::Application.app(Jasmine.config), config.rack_options)
62
- puts "your server is running here: http://localhost:#{port}/"
62
+ if config.random
63
+ puts "your server is running here: http://localhost:#{port}/"
64
+ else
65
+ puts "your server is running here: http://localhost:#{port}/?random=false"
66
+ end
63
67
  puts "your tests are here: #{config.spec_dir}"
64
68
  puts "your source files are here: #{config.src_dir}"
65
69
  puts ''
@@ -1,3 +1,3 @@
1
1
  module Jasmine
2
- VERSION = "3.2.0"
2
+ VERSION = "3.6.0"
3
3
  end
@@ -0,0 +1,19 @@
1
+ # Jasmine Gem 3.3 Release Notes
2
+
3
+ ## Summary
4
+
5
+ This release updates the jasmine-core dependency to 3.3.0. See the
6
+ [jasmine-core release notes](https://github.com/jasmine/jasmine/blob/master/release_notes/3.3.0.md)
7
+ for more information
8
+
9
+ ## Changes
10
+
11
+ * Fix jasmine-core dependency to allow patch version changes
12
+
13
+ * Remove Rails 3 from README since it is no longer supported.
14
+ - See #299
15
+
16
+
17
+ ------
18
+
19
+ _Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
@@ -0,0 +1,17 @@
1
+ # Jasmine Gem 3.4 Release Notes
2
+
3
+ ## Summary
4
+
5
+ This release updates the jasmine-core dependency to 3.4.0. See the
6
+ [jasmine-core release notes](https://github.com/jasmine/jasmine/blob/master/release_notes/3.4.0.md)
7
+ for more information
8
+
9
+ ## Changes
10
+
11
+ * Chrome headless as an option to phantomJS
12
+ - Merges [#301](https://github.com/jasmine/jasmine-gem/issues/301) from @stoivo
13
+ - Fixes [#293](https://github.com/jasmine/jasmine-gem/issues/293)
14
+
15
+ ------
16
+
17
+ _Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
@@ -0,0 +1,16 @@
1
+ # Jasmine Gem 3.5 Release Notes
2
+
3
+ ## Summary
4
+
5
+ This release updates the jasmine-core dependency to 3.5.0. See the
6
+ [jasmine-core release notes](https://github.com/jasmine/jasmine/blob/master/release_notes/3.5.0.md)
7
+ for more information
8
+
9
+ ## Changes
10
+
11
+ * Add docs for how to use the new Chrome Headless runner
12
+ - Fixes [#308](https://github.com/jasmine/jasmine-gem/issues/308)
13
+
14
+ ------
15
+
16
+ _Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
@@ -0,0 +1,18 @@
1
+ # Jasmine Gem 3.5.1 Release Notes
2
+
3
+ ## Summary
4
+
5
+ This update allows the gem to continue working with Sprockets in Rails 6
6
+
7
+ ## Changes
8
+
9
+ * Various readme improvements
10
+ - Merges [#312](https://github.com/jasmine/jasmine-gem/issues/312) from @cprodhomme
11
+
12
+ * Allow Jasmine to continue to work with Rails 6
13
+ - Merges [#310](https://github.com/jasmine/jasmine-gem/issues/310) from @cbaines
14
+ - Fixes [#311](https://github.com/jasmine/jasmine-gem/issues/311)
15
+
16
+ ------
17
+
18
+ _Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
@@ -0,0 +1,31 @@
1
+ # Jasmine Gem 3.6 Release Notes
2
+
3
+ ## Summary
4
+
5
+ This release updates the jasmine-core dependency to 3.6.0. See the
6
+ [jasmine-core release notes](https://github.com/jasmine/jasmine/blob/main/release_notes/3.6.0.md)
7
+ for more information
8
+
9
+
10
+ ## Changes
11
+
12
+ * Change jasmine:server url depending on random flag
13
+ * Merges #317 from @vimalloc
14
+ * Fixes #307
15
+
16
+ * Fix Action View deprecation warnings in Rails 6
17
+ * Merges #318 from @pixeltrix
18
+
19
+ * Prevent race condition with Chrome Remote startup
20
+ * Merges #316 from @stoivo
21
+
22
+ * Add API to enable/disable coloring text
23
+ * Merges #313 from @soutaro
24
+
25
+ * Add support for chrome from yaourt
26
+ * Merges #315 from @TheBlackArroVV
27
+ * Fixes #314
28
+
29
+ ------
30
+
31
+ _Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jasmine::Runners::ChromeHeadless do
4
+
5
+ let(:config) {
6
+ {
7
+ show_console_log: nil,
8
+ show_full_stack_trace: nil,
9
+ chrome_cli_options: nil,
10
+ chrome_binary: nil,
11
+ }
12
+ }
13
+
14
+ it 'uses chrome_binary from config is set' do
15
+ config[:chrome_binary] = "some_path"
16
+ runner = Jasmine::Runners::ChromeHeadless.new(nil, nil, double(config))
17
+
18
+ expect(runner.chrome_binary).to eq("some_path")
19
+ end
20
+
21
+ it 'uses chrome_binary from default chrome path if it exist' do
22
+ allow(File).to receive(:file?).and_return(true)
23
+ runner = Jasmine::Runners::ChromeHeadless.new(nil, nil, double(config))
24
+
25
+ expect(runner.chrome_binary).to eq("/usr/bin/google-chrome")
26
+ end
27
+
28
+ it 'chrome_binary raise an exeption if nowhere to be found' do
29
+ allow(File).to receive(:file?).and_return(false)
30
+ runner = Jasmine::Runners::ChromeHeadless.new(nil, nil, double(config))
31
+
32
+ expect {
33
+ runner.chrome_binary
34
+ }.to raise_error(RuntimeError)
35
+ end
36
+
37
+ describe "cli_options_string" do
38
+ it "empty hash is empty result" do
39
+ runner = Jasmine::Runners::ChromeHeadless.new(nil, nil, double(config))
40
+ expect(runner.cli_options_string).to eq("")
41
+ end
42
+
43
+ it "formats hash properly" do
44
+ config[:chrome_cli_options] = {"no-sandbox" => nil, "headless" => nil, "remote-debugging-port" => 9222}
45
+ runner = Jasmine::Runners::ChromeHeadless.new(nil, nil, double(config))
46
+ expect(runner.cli_options_string).to eq("--no-sandbox --headless --remote-debugging-port=9222")
47
+ end
48
+ end
49
+
50
+ end
@@ -61,6 +61,149 @@ describe Jasmine::CiRunner do
61
61
  expect(runner).to have_received(:run)
62
62
  end
63
63
 
64
+ it 'instantiates all formatters' do
65
+ class SimpleFormatter1
66
+ end
67
+
68
+ class SimpleFormatter2
69
+ end
70
+
71
+ expect(config).to receive(:formatters) { [SimpleFormatter1, SimpleFormatter2] }
72
+
73
+ ci_runner = Jasmine::CiRunner.new(config, thread: fake_thread, application_factory: application_factory, server_factory: server_factory, outputter: outputter)
74
+
75
+ ci_runner.run
76
+
77
+ expect(runner_factory).to have_received(:call).with(anything, anything) do |multi_formatter, url|
78
+ expect_any_instance_of(SimpleFormatter1).to receive(:format)
79
+ expect_any_instance_of(SimpleFormatter2).to receive(:format)
80
+
81
+ multi_formatter.format([])
82
+ end
83
+ end
84
+
85
+ it 'instantiates formatters with arguments' do
86
+ class SimpleFormatter
87
+ attr_reader :obj
88
+ def initialize(obj)
89
+ @obj = obj
90
+ end
91
+ end
92
+
93
+ expect(config).to receive(:formatters) { [SimpleFormatter] }
94
+
95
+ ci_runner = Jasmine::CiRunner.new(config, thread: fake_thread, application_factory: application_factory, server_factory: server_factory, outputter: outputter)
96
+
97
+ ci_runner.run
98
+
99
+ expect(runner_factory).to have_received(:call).with(anything, anything) do |multi_formatter, url|
100
+ expect_any_instance_of(SimpleFormatter).to receive(:format) do |formatter, results|
101
+ expect(formatter.obj).to eq(config)
102
+ end
103
+
104
+ multi_formatter.format([])
105
+ end
106
+ end
107
+
108
+ it 'works with formatters that are not classes' do
109
+ class Factory1
110
+ attr_reader :called
111
+ def new
112
+ @called = true
113
+ nil
114
+ end
115
+ end
116
+
117
+ class Factory2
118
+ attr_reader :called
119
+ attr_reader :obj
120
+ def new(obj)
121
+ @obj = obj
122
+ @called = true
123
+ nil
124
+ end
125
+ end
126
+
127
+ factory1 = Factory1.new
128
+ factory2 = Factory2.new
129
+
130
+ expect(config).to receive(:formatters) { [factory1, factory2] }
131
+
132
+ ci_runner = Jasmine::CiRunner.new(config, thread: fake_thread, application_factory: application_factory, server_factory: server_factory, outputter: outputter)
133
+
134
+ ci_runner.run
135
+
136
+ expect(factory1.called).to eq(true)
137
+ expect(factory2.called).to eq(true)
138
+ expect(factory2.obj).to eq(config)
139
+ end
140
+
141
+ it 'handles optional arguments by only passing config when it is required' do
142
+ class NoConfigFormatter
143
+ attr_reader :optional
144
+ def initialize(optional = {config: 'no'})
145
+ @optional = optional
146
+ end
147
+ end
148
+
149
+ class HasConfigFormatter
150
+ attr_reader :obj, :optional
151
+ def initialize(obj, optional = {config: 'no'})
152
+ @obj = obj
153
+ @optional = optional
154
+ end
155
+ end
156
+
157
+ class NoConfigFactory
158
+ def initialize(dummy_formatter)
159
+ @dummy_formatter = dummy_formatter
160
+ end
161
+ attr_reader :optional
162
+ def new(optional = {config: 'no'})
163
+ @optional = optional
164
+ @dummy_formatter
165
+ end
166
+ end
167
+
168
+ class HasConfigFactory
169
+ def initialize(dummy_formatter)
170
+ @dummy_formatter = dummy_formatter
171
+ end
172
+ attr_reader :obj, :optional
173
+ def new(obj, optional = {config: 'no'})
174
+ @obj = obj
175
+ @optional = optional
176
+ @dummy_formatter
177
+ end
178
+ end
179
+
180
+ no_config_factory = NoConfigFactory.new(double(:formatter, format: nil))
181
+ has_config_factory = HasConfigFactory.new(double(:formatter, format: nil))
182
+
183
+ expect(config).to receive(:formatters) { [NoConfigFormatter, HasConfigFormatter, no_config_factory, has_config_factory] }
184
+
185
+ ci_runner = Jasmine::CiRunner.new(config, thread: fake_thread, application_factory: application_factory, server_factory: server_factory, outputter: outputter)
186
+
187
+ ci_runner.run
188
+
189
+ expect(no_config_factory.optional).to eq({config: 'no'})
190
+ expect(has_config_factory.optional).to eq({config: 'no'})
191
+ expect(has_config_factory.obj).to eq(config)
192
+
193
+ expect(runner_factory).to have_received(:call).with(anything, anything) do |multi_formatter, url|
194
+ expect_any_instance_of(NoConfigFormatter).to receive(:format) do |formatter, results|
195
+ expect(formatter.optional).to eq({config: 'no'})
196
+ end
197
+
198
+ expect_any_instance_of(HasConfigFormatter).to receive(:format) do |formatter, results|
199
+ expect(formatter.optional).to eq({config: 'no'})
200
+ expect(formatter.obj).to eq(config)
201
+ end
202
+
203
+ multi_formatter.format([])
204
+ end
205
+ end
206
+
64
207
  it 'adds runner boot files when necessary' do
65
208
  expect(runner).to receive(:boot_js).at_least(:once) { 'foo/bar/baz.js' }
66
209
  expect(config).to receive(:runner_boot_dir=).with('foo/bar')
@@ -215,5 +215,18 @@ describe Jasmine::Configuration do
215
215
  config.runner.call('hi')
216
216
  end
217
217
  end
218
+
219
+ describe 'colorization settings' do
220
+ it 'defaults to color' do
221
+ config = Jasmine::Configuration.new
222
+ expect(config.color).to eq(true)
223
+ end
224
+
225
+ it 'can be set to false' do
226
+ config = Jasmine::Configuration.new
227
+ config.color = false
228
+ expect(config.color).to eq(false)
229
+ end
230
+ end
218
231
  end
219
232
 
@@ -4,10 +4,19 @@ require 'yaml'
4
4
  require 'jasmine/ruby_versions'
5
5
 
6
6
  if rails_available?
7
+ if !Bundler.respond_to?(:with_unbundled_env)
8
+ module Bundler
9
+ class << self
10
+ alias_method :with_unbundled_env, :with_clean_env
11
+ end
12
+ end
13
+ end
14
+
7
15
  describe 'A Rails app' do
8
16
  def bundle_install
9
- puts `NOKOGIRI_USE_SYSTEM_LIBRARIES=true bundle install --path vendor --retry 3;`
17
+ bundle_output = `NOKOGIRI_USE_SYSTEM_LIBRARIES=true bundle install`
10
18
  unless $?.success?
19
+ puts bundle_output
11
20
  raise "Bundle failed to install."
12
21
  end
13
22
  end
@@ -16,26 +25,35 @@ if rails_available?
16
25
  temp_dir_before
17
26
  Dir::chdir @tmp
18
27
 
19
- `rails new rails-example --skip-bundle --skip-active-record`
28
+ if rails_version == 'rails6'
29
+ `rails new rails-example --skip-bundle --skip-active-record --skip-bootsnap --skip-webpack-install --skip-javascript`
30
+ else
31
+ `rails new rails-example --skip-bundle --skip-active-record`
32
+ end
20
33
  Dir::chdir File.join(@tmp, 'rails-example')
21
34
 
22
35
  base = File.absolute_path(File.join(__FILE__, '../..'))
23
36
 
24
- # execjs v2.2.0 is broken in rbx, locking the version to 2.0.2 for now
25
- # see https://github.com/sstephenson/execjs/issues/148
26
-
27
37
  open('Gemfile', 'a') { |f|
28
38
  f.puts "gem 'jasmine', :path => '#{base}'"
29
- f.puts "gem 'jasmine-core', :git => 'http://github.com/jasmine/jasmine.git'"
30
- if RUBY_PLATFORM != 'java' && ENV['RAILS_VERSION'] != 'rails5'
39
+ f.puts "gem 'jasmine-core', :git => 'http://github.com/jasmine/jasmine.git', ref: 'main'"
40
+ if RUBY_PLATFORM != 'java' && rails_version == 'rails4'
31
41
  f.puts "gem 'thin'"
32
42
  end
33
- f.puts "gem 'angularjs-rails'"
34
- f.puts "gem 'execjs', '2.0.2'"
35
43
  f.flush
36
44
  }
37
45
 
38
- Bundler.with_clean_env do
46
+ FileUtils.mkdir_p('.bundle')
47
+ open('.bundle/config', 'a') do |f|
48
+ f.puts(<<~YAML)
49
+ ---
50
+ BUNDLE_PATH: "vendor"
51
+ BUNDLE_RETRY: "3"
52
+ YAML
53
+ f.flush
54
+ end
55
+
56
+ Bundler.with_unbundled_env do
39
57
  bundle_install
40
58
  `bundle exec rails g jasmine:install`
41
59
  expect($?).to eq 0
@@ -47,6 +65,19 @@ if rails_available?
47
65
  expect(File.exists?('spec/javascripts/jasmine_examples/PlayerSpec.js')).to eq true
48
66
  expect(File.exists?('spec/javascripts/helpers/jasmine_examples/SpecHelper.js')).to eq true
49
67
  end
68
+
69
+ if rails_version == 'rails6'
70
+ FileUtils.mkdir_p('app/assets/javascripts')
71
+ open('app/assets/javascripts/application.js', 'a') { |f|
72
+ f.puts '//= require_tree .'
73
+ f.flush
74
+ }
75
+ FileUtils.mkdir_p('app/assets/config')
76
+ open('app/assets/config/manifest.js', 'a') { |f|
77
+ f.puts '//= link_directory ../javascripts .js'
78
+ f.flush
79
+ }
80
+ end
50
81
  end
51
82
 
52
83
  after :all do
@@ -56,94 +87,75 @@ if rails_available?
56
87
  it 'should have the jasmine & jasmine:ci rake task' do
57
88
  #See https://github.com/jimweirich/rake/issues/220 and https://github.com/jruby/activerecord-jdbc-adapter/pull/467
58
89
  #There's a workaround, but requires setting env vars & jruby opts (non-trivial when inside of a jruby process), so skip for now.
59
- Bundler.with_clean_env do
90
+ Bundler.with_unbundled_env do
60
91
  output = `bundle exec rake -T`
61
92
  expect(output).to include('jasmine ')
62
93
  expect(output).to include('jasmine:ci')
63
94
  end
64
95
  end
65
96
 
66
- it "rake jasmine:ci runs and returns expected results" do
67
- Bundler.with_clean_env do
68
- output = `bundle exec rake jasmine:ci`
69
- expect(output).to include('5 specs, 0 failures')
97
+ context 'with angular mocks' do
98
+ before(:all) do
99
+ open('spec/javascripts/helpers/angular_helper.js', 'w') { |f|
100
+ f.puts "//= require angular-mocks"
101
+ f.flush
102
+ }
70
103
  end
71
- end
72
104
 
73
- it "rake jasmine:ci returns proper exit code when specs fail" do
74
- Bundler.with_clean_env do
75
- FileUtils.cp(File.join(@root, 'spec', 'fixture', 'failing_test.js'), File.join('spec', 'javascripts'))
76
- failing_yaml = custom_jasmine_config('failing') do |jasmine_config|
77
- jasmine_config['spec_files'] << 'failing_test.js'
78
- end
79
- output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{failing_yaml}`
80
- expect($?).to_not be_success
81
- expect(output).to include('6 specs, 1 failure')
105
+ after(:all) do
106
+ FileUtils.rm('spec/javascripts/helpers/angular_helper.js')
82
107
  end
83
- end
84
108
 
85
- it "rake jasmine:ci runs specs when an error occurs in the javascript" do
86
- Bundler.with_clean_env do
87
- FileUtils.cp(File.join(@root, 'spec', 'fixture', 'exception_test.js'), File.join('spec', 'javascripts'))
88
- exception_yaml = custom_jasmine_config('exception') do |jasmine_config|
89
- jasmine_config['spec_files'] << 'exception_test.js'
109
+ it "rake jasmine runs and serves the expected webpage when using asset pipeline" do
110
+ open('app/assets/stylesheets/foo.css', 'w') { |f|
111
+ f.puts "/* hi dere */"
112
+ f.flush
113
+ }
114
+
115
+ css_yaml = custom_jasmine_config('css') do |jasmine_config|
116
+ jasmine_config['src_files'] = %w[assets/application.js http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js]
117
+ jasmine_config['stylesheets'] = ['assets/application.css']
90
118
  end
91
- output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{exception_yaml}`
92
- expect($?).to_not be_success
93
- expect(output).to include('5 specs, 0 failures')
94
- end
95
- end
96
119
 
97
- it "runs specs written in coffeescript" do
98
- coffee_yaml = custom_jasmine_config('coffee') do |jasmine_config|
99
- jasmine_config['spec_files'] << 'coffee_spec.coffee'
100
- end
101
- FileUtils.cp(File.join(@root, 'spec', 'fixture', 'coffee_spec.coffee'), File.join('spec', 'javascripts'))
120
+ Bundler.with_unbundled_env do
121
+ `bundle add angularjs-rails`
122
+ end
123
+ run_jasmine_server("JASMINE_CONFIG_PATH=#{css_yaml}") do
124
+ output = Net::HTTP.get(URI.parse('http://localhost:8888/'))
125
+ if rails_version == 'rails6'
126
+ expect(output).to match(%r{script src.*/(assets/application.debug-[^\.]+\.js)})
127
+ expect(output).to match(%r{<link rel=.stylesheet.*?href=.*/assets/application.debug-[^\.]+\.css})
128
+ else
129
+ expect(output).to match(%r{script src.*/assets/jasmine_examples/Player(\.self-[^\.]+)?\.js})
130
+ expect(output).to match(%r{script src.*/assets/jasmine_examples/Song(\.self-[^\.]+)?\.js})
131
+ expect(output).to match(%r{script src.*angular_helper\.js})
132
+ expect(output).to match(%r{<link rel=.stylesheet.*?href=./assets/foo(\.self-[^\.]+)?\.css\?.*?>})
133
+ end
134
+ expect(output).to match(%r{script src=['"]http://ajax\.googleapis\.com/ajax/libs/jquery/1\.11\.0/jquery\.min\.js})
102
135
 
103
- Bundler.with_clean_env do
104
- output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{coffee_yaml}`
105
- expect(output).to include('6 specs, 0 failures')
136
+ output = Net::HTTP.get(URI.parse('http://localhost:8888/__spec__/helpers/angular_helper.js'))
137
+ expect(output).to match(/angular\.mock/)
138
+ end
106
139
  end
107
140
  end
108
141
 
109
- it "rake jasmine runs and serves the expected webpage when using asset pipeline" do
110
- open('app/assets/stylesheets/foo.css', 'w') { |f|
111
- f.puts "/* hi dere */"
112
- f.flush
113
- }
114
-
115
- open('spec/javascripts/helpers/angular_helper.js', 'w') { |f|
116
- f.puts "//= require angular-mocks"
117
- f.flush
118
- }
119
-
120
- css_yaml = custom_jasmine_config('css') do |jasmine_config|
121
- jasmine_config['src_files'] = %w[assets/application.js http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js]
122
- jasmine_config['stylesheets'] = ['assets/application.css']
142
+ context 'with an assets_prefix set' do
143
+ before(:all) do
144
+ open('app/assets/stylesheets/assets_prefix.js.erb', 'w') { |f|
145
+ f.puts "<%= assets_prefix %>"
146
+ f.flush
147
+ }
123
148
  end
124
149
 
125
- run_jasmine_server("JASMINE_CONFIG_PATH=#{css_yaml}") do
126
- output = Net::HTTP.get(URI.parse('http://localhost:8888/'))
127
- expect(output).to match(%r{script src.*/assets/jasmine_examples/Player(\.self-[^\.]+)?\.js})
128
- expect(output).to match(%r{script src=['"]http://ajax\.googleapis\.com/ajax/libs/jquery/1\.11\.0/jquery\.min\.js})
129
- expect(output).to match(%r{script src.*/assets/jasmine_examples/Song(\.self-[^\.]+)?\.js})
130
- expect(output).to match(%r{script src.*angular_helper\.js})
131
- expect(output).to match(%r{<link rel=.stylesheet.*?href=./assets/foo(\.self-[^\.]+)?\.css\?.*?>})
132
-
133
- output = Net::HTTP.get(URI.parse('http://localhost:8888/__spec__/helpers/angular_helper.js'))
134
- expect(output).to match(/angular\.mock/)
150
+ after(:all) do
151
+ FileUtils.rm('app/assets/stylesheets/assets_prefix.js.erb')
135
152
  end
136
- end
137
153
 
138
- it "sets assets_prefix when using sprockets" do
139
- open('app/assets/stylesheets/assets_prefix.js.erb', 'w') { |f|
140
- f.puts "<%= assets_prefix %>"
141
- f.flush
142
- }
143
-
144
- run_jasmine_server do
145
- output = Net::HTTP.get(URI.parse('http://localhost:8888/assets/assets_prefix.js'))
146
- expect(output).to match("/assets")
154
+ it "sets assets_prefix when using sprockets" do
155
+ run_jasmine_server do
156
+ output = Net::HTTP.get(URI.parse('http://localhost:8888/assets/assets_prefix.js'))
157
+ expect(output).to match("/assets")
158
+ end
147
159
  end
148
160
  end
149
161
 
@@ -156,7 +168,7 @@ if rails_available?
156
168
  FileUtils.cp(File.join(@root, 'spec', 'fixture', 'non_asset_pipeline.js'), File.join('public', 'javascripts'))
157
169
  FileUtils.cp(File.join(@root, 'spec', 'fixture', 'non_asset_pipeline_test.js'), File.join('spec', 'javascripts'))
158
170
 
159
- Bundler.with_clean_env do
171
+ Bundler.with_unbundled_env do
160
172
  output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{yaml}`
161
173
  expect(output).to include('1 spec, 0 failures')
162
174
  end
@@ -168,9 +180,9 @@ if rails_available?
168
180
  jasmine_config['rack_options'] = { 'server' => 'webrick' }
169
181
  end
170
182
 
171
- Bundler.with_clean_env do
183
+ Bundler.with_unbundled_env do
172
184
  default_output = `bundle exec rake jasmine:ci`
173
- if ENV['RAILS_VERSION'] == 'rails5' || ENV['RAILS_VERSION'].nil?
185
+ if rails_version == 'rails6' || rails_version == 'rails5' || rails_version.nil?
174
186
  expect(default_output).to include('Puma starting')
175
187
  else
176
188
  expect(default_output).to include('Thin web server')
@@ -181,55 +193,98 @@ if rails_available?
181
193
  end
182
194
  end
183
195
 
184
- describe 'using sprockets 4' do
185
- before :all do
186
- FileUtils.cp('Gemfile', 'Gemfile-old')
187
- FileUtils.rm 'Gemfile.lock'
196
+ if rails_version == 'rails6'
197
+ describe 'using sprockets 4' do
198
+ it "serves source mapped assets" do
199
+ run_jasmine_server do
200
+ output = Net::HTTP.get(URI.parse('http://localhost:8888/'))
188
201
 
189
- open('Gemfile', 'a') { |f|
190
- f.puts "gem 'sprockets', '~> 4.0.0.beta6'"
191
- f.flush
192
- }
193
- Bundler.with_clean_env do
194
- bundle_install
202
+ js_match = output.match %r{script src.*/(assets/application.debug-[^\.]+\.js)}
203
+ expect(js_match).to_not be_nil
204
+
205
+ js_path = js_match[1]
206
+ output = Net::HTTP.get(URI.parse("http://localhost:8888/#{js_path}"))
207
+ expect(output).to match(%r{//# sourceMappingURL=.*\.map})
208
+ end
195
209
  end
210
+ end
211
+ end
196
212
 
197
- FileUtils.mkdir_p('app/assets/config')
213
+ shared_examples_for 'a working jasmine:ci' do
214
+ it "rake jasmine:ci runs and returns expected results" do
215
+ Bundler.with_unbundled_env do
216
+ output = `bundle exec rake jasmine:ci`
217
+ expect(output).to include('5 specs, 0 failures')
218
+ expect($?).to be_success
219
+ end
220
+ end
198
221
 
199
- open('app/assets/config/manifest.js', 'w') { |f|
200
- f.puts "//= link application.js"
201
- f.puts "//= link application.css"
202
- f.flush
203
- }
222
+ it "rake jasmine:ci returns proper exit code when specs fail" do
223
+ Bundler.with_unbundled_env do
224
+ FileUtils.cp(File.join(@root, 'spec', 'fixture', 'failing_test.js'), File.join('spec', 'javascripts'))
225
+ failing_yaml = custom_jasmine_config('failing') do |jasmine_config|
226
+ jasmine_config['spec_files'] << 'failing_test.js'
227
+ end
228
+ output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{failing_yaml}`
229
+ expect($?).to_not be_success
230
+ expect(output).to include('6 specs, 1 failure')
231
+ end
204
232
  end
205
233
 
206
- after :all do
207
- FileUtils.mv 'Gemfile-old', 'Gemfile'
208
- FileUtils.rm 'Gemfile.lock'
209
- FileUtils.rm 'app/assets/config/manifest.js'
210
- Bundler.with_clean_env do
211
- bundle_install
234
+ it "rake jasmine:ci runs specs when an error occurs in the javascript" do
235
+ Bundler.with_unbundled_env do
236
+ FileUtils.cp(File.join(@root, 'spec', 'fixture', 'exception_test.js'), File.join('spec', 'javascripts'))
237
+ exception_yaml = custom_jasmine_config('exception') do |jasmine_config|
238
+ jasmine_config['spec_files'] << 'exception_test.js'
239
+ end
240
+ output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{exception_yaml}`
241
+ expect($?).to_not be_success
242
+ expect(output).to include('5 specs, 0 failures')
212
243
  end
213
244
  end
214
245
 
215
- it "serves source mapped assets" do
216
- run_jasmine_server do
217
- output = Net::HTTP.get(URI.parse('http://localhost:8888/'))
246
+ unless rails_version == 'rails6'
247
+ it "runs specs written in coffeescript" do
248
+ coffee_yaml = custom_jasmine_config('coffee') do |jasmine_config|
249
+ jasmine_config['spec_files'] << 'coffee_spec.coffee'
250
+ end
251
+ FileUtils.cp(File.join(@root, 'spec', 'fixture', 'coffee_spec.coffee'), File.join('spec', 'javascripts'))
218
252
 
219
- js_match = output.match %r{script src.*/(assets/application.debug-[^\.]+\.js)}
253
+ Bundler.with_unbundled_env do
254
+ output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{coffee_yaml}`
255
+ expect(output).to include('6 specs, 0 failures')
256
+ expect($?).to be_success
257
+ end
258
+ end
259
+ end
260
+ end
220
261
 
221
- expect(js_match).to_not be_nil
222
- expect(output).to match(%r{<link rel=.stylesheet.*?href=.*/assets/application.debug-[^\.]+\.css})
262
+ describe "with phantomJS" do
263
+ it_behaves_like 'a working jasmine:ci'
264
+ end
223
265
 
224
- js_path = js_match[1]
225
- output = Net::HTTP.get(URI.parse("http://localhost:8888/#{js_path}"))
226
- expect(output).to match(%r{//# sourceMappingURL=.*\.map})
266
+ describe "with Chrome headless" do
267
+ before :all do
268
+ open('spec/javascripts/support/jasmine_helper.rb', 'w') { |f|
269
+ f.puts "Jasmine.configure do |config|\n config.runner_browser = :chromeheadless\nend\n"
270
+ f.flush
271
+ }
272
+ Bundler.with_unbundled_env do
273
+ `bundle add chrome_remote`
227
274
  end
228
275
  end
276
+
277
+ after :all do
278
+ Bundler.with_unbundled_env do
279
+ `bundle remove chrome_remote`
280
+ end
281
+ end
282
+
283
+ it_behaves_like 'a working jasmine:ci'
229
284
  end
230
285
 
231
286
  def run_jasmine_server(options = "")
232
- Bundler.with_clean_env do
287
+ Bundler.with_unbundled_env do
233
288
  begin
234
289
  pid = IO.popen("bundle exec rake jasmine #{options}").pid
235
290
  Jasmine::wait_for_listener(8888, 'localhost', 60)