jekyll-minibundle 3.0.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +78 -66
- data/README.md +117 -101
- data/Rakefile +8 -26
- data/jekyll-minibundle.gemspec +5 -11
- data/lib/jekyll/minibundle/asset_bundle.rb +1 -1
- data/lib/jekyll/minibundle/asset_file_drop.rb +1 -3
- data/lib/jekyll/minibundle/asset_file_registry.rb +2 -2
- data/lib/jekyll/minibundle/asset_tag_markup.rb +1 -1
- data/lib/jekyll/minibundle/bundle_file.rb +3 -0
- data/lib/jekyll/minibundle/development_file.rb +2 -0
- data/lib/jekyll/minibundle/hashes.rb +1 -3
- data/lib/jekyll/minibundle/stamp_file.rb +3 -0
- data/lib/jekyll/minibundle/variable_template.rb +3 -1
- data/lib/jekyll/minibundle/variable_template_registry.rb +2 -2
- data/lib/jekyll/minibundle/version.rb +1 -1
- metadata +8 -184
- data/test/fixture/site/_assets/scripts/app.js +0 -5
- data/test/fixture/site/_assets/scripts/dependency.js +0 -4
- data/test/fixture/site/_assets/styles/common.css +0 -2
- data/test/fixture/site/_assets/styles/reset.css +0 -2
- data/test/fixture/site/_bin/remove_comments +0 -4
- data/test/fixture/site/_bin/with_count +0 -15
- data/test/fixture/site/_config.yml +0 -3
- data/test/fixture/site/_layouts/default.html +0 -29
- data/test/fixture/site/_tmp/site.css +0 -3
- data/test/fixture/site/about.html +0 -4
- data/test/fixture/site/assets/site.css +0 -2
- data/test/fixture/site/index.html +0 -4
- data/test/integration/minibundle_development_mode_test.rb +0 -554
- data/test/integration/minibundle_production_mode_test.rb +0 -900
- data/test/integration/ministamp_development_mode_test.rb +0 -235
- data/test/integration/ministamp_production_mode_test.rb +0 -342
- data/test/integration/static_files_as_asset_sources_test.rb +0 -75
- data/test/support/assertions.rb +0 -26
- data/test/support/fixture_config.rb +0 -20
- data/test/support/static_file_config.rb +0 -23
- data/test/support/test_case.rb +0 -175
- data/test/unit/asset_bundle_test.rb +0 -57
- data/test/unit/asset_file_drop_test.rb +0 -66
- data/test/unit/asset_file_registry_test.rb +0 -237
- data/test/unit/asset_tag_markup_test.rb +0 -46
- data/test/unit/bundle_file_properties_test.rb +0 -108
- data/test/unit/bundle_file_writing_test.rb +0 -155
- data/test/unit/development_file_properties_test.rb +0 -97
- data/test/unit/development_file_writing_test.rb +0 -50
- data/test/unit/environment_test.rb +0 -29
- data/test/unit/files_test.rb +0 -61
- data/test/unit/hashes_test.rb +0 -43
- data/test/unit/jekyll_static_file_api_test.rb +0 -172
- data/test/unit/mini_bundle_block_test.rb +0 -125
- data/test/unit/mini_stamp_tag_test.rb +0 -64
- data/test/unit/stamp_file_properties_test.rb +0 -98
- data/test/unit/stamp_file_writing_test.rb +0 -130
- data/test/unit/variable_template_test.rb +0 -121
|
@@ -1,900 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
require 'digest/md5'
|
|
6
|
-
|
|
7
|
-
module Jekyll::Minibundle::Test
|
|
8
|
-
class MinibundleProductionModeTest < TestCase
|
|
9
|
-
include FixtureConfig
|
|
10
|
-
|
|
11
|
-
def test_css_asset_bundle_has_stamp
|
|
12
|
-
with_precompiled_site(:production) do
|
|
13
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_js_asset_bundle_has_stamp
|
|
18
|
-
with_precompiled_site(:production) do
|
|
19
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_css_asset_bundle_has_configured_attributes
|
|
24
|
-
with_precompiled_site(:production) do
|
|
25
|
-
element = find_css_element_from_index
|
|
26
|
-
assert_equal('my-styles', element['id'])
|
|
27
|
-
assert_equal('projection', element['media'])
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_js_asset_bundle_has_configured_attributes
|
|
32
|
-
with_precompiled_site(:production) do
|
|
33
|
-
element = find_js_element_from_index
|
|
34
|
-
assert_equal('my-scripts', element['id'])
|
|
35
|
-
assert_equal('', element['async'])
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_copies_css_asset_bundle_to_destination_dir
|
|
40
|
-
with_precompiled_site(:production) do
|
|
41
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_copies_js_asset_bundle_to_destination_dir
|
|
46
|
-
with_precompiled_site(:production) do
|
|
47
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_concatenates_css_asset_bundle_in_configured_order
|
|
52
|
-
with_precompiled_site(:production) do
|
|
53
|
-
bundle = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
54
|
-
assert_operator(bundle.index('html { margin: 0; }'), :<, bundle.index('p { margin: 0; }'))
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_concatenates_js_asset_bundle_in_configured_order
|
|
59
|
-
with_precompiled_site(:production) do
|
|
60
|
-
bundle = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
61
|
-
assert_operator(bundle.index('root.dependency = {};'), :<, bundle.index('root.app = {};'))
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_inserts_semicolons_between_js_assets
|
|
66
|
-
with_precompiled_site(:production) do
|
|
67
|
-
bundle = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
68
|
-
assert_match(/}\)\(window\)\n;\n\(function/, bundle)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_minifies_css_asset_bundle
|
|
73
|
-
with_precompiled_site(:production) do
|
|
74
|
-
source_contents_size = source_assets_size(CSS_BUNDLE_SOURCE_DIR, %w[reset common], 'css')
|
|
75
|
-
destination_contents_size = File.read(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
|
|
76
|
-
assert_operator(destination_contents_size, :<, source_contents_size)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_minifies_js_asset_bundle
|
|
81
|
-
with_precompiled_site(:production) do
|
|
82
|
-
source_contents_size = source_assets_size(JS_BUNDLE_SOURCE_DIR, %w[dependency app], 'js')
|
|
83
|
-
destination_contents_size = File.read(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)).size
|
|
84
|
-
assert_operator(destination_contents_size, :<, source_contents_size)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_changing_asset_source_file_rewrites_destination
|
|
89
|
-
with_site_dir do
|
|
90
|
-
generate_site(:production)
|
|
91
|
-
|
|
92
|
-
ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'app.js'), '(function() {})()') }
|
|
93
|
-
|
|
94
|
-
generate_site(:production, clear_cache: false)
|
|
95
|
-
|
|
96
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
97
|
-
|
|
98
|
-
new_destination = 'assets/site-375a0b430b0c5555d0edd2205d26c04d.js'
|
|
99
|
-
|
|
100
|
-
assert_equal(new_destination, find_js_path_from_index)
|
|
101
|
-
assert(File.file?(destination_path(new_destination)))
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_touching_asset_source_file_rewrites_destination
|
|
106
|
-
with_site_dir do
|
|
107
|
-
generate_site(:production)
|
|
108
|
-
|
|
109
|
-
org_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
110
|
-
ensure_file_mtime_changes { FileUtils.touch(source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')) }
|
|
111
|
-
|
|
112
|
-
generate_site(:production, clear_cache: false)
|
|
113
|
-
|
|
114
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
115
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
116
|
-
assert_operator(file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)), :>, org_mtime)
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
def test_changing_asset_source_directory_rewrites_destination
|
|
121
|
-
with_site_dir do
|
|
122
|
-
generate_site(:production)
|
|
123
|
-
|
|
124
|
-
org_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
125
|
-
|
|
126
|
-
match_snippet = <<-LIQUID
|
|
127
|
-
{% minibundle js %}
|
|
128
|
-
source_dir: _assets/scripts
|
|
129
|
-
LIQUID
|
|
130
|
-
|
|
131
|
-
replacement_snippet = <<-LIQUID
|
|
132
|
-
{% minibundle js %}
|
|
133
|
-
source_dir: _assets/scripts2
|
|
134
|
-
LIQUID
|
|
135
|
-
|
|
136
|
-
ensure_file_mtime_changes do
|
|
137
|
-
FileUtils.mv(source_path('_assets/scripts'), source_path('_assets/scripts2'))
|
|
138
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
generate_site(:production, clear_cache: false)
|
|
142
|
-
|
|
143
|
-
new_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH))
|
|
144
|
-
|
|
145
|
-
assert_operator(new_mtime, :>, org_mtime)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def test_changing_asset_source_list_rewrites_destination
|
|
150
|
-
with_site_dir do
|
|
151
|
-
generate_site(:production)
|
|
152
|
-
|
|
153
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
154
|
-
|
|
155
|
-
match_snippet = <<-YAML
|
|
156
|
-
assets:
|
|
157
|
-
- dependency
|
|
158
|
-
- app
|
|
159
|
-
YAML
|
|
160
|
-
|
|
161
|
-
replacement_snippet = <<-YAML
|
|
162
|
-
assets:
|
|
163
|
-
- dependency
|
|
164
|
-
YAML
|
|
165
|
-
|
|
166
|
-
ensure_file_mtime_changes do
|
|
167
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
generate_site(:production, clear_cache: false)
|
|
171
|
-
|
|
172
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
173
|
-
|
|
174
|
-
new_destination = 'assets/site-71042d0b7c86c04e015fde694dd9f409.js'
|
|
175
|
-
|
|
176
|
-
assert_equal(new_destination, find_js_path_from_index)
|
|
177
|
-
assert(File.file?(destination_path(new_destination)))
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def test_changing_asset_source_list_removes_old_temporary_bundle_file
|
|
182
|
-
with_site_dir do
|
|
183
|
-
other_tempfiles = find_tempfiles('*.js')
|
|
184
|
-
|
|
185
|
-
generate_site(:production)
|
|
186
|
-
|
|
187
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
188
|
-
|
|
189
|
-
match_snippet = <<-YAML
|
|
190
|
-
assets:
|
|
191
|
-
- dependency
|
|
192
|
-
- app
|
|
193
|
-
YAML
|
|
194
|
-
|
|
195
|
-
replacement_snippet = <<-YAML
|
|
196
|
-
assets:
|
|
197
|
-
- dependency
|
|
198
|
-
YAML
|
|
199
|
-
|
|
200
|
-
old_tempfiles = find_tempfiles('*.js') - other_tempfiles
|
|
201
|
-
|
|
202
|
-
ensure_file_mtime_changes do
|
|
203
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
generate_site(:production, clear_cache: false)
|
|
207
|
-
|
|
208
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
209
|
-
assert(File.file?(destination_path('assets/site-71042d0b7c86c04e015fde694dd9f409.js')))
|
|
210
|
-
assert((find_tempfiles('*.js') & old_tempfiles).empty?)
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def test_changing_asset_destination_path_rewrites_destination
|
|
215
|
-
with_site_dir do
|
|
216
|
-
generate_site(:production)
|
|
217
|
-
|
|
218
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
219
|
-
|
|
220
|
-
ensure_file_mtime_changes do
|
|
221
|
-
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
generate_site(:production, clear_cache: false)
|
|
225
|
-
|
|
226
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
227
|
-
|
|
228
|
-
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
|
229
|
-
|
|
230
|
-
assert_equal(new_destination, find_js_path_from_index)
|
|
231
|
-
assert(File.file?(destination_path(new_destination)))
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def test_changing_asset_destination_path_removes_old_temporary_bundle_file
|
|
236
|
-
with_site_dir do
|
|
237
|
-
other_tempfiles = find_tempfiles('*.js')
|
|
238
|
-
|
|
239
|
-
generate_site(:production)
|
|
240
|
-
|
|
241
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
242
|
-
|
|
243
|
-
old_tempfiles = find_tempfiles('*.js') - other_tempfiles
|
|
244
|
-
|
|
245
|
-
ensure_file_mtime_changes do
|
|
246
|
-
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
generate_site(:production, clear_cache: false)
|
|
250
|
-
|
|
251
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
252
|
-
assert(File.file?(destination_path("assets/site2-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
253
|
-
assert((find_tempfiles('*.js') & old_tempfiles).empty?)
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
|
258
|
-
with_site_dir do
|
|
259
|
-
generate_site(:production)
|
|
260
|
-
|
|
261
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
262
|
-
|
|
263
|
-
ensure_file_mtime_changes do
|
|
264
|
-
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
generate_site(:production, clear_cache: false)
|
|
268
|
-
|
|
269
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
270
|
-
|
|
271
|
-
new_destination = "assets/site2-#{JS_BUNDLE_FINGERPRINT}.js"
|
|
272
|
-
|
|
273
|
-
assert_equal(new_destination, find_js_path_from_index)
|
|
274
|
-
assert(File.file?(destination_path(new_destination)))
|
|
275
|
-
|
|
276
|
-
ensure_file_mtime_changes do
|
|
277
|
-
change_destination_path_in_minibundle_block('assets/site2', 'assets/site')
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
generate_site(:production, clear_cache: false)
|
|
281
|
-
|
|
282
|
-
refute(File.file?(destination_path(new_destination)))
|
|
283
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
284
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def test_changing_minifier_cmd_rewrites_destination
|
|
289
|
-
with_site_dir do
|
|
290
|
-
generate_site(:production)
|
|
291
|
-
|
|
292
|
-
assert_equal(0, get_minifier_cmd_count)
|
|
293
|
-
destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
294
|
-
org_mtime = file_mtime_of(destination)
|
|
295
|
-
|
|
296
|
-
match_snippet = <<-LIQUID
|
|
297
|
-
{% minibundle js %}
|
|
298
|
-
LIQUID
|
|
299
|
-
|
|
300
|
-
replacement_snippet = <<-LIQUID
|
|
301
|
-
{% minibundle js %}
|
|
302
|
-
minifier_cmd: #{minifier_cmd_to_remove_comments_and_count}
|
|
303
|
-
LIQUID
|
|
304
|
-
|
|
305
|
-
ensure_file_mtime_changes do
|
|
306
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
307
|
-
end
|
|
308
|
-
|
|
309
|
-
generate_site(:production, clear_cache: false)
|
|
310
|
-
|
|
311
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
312
|
-
assert_operator(file_mtime_of(destination), :>, org_mtime)
|
|
313
|
-
end
|
|
314
|
-
end
|
|
315
|
-
|
|
316
|
-
def test_supports_relative_and_absolute_destination_paths
|
|
317
|
-
with_site_dir do
|
|
318
|
-
generate_site(:production)
|
|
319
|
-
|
|
320
|
-
destination_css = destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
321
|
-
destination_js = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
322
|
-
org_mtime_css = file_mtime_of(destination_css)
|
|
323
|
-
org_mtime_js = file_mtime_of(destination_js)
|
|
324
|
-
|
|
325
|
-
assert(File.file?(destination_css))
|
|
326
|
-
assert(File.file?(destination_js))
|
|
327
|
-
|
|
328
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
329
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
330
|
-
|
|
331
|
-
ensure_file_mtime_changes do
|
|
332
|
-
find_and_gsub_in_file(
|
|
333
|
-
source_path('_layouts/default.html'),
|
|
334
|
-
'destination_path: assets/site',
|
|
335
|
-
'destination_path: /assets/site'
|
|
336
|
-
)
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
generate_site(:production, clear_cache: false)
|
|
340
|
-
|
|
341
|
-
assert(File.file?(destination_css))
|
|
342
|
-
assert(File.file?(destination_js))
|
|
343
|
-
assert_equal(org_mtime_css, file_mtime_of(destination_css))
|
|
344
|
-
assert_equal(org_mtime_js, file_mtime_of(destination_js))
|
|
345
|
-
assert_equal("/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index)
|
|
346
|
-
assert_equal("/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
|
347
|
-
end
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
def test_supports_baseurl
|
|
351
|
-
with_site_dir do
|
|
352
|
-
merge_to_yaml_file(source_path('_config.yml'), 'baseurl' => '/root')
|
|
353
|
-
|
|
354
|
-
find_and_gsub_in_file(
|
|
355
|
-
source_path('_layouts/default.html'),
|
|
356
|
-
' {% minibundle css %}',
|
|
357
|
-
<<-LIQUID
|
|
358
|
-
{% minibundle css %}
|
|
359
|
-
baseurl: '{{ site.baseurl }}/'
|
|
360
|
-
LIQUID
|
|
361
|
-
)
|
|
362
|
-
|
|
363
|
-
find_and_gsub_in_file(
|
|
364
|
-
source_path('_layouts/default.html'),
|
|
365
|
-
' {% minibundle js %}',
|
|
366
|
-
<<-LIQUID
|
|
367
|
-
{% minibundle js %}
|
|
368
|
-
baseurl: {{ site.baseurl }}/js
|
|
369
|
-
LIQUID
|
|
370
|
-
)
|
|
371
|
-
|
|
372
|
-
generate_site(:production)
|
|
373
|
-
|
|
374
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
375
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
376
|
-
|
|
377
|
-
assert_equal("/root/#{CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_css_path_from_index)
|
|
378
|
-
assert_equal("/root/js/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
|
379
|
-
end
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
def test_strips_dot_slash_from_dot_baseurl
|
|
383
|
-
with_site_dir do
|
|
384
|
-
find_and_gsub_in_file(
|
|
385
|
-
source_path('_layouts/default.html'),
|
|
386
|
-
' {% minibundle css %}',
|
|
387
|
-
<<-LIQUID
|
|
388
|
-
{% minibundle css %}
|
|
389
|
-
baseurl: .
|
|
390
|
-
LIQUID
|
|
391
|
-
)
|
|
392
|
-
|
|
393
|
-
find_and_gsub_in_file(
|
|
394
|
-
source_path('_layouts/default.html'),
|
|
395
|
-
' {% minibundle js %}',
|
|
396
|
-
<<-LIQUID
|
|
397
|
-
{% minibundle js %}
|
|
398
|
-
baseurl: .
|
|
399
|
-
LIQUID
|
|
400
|
-
)
|
|
401
|
-
|
|
402
|
-
generate_site(:production)
|
|
403
|
-
|
|
404
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
405
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
406
|
-
|
|
407
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
408
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
409
|
-
|
|
410
|
-
generate_site(:production, clear_cache: false)
|
|
411
|
-
|
|
412
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
413
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
414
|
-
|
|
415
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
416
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
417
|
-
end
|
|
418
|
-
end
|
|
419
|
-
|
|
420
|
-
def test_strips_dot_slash_from_dot_slash_baseurl
|
|
421
|
-
with_site_dir do
|
|
422
|
-
find_and_gsub_in_file(
|
|
423
|
-
source_path('_layouts/default.html'),
|
|
424
|
-
' {% minibundle css %}',
|
|
425
|
-
<<-LIQUID
|
|
426
|
-
{% minibundle css %}
|
|
427
|
-
baseurl: ./
|
|
428
|
-
LIQUID
|
|
429
|
-
)
|
|
430
|
-
|
|
431
|
-
find_and_gsub_in_file(
|
|
432
|
-
source_path('_layouts/default.html'),
|
|
433
|
-
' {% minibundle js %}',
|
|
434
|
-
<<-LIQUID
|
|
435
|
-
{% minibundle js %}
|
|
436
|
-
baseurl: ./
|
|
437
|
-
LIQUID
|
|
438
|
-
)
|
|
439
|
-
|
|
440
|
-
generate_site(:production)
|
|
441
|
-
|
|
442
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
443
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
444
|
-
|
|
445
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
446
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
447
|
-
|
|
448
|
-
generate_site(:production, clear_cache: false)
|
|
449
|
-
|
|
450
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
451
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
452
|
-
|
|
453
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
454
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
def test_strips_dot_slash_from_relative_destination_path
|
|
459
|
-
with_site_dir do
|
|
460
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: site')
|
|
461
|
-
|
|
462
|
-
generate_site(:production)
|
|
463
|
-
|
|
464
|
-
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
|
465
|
-
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
466
|
-
|
|
467
|
-
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
|
468
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
469
|
-
|
|
470
|
-
generate_site(:production, clear_cache: false)
|
|
471
|
-
|
|
472
|
-
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
|
473
|
-
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
474
|
-
|
|
475
|
-
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
|
476
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
477
|
-
end
|
|
478
|
-
end
|
|
479
|
-
|
|
480
|
-
def test_strips_dot_slash_from_dot_slash_destination_path
|
|
481
|
-
with_site_dir do
|
|
482
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'destination_path: assets/site', 'destination_path: ./site')
|
|
483
|
-
|
|
484
|
-
generate_site(:production)
|
|
485
|
-
|
|
486
|
-
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
|
487
|
-
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
488
|
-
|
|
489
|
-
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
|
490
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
491
|
-
|
|
492
|
-
generate_site(:production, clear_cache: false)
|
|
493
|
-
|
|
494
|
-
assert(File.file?(destination_path("site-#{CSS_BUNDLE_FINGERPRINT}.css")))
|
|
495
|
-
assert(File.file?(destination_path("site-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
496
|
-
|
|
497
|
-
assert_equal("site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
|
498
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
499
|
-
end
|
|
500
|
-
end
|
|
501
|
-
|
|
502
|
-
def test_supports_destination_baseurl
|
|
503
|
-
with_site_dir do
|
|
504
|
-
merge_to_yaml_file(source_path('_config.yml'), 'cdn_baseurl' => 'https://cdn.example.com/?file=')
|
|
505
|
-
|
|
506
|
-
find_and_gsub_in_file(
|
|
507
|
-
source_path('_layouts/default.html'),
|
|
508
|
-
' {% minibundle css %}',
|
|
509
|
-
<<-LIQUID
|
|
510
|
-
{% minibundle css %}
|
|
511
|
-
baseurl: /ignored
|
|
512
|
-
destination_baseurl: {{ site.cdn_baseurl }}css/
|
|
513
|
-
LIQUID
|
|
514
|
-
)
|
|
515
|
-
|
|
516
|
-
find_and_gsub_in_file(
|
|
517
|
-
source_path('_layouts/default.html'),
|
|
518
|
-
/ #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
|
|
519
|
-
<<-LIQUID
|
|
520
|
-
{% minibundle js %}
|
|
521
|
-
source_dir: _assets/scripts
|
|
522
|
-
destination_path: static
|
|
523
|
-
baseurl: /ignored
|
|
524
|
-
destination_baseurl: '{{ site.cdn_baseurl }}'
|
|
525
|
-
assets:
|
|
526
|
-
- dependency
|
|
527
|
-
- app
|
|
528
|
-
{% endminibundle %}
|
|
529
|
-
LIQUID
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
generate_site(:production)
|
|
533
|
-
|
|
534
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
535
|
-
assert(File.file?(destination_path("static-#{JS_BUNDLE_FINGERPRINT}.js")))
|
|
536
|
-
|
|
537
|
-
assert_equal("https://cdn.example.com/?file=css/site-#{CSS_BUNDLE_FINGERPRINT}.css", find_css_path_from_index)
|
|
538
|
-
assert_equal("https://cdn.example.com/?file=static-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
539
|
-
end
|
|
540
|
-
end
|
|
541
|
-
|
|
542
|
-
def test_supports_changing_attributes
|
|
543
|
-
with_site_dir do
|
|
544
|
-
generate_site(:production)
|
|
545
|
-
|
|
546
|
-
assert_equal(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_css_path_from_index)
|
|
547
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
548
|
-
|
|
549
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-styles', 'id: my-styles2')
|
|
550
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
|
551
|
-
|
|
552
|
-
generate_site(:production, clear_cache: false)
|
|
553
|
-
|
|
554
|
-
assert_equal('my-styles2', find_css_element_from_index['id'])
|
|
555
|
-
assert_equal('my-scripts2', find_js_element_from_index['id'])
|
|
556
|
-
end
|
|
557
|
-
end
|
|
558
|
-
|
|
559
|
-
def test_bundles_assets_only_once_at_startup
|
|
560
|
-
with_site_dir do
|
|
561
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
562
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
563
|
-
end
|
|
564
|
-
end
|
|
565
|
-
|
|
566
|
-
def test_does_not_rebundle_assets_when_changing_nonsource_files
|
|
567
|
-
with_site_dir do
|
|
568
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
569
|
-
|
|
570
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
571
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
572
|
-
|
|
573
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
574
|
-
|
|
575
|
-
ensure_file_mtime_changes { File.write(source_path(CSS_BUNDLE_SOURCE_DIR, 'common.css'), 'h1 {}') }
|
|
576
|
-
|
|
577
|
-
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
578
|
-
|
|
579
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
580
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
581
|
-
|
|
582
|
-
ensure_file_mtime_changes { FileUtils.touch('index.html') }
|
|
583
|
-
|
|
584
|
-
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
585
|
-
|
|
586
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
587
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
588
|
-
end
|
|
589
|
-
end
|
|
590
|
-
|
|
591
|
-
def test_does_not_rebundle_assets_when_changing_attributes
|
|
592
|
-
with_site_dir do
|
|
593
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
594
|
-
|
|
595
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
596
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
597
|
-
|
|
598
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
599
|
-
|
|
600
|
-
ensure_file_mtime_changes do
|
|
601
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
|
602
|
-
end
|
|
603
|
-
|
|
604
|
-
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
605
|
-
|
|
606
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
607
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
608
|
-
end
|
|
609
|
-
end
|
|
610
|
-
|
|
611
|
-
def test_does_not_rebundle_assets_when_changing_baseurl
|
|
612
|
-
with_site_dir do
|
|
613
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
614
|
-
|
|
615
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
616
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
617
|
-
|
|
618
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
619
|
-
|
|
620
|
-
ensure_file_mtime_changes do
|
|
621
|
-
find_and_gsub_in_file(
|
|
622
|
-
source_path('_layouts/default.html'),
|
|
623
|
-
' {% minibundle js %}',
|
|
624
|
-
<<-LIQUID
|
|
625
|
-
{% minibundle js %}
|
|
626
|
-
baseurl: /js-root
|
|
627
|
-
LIQUID
|
|
628
|
-
)
|
|
629
|
-
end
|
|
630
|
-
|
|
631
|
-
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
632
|
-
|
|
633
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
634
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
635
|
-
assert_equal("/js-root/#{JS_BUNDLE_DESTINATION_FINGERPRINT_PATH}", find_js_path_from_index)
|
|
636
|
-
end
|
|
637
|
-
end
|
|
638
|
-
|
|
639
|
-
def test_does_not_rebundle_assets_when_changing_destination_baseurl
|
|
640
|
-
with_site_dir do
|
|
641
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
642
|
-
|
|
643
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
644
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
645
|
-
|
|
646
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
647
|
-
|
|
648
|
-
ensure_file_mtime_changes do
|
|
649
|
-
find_and_gsub_in_file(
|
|
650
|
-
source_path('_layouts/default.html'),
|
|
651
|
-
' {% minibundle js %}',
|
|
652
|
-
<<-LIQUID
|
|
653
|
-
{% minibundle js %}
|
|
654
|
-
destination_baseurl: /root/
|
|
655
|
-
LIQUID
|
|
656
|
-
)
|
|
657
|
-
end
|
|
658
|
-
|
|
659
|
-
generate_site(:production, clear_cache: false, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count)
|
|
660
|
-
|
|
661
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
662
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
663
|
-
assert_equal("/root/site-#{JS_BUNDLE_FINGERPRINT}.js", find_js_path_from_index)
|
|
664
|
-
end
|
|
665
|
-
end
|
|
666
|
-
|
|
667
|
-
def test_gets_minifier_command_from_site_configuration
|
|
668
|
-
with_site_dir do
|
|
669
|
-
merge_to_yaml_file(
|
|
670
|
-
source_path('_config.yml'),
|
|
671
|
-
'minibundle' => {'minifier_commands' => {'js' => minifier_cmd_to_remove_comments_and_count('minifier_cmd_config_count')}}
|
|
672
|
-
)
|
|
673
|
-
|
|
674
|
-
generate_site(:production, minifier_cmd_js: nil)
|
|
675
|
-
|
|
676
|
-
assert_equal(0, get_minifier_cmd_count)
|
|
677
|
-
assert_equal(1, get_minifier_cmd_count('minifier_cmd_config_count'))
|
|
678
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
679
|
-
end
|
|
680
|
-
end
|
|
681
|
-
|
|
682
|
-
def test_minifier_command_from_environment_overrides_command_from_site_configuration
|
|
683
|
-
with_site_dir do
|
|
684
|
-
merge_to_yaml_file(
|
|
685
|
-
source_path('_config.yml'),
|
|
686
|
-
'minibundle' => {'minifier_commands' => {'js' => minifier_cmd_to_remove_comments_and_count('minifier_cmd_config_count')}}
|
|
687
|
-
)
|
|
688
|
-
|
|
689
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_env_count'))
|
|
690
|
-
|
|
691
|
-
assert_equal(0, get_minifier_cmd_count('minifier_cmd_config_count'))
|
|
692
|
-
assert_equal(1, get_minifier_cmd_count('minifier_cmd_env_count'))
|
|
693
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
694
|
-
end
|
|
695
|
-
end
|
|
696
|
-
|
|
697
|
-
def test_minifier_command_in_local_block_overrides_command_from_environment
|
|
698
|
-
with_site_dir do
|
|
699
|
-
IO.write('test.html', <<~YAML)
|
|
700
|
-
---
|
|
701
|
-
layout: override
|
|
702
|
-
title: Test
|
|
703
|
-
---
|
|
704
|
-
YAML
|
|
705
|
-
|
|
706
|
-
IO.write('_layouts/override.html', <<~LIQUID)
|
|
707
|
-
<!DOCTYPE html>
|
|
708
|
-
<html>
|
|
709
|
-
<body>
|
|
710
|
-
{% minibundle js %}
|
|
711
|
-
source_dir: _assets/scripts
|
|
712
|
-
destination_path: assets/deps
|
|
713
|
-
assets:
|
|
714
|
-
- dependency
|
|
715
|
-
minifier_cmd: #{minifier_cmd_to_remove_comments_and_count('minifier_cmd_local_count')}
|
|
716
|
-
{% endminibundle %}
|
|
717
|
-
</body>
|
|
718
|
-
</html>
|
|
719
|
-
LIQUID
|
|
720
|
-
|
|
721
|
-
generate_site(:production, minifier_cmd_js: minifier_cmd_to_remove_comments_and_count('minifier_cmd_global_count'))
|
|
722
|
-
|
|
723
|
-
assert_equal(1, get_minifier_cmd_count('minifier_cmd_local_count'))
|
|
724
|
-
assert(File.file?(destination_path('assets/deps-71042d0b7c86c04e015fde694dd9f409.js')))
|
|
725
|
-
|
|
726
|
-
assert_equal(1, get_minifier_cmd_count('minifier_cmd_global_count'))
|
|
727
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
728
|
-
end
|
|
729
|
-
end
|
|
730
|
-
|
|
731
|
-
def test_destination_file_respects_umask
|
|
732
|
-
with_site_dir do
|
|
733
|
-
with_umask(0o027) do
|
|
734
|
-
generate_site(:production)
|
|
735
|
-
assert_equal(0o640, file_permissions_of(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
736
|
-
end
|
|
737
|
-
end
|
|
738
|
-
end
|
|
739
|
-
|
|
740
|
-
def test_escapes_destination_path_url_and_attributes_in_generated_html_element
|
|
741
|
-
with_site_dir do
|
|
742
|
-
find_and_gsub_in_file(
|
|
743
|
-
source_path('_layouts/default.html'),
|
|
744
|
-
/ #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
|
|
745
|
-
<<-LIQUID
|
|
746
|
-
{% minibundle js %}
|
|
747
|
-
source_dir: _assets/scripts
|
|
748
|
-
destination_path: 'dst">'
|
|
749
|
-
assets:
|
|
750
|
-
- dependency
|
|
751
|
-
- app
|
|
752
|
-
attributes:
|
|
753
|
-
test: '"/><br>'
|
|
754
|
-
{% endminibundle %}
|
|
755
|
-
LIQUID
|
|
756
|
-
)
|
|
757
|
-
|
|
758
|
-
generate_site(:production)
|
|
759
|
-
|
|
760
|
-
assert(File.file?(destination_path(%(dst">-#{JS_BUNDLE_FINGERPRINT}.js))))
|
|
761
|
-
assert_equal(%(dst">-#{JS_BUNDLE_FINGERPRINT}.js), find_js_path_from_index)
|
|
762
|
-
assert_equal('"/><br>', find_js_element_from_index['test'])
|
|
763
|
-
end
|
|
764
|
-
end
|
|
765
|
-
|
|
766
|
-
def test_empty_asset_sources_produces_empty_bundle
|
|
767
|
-
with_site_dir do
|
|
768
|
-
match_snippet = <<-YAML
|
|
769
|
-
assets:
|
|
770
|
-
- dependency
|
|
771
|
-
- app
|
|
772
|
-
YAML
|
|
773
|
-
|
|
774
|
-
replacement_snippet = <<-YAML
|
|
775
|
-
assets: []
|
|
776
|
-
YAML
|
|
777
|
-
|
|
778
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
779
|
-
|
|
780
|
-
generate_site(:production)
|
|
781
|
-
|
|
782
|
-
destination = "assets/site-#{Digest::MD5.hexdigest('')}.js"
|
|
783
|
-
|
|
784
|
-
assert_equal(destination, find_js_path_from_index)
|
|
785
|
-
assert(File.file?(destination_path(destination)))
|
|
786
|
-
end
|
|
787
|
-
end
|
|
788
|
-
|
|
789
|
-
def test_allows_relative_paths_in_asset_source_files
|
|
790
|
-
with_site_dir do
|
|
791
|
-
match_snippet = <<-LIQUID
|
|
792
|
-
{% minibundle js %}
|
|
793
|
-
source_dir: _assets/scripts
|
|
794
|
-
destination_path: assets/site
|
|
795
|
-
assets:
|
|
796
|
-
- dependency
|
|
797
|
-
- app
|
|
798
|
-
LIQUID
|
|
799
|
-
|
|
800
|
-
replacement_snippet = <<-LIQUID
|
|
801
|
-
{% minibundle js %}
|
|
802
|
-
source_dir: _assets
|
|
803
|
-
destination_path: assets/site
|
|
804
|
-
assets:
|
|
805
|
-
- scripts/dependencies/one
|
|
806
|
-
- ../_app
|
|
807
|
-
LIQUID
|
|
808
|
-
|
|
809
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
810
|
-
|
|
811
|
-
FileUtils.mkdir('_assets/scripts/dependencies')
|
|
812
|
-
FileUtils.mv(source_path('_assets/scripts/dependency.js'), source_path('_assets/scripts/dependencies/one.js'))
|
|
813
|
-
FileUtils.mv(source_path('_assets/scripts/app.js'), source_path('_app.js'))
|
|
814
|
-
|
|
815
|
-
generate_site(:production)
|
|
816
|
-
|
|
817
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
818
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
819
|
-
end
|
|
820
|
-
end
|
|
821
|
-
|
|
822
|
-
def test_allows_root_dir_as_source_dir
|
|
823
|
-
with_site_dir do
|
|
824
|
-
match_snippet = <<-LIQUID
|
|
825
|
-
{% minibundle js %}
|
|
826
|
-
source_dir: _assets/scripts
|
|
827
|
-
destination_path: assets/site
|
|
828
|
-
assets:
|
|
829
|
-
- dependency
|
|
830
|
-
- app
|
|
831
|
-
LIQUID
|
|
832
|
-
|
|
833
|
-
replacement_snippet = <<-LIQUID
|
|
834
|
-
{% minibundle js %}
|
|
835
|
-
source_dir: .
|
|
836
|
-
destination_path: assets/site
|
|
837
|
-
assets:
|
|
838
|
-
- _assets/scripts/dependency
|
|
839
|
-
- _assets/scripts/app
|
|
840
|
-
LIQUID
|
|
841
|
-
|
|
842
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
843
|
-
|
|
844
|
-
generate_site(:production)
|
|
845
|
-
|
|
846
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, find_js_path_from_index)
|
|
847
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
848
|
-
end
|
|
849
|
-
end
|
|
850
|
-
|
|
851
|
-
private
|
|
852
|
-
|
|
853
|
-
def find_css_element_from_index
|
|
854
|
-
find_html_element_from_index('head link[media!="screen"]')
|
|
855
|
-
end
|
|
856
|
-
|
|
857
|
-
def find_css_path_from_index
|
|
858
|
-
find_css_element_from_index['href']
|
|
859
|
-
end
|
|
860
|
-
|
|
861
|
-
def find_js_element_from_index
|
|
862
|
-
find_html_element_from_index('body script')
|
|
863
|
-
end
|
|
864
|
-
|
|
865
|
-
def find_js_path_from_index
|
|
866
|
-
find_js_element_from_index['src']
|
|
867
|
-
end
|
|
868
|
-
|
|
869
|
-
def find_html_element_from_index(css)
|
|
870
|
-
find_html_element(File.read(destination_path('index.html')), css).first
|
|
871
|
-
end
|
|
872
|
-
|
|
873
|
-
def source_assets_size(source_subdir, assets, type)
|
|
874
|
-
assets
|
|
875
|
-
.map { |f| File.read(site_fixture_path(source_subdir, "#{f}.#{type}")) }
|
|
876
|
-
.join('')
|
|
877
|
-
.size
|
|
878
|
-
end
|
|
879
|
-
|
|
880
|
-
def change_destination_path_in_minibundle_block(from, to)
|
|
881
|
-
match_snippet = <<-LIQUID
|
|
882
|
-
{% minibundle js %}
|
|
883
|
-
source_dir: _assets/scripts
|
|
884
|
-
destination_path: #{from}
|
|
885
|
-
LIQUID
|
|
886
|
-
|
|
887
|
-
replacement_snippet = <<-LIQUID
|
|
888
|
-
{% minibundle js %}
|
|
889
|
-
source_dir: _assets/scripts
|
|
890
|
-
destination_path: #{to}
|
|
891
|
-
LIQUID
|
|
892
|
-
|
|
893
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
894
|
-
end
|
|
895
|
-
|
|
896
|
-
def find_tempfiles(glob)
|
|
897
|
-
Dir[File.join(Dir.tmpdir, AssetBundle::TEMPFILE_PREFIX + glob)]
|
|
898
|
-
end
|
|
899
|
-
end
|
|
900
|
-
end
|