@@ -49,7 +49,7 @@ def bundle_install
4949 ---
5050 BUNDLE_PATH: "vendor"
5151 BUNDLE_RETRY: "3"
52- YAML
52+ YAML
5353 f . flush
5454 end
5555
@@ -94,6 +94,122 @@ def bundle_install
9494 end
9595 end
9696
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+ }
103+ end
104+
105+ after ( :all ) do
106+ FileUtils . rm ( 'spec/javascripts/helpers/angular_helper.js' )
107+ end
108+
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' ]
118+ end
119+
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} )
135+
136+ output = Net ::HTTP . get ( URI . parse ( 'http://localhost:8888/__spec__/helpers/angular_helper.js' ) )
137+ expect ( output ) . to match ( /angular\. mock/ )
138+ end
139+ end
140+ end
141+
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+ }
148+ end
149+
150+ after ( :all ) do
151+ FileUtils . rm ( 'app/assets/stylesheets/assets_prefix.js.erb' )
152+ end
153+
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
159+ end
160+ end
161+
162+ it "should load js files outside of the assets path too" do
163+ yaml = custom_jasmine_config ( 'public-assets' ) do |jasmine_config |
164+ jasmine_config [ 'src_files' ] << 'public/javascripts/**/*.js'
165+ jasmine_config [ 'spec_files' ] = [ 'non_asset_pipeline_test.js' ]
166+ end
167+ FileUtils . mkdir_p ( File . join ( 'public' , 'javascripts' ) )
168+ FileUtils . cp ( File . join ( @root , 'spec' , 'fixture' , 'non_asset_pipeline.js' ) , File . join ( 'public' , 'javascripts' ) )
169+ FileUtils . cp ( File . join ( @root , 'spec' , 'fixture' , 'non_asset_pipeline_test.js' ) , File . join ( 'spec' , 'javascripts' ) )
170+
171+ Bundler . with_unbundled_env do
172+ output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{ yaml } `
173+ expect ( output ) . to include ( '1 spec, 0 failures' )
174+ end
175+ end
176+
177+ it "should pass custom rack options from jasmine.yml" do
178+ pending "we're testing this with thin, which doesn't work in jruby" if RUBY_PLATFORM == 'java'
179+ rack_yaml = custom_jasmine_config ( 'custom_rack' ) do |jasmine_config |
180+ jasmine_config [ 'rack_options' ] = { 'server' => 'webrick' }
181+ end
182+
183+ Bundler . with_unbundled_env do
184+ default_output = `bundle exec rake jasmine:ci`
185+ if rails_version == 'rails6' || rails_version == 'rails5' || rails_version . nil?
186+ expect ( default_output ) . to include ( 'Puma starting' )
187+ else
188+ expect ( default_output ) . to include ( 'Thin web server' )
189+ end
190+
191+ custom_output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{ rack_yaml } 2>&1`
192+ expect ( custom_output ) . to include ( "WEBrick" )
193+ end
194+ end
195+
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/' ) )
201+
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
209+ end
210+ end
211+ end
212+
97213 describe "with phantomJS" do
98214 it "rake jasmine:ci runs and returns expected results" do
99215 Bundler . with_unbundled_env do
@@ -139,157 +255,6 @@ def bundle_install
139255 end
140256 end
141257 end
142-
143- context 'with angular mocks' do
144- before ( :all ) do
145- open ( 'spec/javascripts/helpers/angular_helper.js' , 'w' ) { |f |
146- f . puts "//= require angular-mocks"
147- f . flush
148- }
149- end
150-
151- after ( :all ) do
152- FileUtils . rm ( 'spec/javascripts/helpers/angular_helper.js' )
153- end
154-
155- it "rake jasmine runs and serves the expected webpage when using asset pipeline" do
156- open ( 'app/assets/stylesheets/foo.css' , 'w' ) { |f |
157- f . puts "/* hi dere */"
158- f . flush
159- }
160-
161- css_yaml = custom_jasmine_config ( 'css' ) do |jasmine_config |
162- jasmine_config [ 'src_files' ] = %w[ assets/application.js http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js ]
163- jasmine_config [ 'stylesheets' ] = [ 'assets/application.css' ]
164- end
165-
166- Bundler . with_unbundled_env do
167- `bundle add angularjs-rails`
168- end
169- run_jasmine_server ( "JASMINE_CONFIG_PATH=#{ css_yaml } " ) do
170- output = Net ::HTTP . get ( URI . parse ( 'http://localhost:8888/' ) )
171- unless rails_version == 'rails6'
172- expect ( output ) . to match ( %r{script src.*/assets/jasmine_examples/Player(\. self-[^\. ]+)?\. js} )
173- expect ( output ) . to match ( %r{script src.*/assets/jasmine_examples/Song(\. self-[^\. ]+)?\. js} )
174- expect ( output ) . to match ( %r{script src.*angular_helper\. js} )
175- expect ( output ) . to match ( %r{<link rel=.stylesheet.*?href=./assets/foo(\. self-[^\. ]+)?\. css\? .*?>} )
176- end
177- expect ( output ) . to match ( %r{script src=['"]http://ajax\. googleapis\. com/ajax/libs/jquery/1\. 11\. 0/jquery\. min\. js} )
178-
179- output = Net ::HTTP . get ( URI . parse ( 'http://localhost:8888/__spec__/helpers/angular_helper.js' ) )
180- expect ( output ) . to match ( /angular\. mock/ )
181- end
182- end
183- end
184-
185- context 'with an assets_prefix set' do
186- before ( :all ) do
187- open ( 'app/assets/stylesheets/assets_prefix.js.erb' , 'w' ) { |f |
188- f . puts "<%= assets_prefix %>"
189- f . flush
190- }
191- end
192-
193- after ( :all ) do
194- FileUtils . rm ( 'app/assets/stylesheets/assets_prefix.js.erb' )
195- end
196-
197- it "sets assets_prefix when using sprockets" do
198- run_jasmine_server do
199- output = Net ::HTTP . get ( URI . parse ( 'http://localhost:8888/assets/assets_prefix.js' ) )
200- expect ( output ) . to match ( "/assets" )
201- end
202- end
203- end
204-
205- it "should load js files outside of the assets path too" do
206- yaml = custom_jasmine_config ( 'public-assets' ) do |jasmine_config |
207- jasmine_config [ 'src_files' ] << 'public/javascripts/**/*.js'
208- jasmine_config [ 'spec_files' ] = [ 'non_asset_pipeline_test.js' ]
209- end
210- FileUtils . mkdir_p ( File . join ( 'public' , 'javascripts' ) )
211- FileUtils . cp ( File . join ( @root , 'spec' , 'fixture' , 'non_asset_pipeline.js' ) , File . join ( 'public' , 'javascripts' ) )
212- FileUtils . cp ( File . join ( @root , 'spec' , 'fixture' , 'non_asset_pipeline_test.js' ) , File . join ( 'spec' , 'javascripts' ) )
213-
214- Bundler . with_unbundled_env do
215- output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{ yaml } `
216- expect ( output ) . to include ( '1 spec, 0 failures' )
217- end
218- end
219-
220- it "should pass custom rack options from jasmine.yml" do
221- pending "we're testing this with thin, which doesn't work in jruby" if RUBY_PLATFORM == 'java'
222- rack_yaml = custom_jasmine_config ( 'custom_rack' ) do |jasmine_config |
223- jasmine_config [ 'rack_options' ] = { 'server' => 'webrick' }
224- end
225-
226- Bundler . with_unbundled_env do
227- default_output = `bundle exec rake jasmine:ci`
228- if rails_version == 'rails6' || rails_version == 'rails5' || rails_version . nil?
229- expect ( default_output ) . to include ( 'Puma starting' )
230- else
231- expect ( default_output ) . to include ( 'Thin web server' )
232- end
233-
234- custom_output = `bundle exec rake jasmine:ci JASMINE_CONFIG_PATH=#{ rack_yaml } 2>&1`
235- expect ( custom_output ) . to include ( "WEBrick" )
236- end
237- end
238-
239- if ruby_at_least? ( '2.5' )
240- describe 'using sprockets 4' do
241- before :all do
242- FileUtils . cp ( 'Gemfile' , 'Gemfile-old' )
243- FileUtils . rm 'Gemfile.lock'
244-
245- open ( 'Gemfile' , 'a' ) { |f |
246- f . puts "gem 'sprockets', '~> 4.0.0'"
247- f . flush
248- }
249- Bundler . with_unbundled_env do
250- bundle_install
251- end
252-
253- FileUtils . mkdir_p ( 'app/assets/config' )
254-
255- if File . exists? ( 'app/assets/config/manifest.js' )
256- FileUtils . move ( 'app/assets/config/manifest.js' , 'app/assets/config/manifest_orig.js' )
257- end
258- open ( 'app/assets/config/manifest.js' , 'w' ) { |f |
259- f . puts "//= link application.js"
260- f . puts "//= link application.css"
261- f . flush
262- }
263- end
264-
265- after :all do
266- FileUtils . mv 'Gemfile-old' , 'Gemfile'
267- FileUtils . rm 'Gemfile.lock'
268- FileUtils . rm 'app/assets/config/manifest.js'
269- if File . exists? ( 'app/assets/config/manifest_orig.js' )
270- FileUtils . move ( 'app/assets/config/manifest_orig.js' , 'app/assets/config/manifest.js' )
271- end
272- Bundler . with_unbundled_env do
273- bundle_install
274- end
275- end
276-
277- it "serves source mapped assets" do
278- run_jasmine_server do
279- output = Net ::HTTP . get ( URI . parse ( 'http://localhost:8888/' ) )
280-
281- js_match = output . match %r{script src.*/(assets/application.debug-[^\. ]+\. js)}
282-
283- expect ( js_match ) . to_not be_nil
284- expect ( output ) . to match ( %r{<link rel=.stylesheet.*?href=.*/assets/application.debug-[^\. ]+\. css} )
285-
286- js_path = js_match [ 1 ]
287- output = Net ::HTTP . get ( URI . parse ( "http://localhost:8888/#{ js_path } " ) )
288- expect ( output ) . to match ( %r{//# sourceMappingURL=.*\. map} )
289- end
290- end
291- end
292- end
293258 end
294259
295260 describe "with Chrome headless" do
0 commit comments