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,554 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
|
|
6
|
-
module Jekyll::Minibundle::Test
|
|
7
|
-
class MinibundleDevelopmentModeTest < TestCase
|
|
8
|
-
include FixtureConfig
|
|
9
|
-
|
|
10
|
-
CSS_ASSET_DESTINATION_PATHS = %w[reset common].map { |f| File.join(CSS_BUNDLE_DESTINATION_PATH, "#{f}.css") }
|
|
11
|
-
JS_ASSET_DESTINATION_PATHS = %w[dependency app].map { |f| File.join(JS_BUNDLE_DESTINATION_PATH, "#{f}.js") }
|
|
12
|
-
|
|
13
|
-
def test_css_assets_have_tags_in_configured_order
|
|
14
|
-
with_precompiled_site(:development) do
|
|
15
|
-
assert_equal(CSS_ASSET_DESTINATION_PATHS, find_css_paths_from_index)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_js_assets_have_tags_in_configured_order
|
|
20
|
-
with_precompiled_site(:development) do
|
|
21
|
-
assert_equal(JS_ASSET_DESTINATION_PATHS, find_js_paths_from_index)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_css_assets_have_configured_attributes
|
|
26
|
-
with_precompiled_site(:development) do
|
|
27
|
-
elements = find_css_elements_from_index.map { |el| [el['id'], el['media']] }.uniq
|
|
28
|
-
assert_equal([%w[my-styles projection]], elements)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def test_js_assets_have_configured_attributes
|
|
33
|
-
with_precompiled_site(:development) do
|
|
34
|
-
elements = find_js_elements_from_index.map { |el| [el['id'], el['async']] }.uniq
|
|
35
|
-
assert_equal([['my-scripts', '']], elements)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_copies_css_assets_to_destination_dir
|
|
40
|
-
with_precompiled_site(:development) do
|
|
41
|
-
CSS_ASSET_DESTINATION_PATHS.each do |path|
|
|
42
|
-
expect_file_exists_and_is_equal_to(destination_path(path), site_fixture_path(CSS_BUNDLE_SOURCE_DIR, File.basename(path)))
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_copies_js_assets_to_destination_dir
|
|
48
|
-
with_precompiled_site(:development) do
|
|
49
|
-
JS_ASSET_DESTINATION_PATHS.each do |path|
|
|
50
|
-
expect_file_exists_and_is_equal_to(destination_path(path), site_fixture_path(JS_BUNDLE_SOURCE_DIR, File.basename(path)))
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
[
|
|
56
|
-
{desc: 'changing', action: ->(source) { File.write(source, '(function() {})()') }},
|
|
57
|
-
{desc: 'touching', action: ->(source) { FileUtils.touch(source) }}
|
|
58
|
-
].each do |spec|
|
|
59
|
-
define_method :"test_#{spec.fetch(:desc)}_asset_source_file_rewrites_destination" do
|
|
60
|
-
with_site_dir do
|
|
61
|
-
generate_site(:development)
|
|
62
|
-
|
|
63
|
-
destination = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
64
|
-
org_mtime = file_mtime_of(destination)
|
|
65
|
-
source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
|
|
66
|
-
ensure_file_mtime_changes { spec.fetch(:action).call(source) }
|
|
67
|
-
|
|
68
|
-
generate_site(:development, clear_cache: false)
|
|
69
|
-
|
|
70
|
-
assert_equal(File.read(destination), File.read(source))
|
|
71
|
-
assert_operator(file_mtime_of(destination), :>, org_mtime)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_changing_asset_source_directory_rewrites_destination
|
|
77
|
-
with_site_dir do
|
|
78
|
-
generate_site(:development)
|
|
79
|
-
|
|
80
|
-
destination = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
81
|
-
org_mtime = file_mtime_of(destination)
|
|
82
|
-
|
|
83
|
-
match_snippet = <<-LIQUID
|
|
84
|
-
{% minibundle js %}
|
|
85
|
-
source_dir: _assets/scripts
|
|
86
|
-
LIQUID
|
|
87
|
-
|
|
88
|
-
replacement_snippet = <<-LIQUID
|
|
89
|
-
{% minibundle js %}
|
|
90
|
-
source_dir: _assets/scripts2
|
|
91
|
-
LIQUID
|
|
92
|
-
|
|
93
|
-
ensure_file_mtime_changes do
|
|
94
|
-
FileUtils.mv(source_path('_assets/scripts'), source_path('_assets/scripts2'))
|
|
95
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
generate_site(:development, clear_cache: false)
|
|
99
|
-
|
|
100
|
-
assert_operator(file_mtime_of(destination), :>, org_mtime)
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_changing_asset_source_list_rewrites_destination
|
|
105
|
-
with_site_dir do
|
|
106
|
-
generate_site(:development)
|
|
107
|
-
|
|
108
|
-
org_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
|
109
|
-
|
|
110
|
-
match_snippet = <<-YAML
|
|
111
|
-
assets:
|
|
112
|
-
- dependency
|
|
113
|
-
- app
|
|
114
|
-
YAML
|
|
115
|
-
|
|
116
|
-
replacement_snippet = <<-YAML
|
|
117
|
-
assets:
|
|
118
|
-
- dependency
|
|
119
|
-
YAML
|
|
120
|
-
|
|
121
|
-
ensure_file_mtime_changes do
|
|
122
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
generate_site(:development, clear_cache: false)
|
|
126
|
-
|
|
127
|
-
assert_equal([File.join(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')], find_js_paths_from_index)
|
|
128
|
-
|
|
129
|
-
new_mtime = file_mtime_of(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js'))
|
|
130
|
-
assert_operator(new_mtime, :>, org_mtime)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_changing_asset_destination_path_rewrites_destination
|
|
135
|
-
with_site_dir do
|
|
136
|
-
generate_site(:development)
|
|
137
|
-
|
|
138
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')))
|
|
139
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
140
|
-
|
|
141
|
-
ensure_file_mtime_changes do
|
|
142
|
-
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
generate_site(:development, clear_cache: false)
|
|
146
|
-
|
|
147
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')))
|
|
148
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
149
|
-
|
|
150
|
-
assert_equal(['assets/site2/dependency.js', 'assets/site2/app.js'], find_js_paths_from_index)
|
|
151
|
-
assert(File.file?(destination_path('assets/site2/dependency.js')))
|
|
152
|
-
assert(File.file?(destination_path('assets/site2/app.js')))
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def test_changing_asset_destination_path_to_new_value_and_back_to_original_rewrites_destination
|
|
157
|
-
with_site_dir do
|
|
158
|
-
generate_site(:development)
|
|
159
|
-
|
|
160
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')))
|
|
161
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
162
|
-
|
|
163
|
-
ensure_file_mtime_changes do
|
|
164
|
-
change_destination_path_in_minibundle_block('assets/site', 'assets/site2')
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
generate_site(:development, clear_cache: false)
|
|
168
|
-
|
|
169
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')))
|
|
170
|
-
refute(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
171
|
-
|
|
172
|
-
assert_equal(['assets/site2/dependency.js', 'assets/site2/app.js'], find_js_paths_from_index)
|
|
173
|
-
assert(File.file?(destination_path('assets/site2/dependency.js')))
|
|
174
|
-
assert(File.file?(destination_path('assets/site2/app.js')))
|
|
175
|
-
|
|
176
|
-
ensure_file_mtime_changes do
|
|
177
|
-
change_destination_path_in_minibundle_block('assets/site2', 'assets/site')
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
generate_site(:development, clear_cache: false)
|
|
181
|
-
|
|
182
|
-
refute(File.file?(destination_path('assets/site2/dependency.js')))
|
|
183
|
-
refute(File.file?(destination_path('assets/site2/app.js')))
|
|
184
|
-
|
|
185
|
-
assert_equal(['assets/site/dependency.js', 'assets/site/app.js'], find_js_paths_from_index)
|
|
186
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'dependency.js')))
|
|
187
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def test_supports_relative_and_absolute_destination_paths
|
|
192
|
-
with_site_dir do
|
|
193
|
-
generate_site(:development)
|
|
194
|
-
|
|
195
|
-
destination_css = destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')
|
|
196
|
-
destination_js = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
197
|
-
org_mtime_css = file_mtime_of(destination_css)
|
|
198
|
-
org_mtime_js = file_mtime_of(destination_js)
|
|
199
|
-
|
|
200
|
-
assert(File.file?(destination_css))
|
|
201
|
-
assert(File.file?(destination_js))
|
|
202
|
-
|
|
203
|
-
assert_equal('assets/site/common.css', find_css_paths_from_index.last)
|
|
204
|
-
assert_equal('assets/site/app.js', find_js_paths_from_index.last)
|
|
205
|
-
|
|
206
|
-
ensure_file_mtime_changes do
|
|
207
|
-
find_and_gsub_in_file(
|
|
208
|
-
source_path('_layouts/default.html'),
|
|
209
|
-
'destination_path: assets/site',
|
|
210
|
-
'destination_path: /assets/site'
|
|
211
|
-
)
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
generate_site(:development, clear_cache: false)
|
|
215
|
-
|
|
216
|
-
assert(File.file?(destination_css))
|
|
217
|
-
assert(File.file?(destination_js))
|
|
218
|
-
assert_equal(org_mtime_css, file_mtime_of(destination_css))
|
|
219
|
-
assert_equal(org_mtime_js, file_mtime_of(destination_js))
|
|
220
|
-
assert_equal('/assets/site/common.css', find_css_paths_from_index.last)
|
|
221
|
-
assert_equal('/assets/site/app.js', find_js_paths_from_index.last)
|
|
222
|
-
end
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def test_supports_baseurl
|
|
226
|
-
with_site_dir do
|
|
227
|
-
merge_to_yaml_file(source_path('_config.yml'), 'baseurl' => '/root')
|
|
228
|
-
|
|
229
|
-
find_and_gsub_in_file(
|
|
230
|
-
source_path('_layouts/default.html'),
|
|
231
|
-
' {% minibundle css %}',
|
|
232
|
-
<<-LIQUID
|
|
233
|
-
{% minibundle css %}
|
|
234
|
-
baseurl: '{{ site.baseurl }}/'
|
|
235
|
-
LIQUID
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
find_and_gsub_in_file(
|
|
239
|
-
source_path('_layouts/default.html'),
|
|
240
|
-
' {% minibundle js %}',
|
|
241
|
-
<<-LIQUID
|
|
242
|
-
{% minibundle js %}
|
|
243
|
-
baseurl: {{ site.baseurl }}/js
|
|
244
|
-
LIQUID
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
generate_site(:development)
|
|
248
|
-
|
|
249
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')))
|
|
250
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
251
|
-
|
|
252
|
-
assert_equal('/root/assets/site/common.css', find_css_paths_from_index.last)
|
|
253
|
-
assert_equal('/root/js/assets/site/app.js', find_js_paths_from_index.last)
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
def test_supports_destination_baseurl
|
|
258
|
-
with_site_dir do
|
|
259
|
-
merge_to_yaml_file(source_path('_config.yml'), 'cdn_baseurl' => 'https://cdn.example.com/?file=')
|
|
260
|
-
|
|
261
|
-
find_and_gsub_in_file(
|
|
262
|
-
source_path('_layouts/default.html'),
|
|
263
|
-
' {% minibundle css %}',
|
|
264
|
-
<<-LIQUID
|
|
265
|
-
{% minibundle css %}
|
|
266
|
-
baseurl: /ignored
|
|
267
|
-
destination_baseurl: {{ site.cdn_baseurl }}css/
|
|
268
|
-
LIQUID
|
|
269
|
-
)
|
|
270
|
-
|
|
271
|
-
find_and_gsub_in_file(
|
|
272
|
-
source_path('_layouts/default.html'),
|
|
273
|
-
/ #{Regexp.escape('{% minibundle js %}')}.*#{Regexp.escape('{% endminibundle %}')}/m,
|
|
274
|
-
<<-LIQUID
|
|
275
|
-
{% minibundle js %}
|
|
276
|
-
source_dir: _assets/scripts
|
|
277
|
-
destination_path: static
|
|
278
|
-
baseurl: /ignored
|
|
279
|
-
destination_baseurl: '{{ site.cdn_baseurl }}'
|
|
280
|
-
assets:
|
|
281
|
-
- dependency
|
|
282
|
-
- app
|
|
283
|
-
{% endminibundle %}
|
|
284
|
-
LIQUID
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
generate_site(:development)
|
|
288
|
-
|
|
289
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')))
|
|
290
|
-
assert(File.file?(destination_path('static/app.js')))
|
|
291
|
-
|
|
292
|
-
assert_equal('https://cdn.example.com/?file=css/site/common.css', find_css_paths_from_index.last)
|
|
293
|
-
assert_equal('https://cdn.example.com/?file=static/app.js', find_js_paths_from_index.last)
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
def test_supports_changing_attributes
|
|
298
|
-
with_site_dir do
|
|
299
|
-
generate_site(:development)
|
|
300
|
-
|
|
301
|
-
assert(File.file?(destination_path(CSS_BUNDLE_DESTINATION_PATH, 'common.css')))
|
|
302
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
303
|
-
|
|
304
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-styles', 'id: my-styles2')
|
|
305
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
|
306
|
-
|
|
307
|
-
generate_site(:development, clear_cache: false)
|
|
308
|
-
|
|
309
|
-
css_ids = find_css_elements_from_index.map { |el| el['id'] }.uniq
|
|
310
|
-
assert_equal(['my-styles2'], css_ids)
|
|
311
|
-
|
|
312
|
-
js_ids = find_js_elements_from_index.map { |el| el['id'] }.uniq
|
|
313
|
-
assert_equal(['my-scripts2'], js_ids)
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
def test_does_not_require_bundling_commands
|
|
318
|
-
with_site_dir do
|
|
319
|
-
generate_site(:development, minifier_cmd_css: nil, minifier_cmd_js: nil)
|
|
320
|
-
pass
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
def test_does_not_rewrite_destination_when_changing_nonsource_files
|
|
325
|
-
with_site_dir do
|
|
326
|
-
generate_site(:development)
|
|
327
|
-
|
|
328
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
329
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
330
|
-
ensure_file_mtime_changes { File.write(source_path(JS_BUNDLE_SOURCE_DIR, 'dependency.js'), '(function() {})()') }
|
|
331
|
-
|
|
332
|
-
generate_site(:development, clear_cache: false)
|
|
333
|
-
|
|
334
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
335
|
-
|
|
336
|
-
ensure_file_mtime_changes { FileUtils.touch('index.html') }
|
|
337
|
-
|
|
338
|
-
generate_site(:development, clear_cache: false)
|
|
339
|
-
|
|
340
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
341
|
-
end
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
def test_does_not_rewrite_destination_when_changing_attributes
|
|
345
|
-
with_site_dir do
|
|
346
|
-
generate_site(:development)
|
|
347
|
-
|
|
348
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
349
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
350
|
-
|
|
351
|
-
ensure_file_mtime_changes do
|
|
352
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), 'id: my-scripts', 'id: my-scripts2')
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
generate_site(:development, clear_cache: false)
|
|
356
|
-
|
|
357
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
def test_does_not_rewrite_destination_when_changing_baseurl
|
|
362
|
-
with_site_dir do
|
|
363
|
-
generate_site(:development)
|
|
364
|
-
|
|
365
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
366
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
367
|
-
|
|
368
|
-
ensure_file_mtime_changes do
|
|
369
|
-
find_and_gsub_in_file(
|
|
370
|
-
source_path('_layouts/default.html'),
|
|
371
|
-
' {% minibundle js %}',
|
|
372
|
-
<<-LIQUID
|
|
373
|
-
{% minibundle js %}
|
|
374
|
-
baseurl: /js-root
|
|
375
|
-
LIQUID
|
|
376
|
-
)
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
generate_site(:development, clear_cache: false)
|
|
380
|
-
|
|
381
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
382
|
-
assert_equal("/js-root/#{JS_BUNDLE_DESTINATION_PATH}/app.js", find_js_paths_from_index.last)
|
|
383
|
-
end
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
def test_does_not_rewrite_destination_when_changing_destination_baseurl
|
|
387
|
-
with_site_dir do
|
|
388
|
-
generate_site(:development)
|
|
389
|
-
|
|
390
|
-
expected_js_path = destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')
|
|
391
|
-
org_mtime = file_mtime_of(expected_js_path)
|
|
392
|
-
|
|
393
|
-
ensure_file_mtime_changes do
|
|
394
|
-
find_and_gsub_in_file(
|
|
395
|
-
source_path('_layouts/default.html'),
|
|
396
|
-
' {% minibundle js %}',
|
|
397
|
-
<<-LIQUID
|
|
398
|
-
{% minibundle js %}
|
|
399
|
-
destination_baseurl: /js-root/
|
|
400
|
-
LIQUID
|
|
401
|
-
)
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
generate_site(:development, clear_cache: false)
|
|
405
|
-
|
|
406
|
-
assert_equal(org_mtime, file_mtime_of(expected_js_path))
|
|
407
|
-
assert_equal('/js-root/site/app.js', find_js_paths_from_index.last)
|
|
408
|
-
end
|
|
409
|
-
end
|
|
410
|
-
|
|
411
|
-
def test_gets_development_mode_from_site_configuration
|
|
412
|
-
with_site_dir do
|
|
413
|
-
merge_to_yaml_file('_config.yml', 'minibundle' => {'mode' => 'development'})
|
|
414
|
-
generate_site(nil)
|
|
415
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
416
|
-
end
|
|
417
|
-
end
|
|
418
|
-
|
|
419
|
-
def test_development_mode_from_environment_overrides_mode_from_site_configuration
|
|
420
|
-
with_site_dir do
|
|
421
|
-
merge_to_yaml_file('_config.yml', 'minibundle' => {'mode' => 'production'})
|
|
422
|
-
generate_site(:development)
|
|
423
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_PATH, 'app.js')))
|
|
424
|
-
end
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
def test_empty_asset_sources_produces_no_destination_assets
|
|
428
|
-
with_site_dir do
|
|
429
|
-
match_snippet = <<-YAML
|
|
430
|
-
assets:
|
|
431
|
-
- dependency
|
|
432
|
-
- app
|
|
433
|
-
YAML
|
|
434
|
-
|
|
435
|
-
replacement_snippet = <<-YAML
|
|
436
|
-
assets: []
|
|
437
|
-
YAML
|
|
438
|
-
|
|
439
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
440
|
-
|
|
441
|
-
generate_site(:development)
|
|
442
|
-
|
|
443
|
-
assert_empty([], find_js_paths_from_index)
|
|
444
|
-
end
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
def test_allows_relative_paths_in_asset_source_files
|
|
448
|
-
with_site_dir do
|
|
449
|
-
match_snippet = <<-LIQUID
|
|
450
|
-
{% minibundle js %}
|
|
451
|
-
source_dir: _assets/scripts
|
|
452
|
-
destination_path: assets/site
|
|
453
|
-
assets:
|
|
454
|
-
- dependency
|
|
455
|
-
- app
|
|
456
|
-
LIQUID
|
|
457
|
-
|
|
458
|
-
replacement_snippet = <<-LIQUID
|
|
459
|
-
{% minibundle js %}
|
|
460
|
-
source_dir: _assets
|
|
461
|
-
destination_path: assets/site
|
|
462
|
-
assets:
|
|
463
|
-
- scripts/dependencies/one
|
|
464
|
-
- ../_app
|
|
465
|
-
LIQUID
|
|
466
|
-
|
|
467
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
468
|
-
|
|
469
|
-
FileUtils.mkdir('_assets/scripts/dependencies')
|
|
470
|
-
FileUtils.mv(source_path('_assets/scripts/dependency.js'), source_path('_assets/scripts/dependencies/one.js'))
|
|
471
|
-
FileUtils.mv(source_path('_assets/scripts/app.js'), source_path('_app.js'))
|
|
472
|
-
|
|
473
|
-
generate_site(:development)
|
|
474
|
-
|
|
475
|
-
assert_equal(['assets/site/scripts/dependencies/one.js', 'assets/site/../_app.js'], find_js_paths_from_index)
|
|
476
|
-
assert(File.file?(destination_path('assets/site/scripts/dependencies/one.js')))
|
|
477
|
-
assert(File.file?(destination_path('assets/_app.js')))
|
|
478
|
-
end
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
def test_allows_root_dir_as_source_dir
|
|
482
|
-
with_site_dir do
|
|
483
|
-
match_snippet = <<-LIQUID
|
|
484
|
-
{% minibundle js %}
|
|
485
|
-
source_dir: _assets/scripts
|
|
486
|
-
destination_path: assets/site
|
|
487
|
-
assets:
|
|
488
|
-
- dependency
|
|
489
|
-
- app
|
|
490
|
-
LIQUID
|
|
491
|
-
|
|
492
|
-
replacement_snippet = <<-LIQUID
|
|
493
|
-
{% minibundle js %}
|
|
494
|
-
source_dir: .
|
|
495
|
-
destination_path: assets/site
|
|
496
|
-
assets:
|
|
497
|
-
- _assets/scripts/dependency
|
|
498
|
-
- _assets/scripts/app
|
|
499
|
-
LIQUID
|
|
500
|
-
|
|
501
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
502
|
-
|
|
503
|
-
generate_site(:development)
|
|
504
|
-
|
|
505
|
-
assert_equal(%w[dependency app].map { |p| File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts', "#{p}.js") }, find_js_paths_from_index)
|
|
506
|
-
assert(File.file?(destination_path(File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts/dependency.js'))))
|
|
507
|
-
assert(File.file?(destination_path(File.join(JS_BUNDLE_DESTINATION_PATH, '_assets/scripts/app.js'))))
|
|
508
|
-
end
|
|
509
|
-
end
|
|
510
|
-
|
|
511
|
-
private
|
|
512
|
-
|
|
513
|
-
def find_css_elements_from_index
|
|
514
|
-
find_html_elements_from_index('head link[media!="screen"]')
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
def find_css_paths_from_index
|
|
518
|
-
find_css_elements_from_index.map { |el| el['href'] }
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
def find_js_elements_from_index
|
|
522
|
-
find_html_elements_from_index('body script')
|
|
523
|
-
end
|
|
524
|
-
|
|
525
|
-
def find_js_paths_from_index
|
|
526
|
-
find_js_elements_from_index.map { |el| el['src'] }
|
|
527
|
-
end
|
|
528
|
-
|
|
529
|
-
def find_html_elements_from_index(css)
|
|
530
|
-
find_html_element(File.read(destination_path('index.html')), css)
|
|
531
|
-
end
|
|
532
|
-
|
|
533
|
-
def expect_file_exists_and_is_equal_to(actual, expected)
|
|
534
|
-
assert(File.file?(actual))
|
|
535
|
-
assert_equal(File.read(expected), File.read(actual))
|
|
536
|
-
end
|
|
537
|
-
|
|
538
|
-
def change_destination_path_in_minibundle_block(from, to)
|
|
539
|
-
match_snippet = <<-LIQUID
|
|
540
|
-
{% minibundle js %}
|
|
541
|
-
source_dir: _assets/scripts
|
|
542
|
-
destination_path: #{from}
|
|
543
|
-
LIQUID
|
|
544
|
-
|
|
545
|
-
replacement_snippet = <<-LIQUID
|
|
546
|
-
{% minibundle js %}
|
|
547
|
-
source_dir: _assets/scripts
|
|
548
|
-
destination_path: #{to}
|
|
549
|
-
LIQUID
|
|
550
|
-
|
|
551
|
-
find_and_gsub_in_file(source_path('_layouts/default.html'), match_snippet, replacement_snippet)
|
|
552
|
-
end
|
|
553
|
-
end
|
|
554
|
-
end
|