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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -66
  3. data/README.md +117 -101
  4. data/Rakefile +8 -26
  5. data/jekyll-minibundle.gemspec +5 -11
  6. data/lib/jekyll/minibundle/asset_bundle.rb +1 -1
  7. data/lib/jekyll/minibundle/asset_file_drop.rb +1 -3
  8. data/lib/jekyll/minibundle/asset_file_registry.rb +2 -2
  9. data/lib/jekyll/minibundle/asset_tag_markup.rb +1 -1
  10. data/lib/jekyll/minibundle/bundle_file.rb +3 -0
  11. data/lib/jekyll/minibundle/development_file.rb +2 -0
  12. data/lib/jekyll/minibundle/hashes.rb +1 -3
  13. data/lib/jekyll/minibundle/stamp_file.rb +3 -0
  14. data/lib/jekyll/minibundle/variable_template.rb +3 -1
  15. data/lib/jekyll/minibundle/variable_template_registry.rb +2 -2
  16. data/lib/jekyll/minibundle/version.rb +1 -1
  17. metadata +8 -184
  18. data/test/fixture/site/_assets/scripts/app.js +0 -5
  19. data/test/fixture/site/_assets/scripts/dependency.js +0 -4
  20. data/test/fixture/site/_assets/styles/common.css +0 -2
  21. data/test/fixture/site/_assets/styles/reset.css +0 -2
  22. data/test/fixture/site/_bin/remove_comments +0 -4
  23. data/test/fixture/site/_bin/with_count +0 -15
  24. data/test/fixture/site/_config.yml +0 -3
  25. data/test/fixture/site/_layouts/default.html +0 -29
  26. data/test/fixture/site/_tmp/site.css +0 -3
  27. data/test/fixture/site/about.html +0 -4
  28. data/test/fixture/site/assets/site.css +0 -2
  29. data/test/fixture/site/index.html +0 -4
  30. data/test/integration/minibundle_development_mode_test.rb +0 -554
  31. data/test/integration/minibundle_production_mode_test.rb +0 -900
  32. data/test/integration/ministamp_development_mode_test.rb +0 -235
  33. data/test/integration/ministamp_production_mode_test.rb +0 -342
  34. data/test/integration/static_files_as_asset_sources_test.rb +0 -75
  35. data/test/support/assertions.rb +0 -26
  36. data/test/support/fixture_config.rb +0 -20
  37. data/test/support/static_file_config.rb +0 -23
  38. data/test/support/test_case.rb +0 -175
  39. data/test/unit/asset_bundle_test.rb +0 -57
  40. data/test/unit/asset_file_drop_test.rb +0 -66
  41. data/test/unit/asset_file_registry_test.rb +0 -237
  42. data/test/unit/asset_tag_markup_test.rb +0 -46
  43. data/test/unit/bundle_file_properties_test.rb +0 -108
  44. data/test/unit/bundle_file_writing_test.rb +0 -155
  45. data/test/unit/development_file_properties_test.rb +0 -97
  46. data/test/unit/development_file_writing_test.rb +0 -50
  47. data/test/unit/environment_test.rb +0 -29
  48. data/test/unit/files_test.rb +0 -61
  49. data/test/unit/hashes_test.rb +0 -43
  50. data/test/unit/jekyll_static_file_api_test.rb +0 -172
  51. data/test/unit/mini_bundle_block_test.rb +0 -125
  52. data/test/unit/mini_stamp_tag_test.rb +0 -64
  53. data/test/unit/stamp_file_properties_test.rb +0 -98
  54. data/test/unit/stamp_file_writing_test.rb +0 -130
  55. data/test/unit/variable_template_test.rb +0 -121
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll::Minibundle::Test
4
- module StaticFileConfig
5
- STATIC_FILE_PROPERTIES = %i[
6
- basename
7
- data
8
- defaults
9
- destination_rel_dir
10
- extname
11
- modified_time
12
- mtime
13
- name
14
- path
15
- placeholders
16
- relative_path
17
- to_liquid
18
- type
19
- url
20
- write?
21
- ].freeze
22
- end
23
- end
@@ -1,175 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
- require 'ostruct'
5
- require 'tempfile'
6
- require 'nokogiri'
7
- require 'jekyll'
8
- require 'jekyll/minibundle'
9
- require 'minitest/autorun'
10
- require_relative 'assertions'
11
-
12
- module Jekyll::Minibundle::Test
13
- class TestCase < ::Minitest::Test
14
- include Assertions
15
- include ::Jekyll::Minibundle
16
-
17
- FIXTURE_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../fixture'))
18
-
19
- def site_fixture_path(*args)
20
- File.join(FIXTURE_DIR, 'site', *args)
21
- end
22
-
23
- def source_path(*args)
24
- File.join(Dir.pwd, *args)
25
- end
26
-
27
- def destination_path(*args)
28
- File.join(Dir.pwd, '_site', *args)
29
- end
30
-
31
- def find_html_element(file, css)
32
- Nokogiri::HTML(file).css(css)
33
- end
34
-
35
- def find_and_gsub_in_file(file, pattern, replacement)
36
- old_content = File.read(file)
37
- new_content = old_content.gsub(pattern, replacement)
38
- File.write(file, new_content)
39
- end
40
-
41
- def merge_to_yaml_file(file, hash)
42
- IO.write(file, YAML.load_file(file).merge(hash).to_yaml)
43
- end
44
-
45
- def file_mtime_of(path)
46
- File.stat(path).mtime
47
- end
48
-
49
- def file_permissions_of(path)
50
- File.stat(path).mode & 0o777
51
- end
52
-
53
- def with_env(env)
54
- org_env = {}
55
- env.each do |k, v|
56
- org_env[k] = ENV[k]
57
- ENV[k] = v
58
- end
59
- yield
60
- ensure
61
- org_env.each { |k, v| ENV[k] = v }
62
- end
63
-
64
- def with_umask(cmask)
65
- org_cmask = File.umask
66
- File.umask(cmask)
67
- yield
68
- ensure
69
- File.umask(org_cmask)
70
- end
71
-
72
- def with_tmp_dir(&block)
73
- Dir.mktmpdir('jekyll-minibundle-test-site-') do |dir|
74
- Dir.chdir(dir, &block)
75
- end
76
- end
77
-
78
- def with_site_dir(&block)
79
- with_tmp_dir do |dir|
80
- _copy_fixture_site_dir(dir)
81
- block.call(dir)
82
- end
83
- end
84
-
85
- def make_fake_site(dir)
86
- OpenStruct.new(source: dir, static_files: [])
87
- end
88
-
89
- def make_real_site(dir = Dir.pwd)
90
- config = nil
91
- capture_io do
92
- config = Jekyll.configuration('source' => dir, 'destination' => '_site')
93
- end
94
- Jekyll::Site.new(config)
95
- end
96
-
97
- def with_fake_site(&block)
98
- with_site_dir do |dir|
99
- block.call(make_fake_site(dir))
100
- end
101
- end
102
-
103
- def with_precompiled_site(mode, &block)
104
- Dir.chdir(_get_precompiled_site(mode), &block)
105
- end
106
-
107
- def generate_site(mode, options = {})
108
- env = {
109
- 'JEKYLL_MINIBUNDLE_MODE' => mode&.to_s,
110
- 'JEKYLL_MINIBUNDLE_CMD_CSS' => options.fetch(:minifier_cmd_css, minifier_cmd_to_remove_comments),
111
- 'JEKYLL_MINIBUNDLE_CMD_JS' => options.fetch(:minifier_cmd_js, minifier_cmd_to_remove_comments)
112
- }
113
- with_env(env) { _generate_site(options) }
114
- end
115
-
116
- def ensure_file_mtime_changes(&block)
117
- sleep 1.5
118
- block.call
119
- end
120
-
121
- def minifier_cmd_to_remove_comments
122
- site_fixture_path('_bin/remove_comments')
123
- end
124
-
125
- def minifier_cmd_to_remove_comments_and_count(count_file = 'minifier_cmd_count')
126
- "#{site_fixture_path('_bin/with_count')} #{count_file} _bin/remove_comments"
127
- end
128
-
129
- def get_minifier_cmd_count(count_file = 'minifier_cmd_count')
130
- if File.file?(count_file)
131
- File.read(count_file).to_i
132
- else
133
- 0
134
- end
135
- end
136
-
137
- def get_send_results(obj, method_names)
138
- method_names.each_with_object({}) do |method_name, acc|
139
- acc[method_name] = obj.send(method_name)
140
- end
141
- end
142
-
143
- private
144
-
145
- def _copy_fixture_site_dir(dir)
146
- FileUtils.cp_r(site_fixture_path('.'), dir)
147
- end
148
-
149
- @@_precompiled_site_dirs = {}
150
-
151
- def _get_precompiled_site(mode)
152
- @@_precompiled_site_dirs[mode] ||= begin
153
- dir = Dir.mktmpdir("jekyll-minibundle-test-precompiled-site-#{mode}-")
154
- at_exit do
155
- FileUtils.rm_rf(dir)
156
- puts "\nCleaned precompiled site in #{mode} mode for tests: #{dir}"
157
- end
158
- Dir.chdir(dir) do
159
- _copy_fixture_site_dir(Dir.pwd)
160
- generate_site(mode)
161
- end
162
- dir
163
- end
164
- end
165
-
166
- def _generate_site(test_options)
167
- if test_options.fetch(:clear_cache, true)
168
- AssetFileRegistry.clear_all
169
- VariableTemplateRegistry.clear
170
- end
171
- site = make_real_site
172
- capture_io { site.process }
173
- end
174
- end
175
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require 'jekyll/minibundle/asset_bundle'
5
-
6
- module Jekyll::Minibundle::Test
7
- class AssetBundleTest < TestCase
8
- def test_raise_exception_if_bundle_command_fails
9
- capture_io do
10
- err = assert_raises(RuntimeError) { make_bundle('read _ignore ; false') }
11
- assert_equal('Bundling "assets/site.js" failed with exit status 1, command: "read _ignore ; false"', err.to_s)
12
- end
13
- end
14
-
15
- def test_log_minifier_stdout_if_bundle_command_fails
16
- cmd = 'ruby -E ISO-8859-15 -e \'gets; puts "line 1\a\nline\t2\xa4"; abort\''
17
- _, actual_stderr = capture_io do
18
- assert_raises(RuntimeError) { make_bundle(cmd) }
19
- end
20
- expected_stderr = <<~MESSAGE
21
- Minibundle: Bundling "assets/site.js" failed with exit status 1, command: #{cmd.inspect}, last 16 bytes of minifier output:
22
- Minibundle: line 1\\x07
23
- Minibundle: line 2\\xa4
24
- MESSAGE
25
- assert_equal(expected_stderr, actual_stderr.gsub(/\e\[\d+m/, '').gsub(/^ +/, ''))
26
- end
27
-
28
- def test_raise_exception_if_bundle_command_not_found
29
- err = assert_raises(RuntimeError) { make_bundle('no-such-jekyll-minibundle-cmd') }
30
- assert_equal('Bundling "assets/site.js" failed: No such file or directory - no-such-jekyll-minibundle-cmd', err.to_s)
31
- end
32
-
33
- def test_raise_exception_if_bundle_command_not_configured
34
- err = assert_raises(RuntimeError) { make_bundle(nil) }
35
- expected_errmsg = <<~MESSAGE
36
- Missing minification command for bundling "assets/site.js". Specify it in
37
- 1) minibundle.minifier_commands.js setting in _config.yml,
38
- 2) $JEKYLL_MINIBUNDLE_CMD_JS environment variable, or
39
- 3) minifier_cmd setting inside minibundle block.
40
- MESSAGE
41
- assert_equal(expected_errmsg, err.to_s)
42
- end
43
-
44
- private
45
-
46
- def make_bundle(minifier_cmd)
47
- bundle = AssetBundle.new(
48
- type: :js,
49
- asset_paths: [site_fixture_path('_assets/scripts/dependency.js')],
50
- destination_path: 'assets/site',
51
- site_dir: site_fixture_path,
52
- minifier_cmd: minifier_cmd
53
- )
54
- bundle.make_bundle
55
- end
56
- end
57
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require_relative '../support/fixture_config'
5
- require 'jekyll/minibundle/asset_file_drop'
6
- require 'jekyll/minibundle/stamp_file'
7
-
8
- module Jekyll::Minibundle::Test
9
- class AssetFileDropTest < TestCase
10
- include FixtureConfig
11
-
12
- def test_method_access_via_subscript_method
13
- with_drop do |drop|
14
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", drop['name'])
15
- end
16
- end
17
-
18
- def test_method_access_via_forwarding
19
- with_drop do |drop|
20
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", drop['name'])
21
- end
22
- end
23
-
24
- def test_key?
25
- with_drop do |drop|
26
- assert(drop.key?('name'))
27
- end
28
- end
29
-
30
- def test_to_h
31
- with_drop do |drop|
32
- hash = drop.to_h
33
- assert_equal(AssetFileDrop::KEYS.sort, hash.keys.sort)
34
- assert_equal("screen-#{STAMP_FINGERPRINT}.css", hash['name'])
35
- assert_equal('.css', hash['extname'])
36
- assert_equal("screen-#{STAMP_FINGERPRINT}", hash['basename'])
37
- assert_instance_of(Time, hash['modified_time'])
38
- assert_equal("/#{STAMP_SOURCE_PATH}", hash['path'])
39
- assert_nil(hash['collection'])
40
- end
41
- end
42
-
43
- def test_to_hash
44
- with_drop do |drop|
45
- assert_equal(drop.to_h, drop.to_hash)
46
- end
47
- end
48
-
49
- def test_inspect
50
- with_drop do |drop|
51
- assert_equal(drop.to_h.keys, JSON.parse(drop.inspect).keys)
52
- end
53
- end
54
-
55
- private
56
-
57
- def with_drop(&block)
58
- with_fake_site do |site|
59
- file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
60
- file.destination_path_for_markup
61
- drop = AssetFileDrop.new(file)
62
- block.call(drop)
63
- end
64
- end
65
- end
66
- end
@@ -1,237 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require_relative '../support/fixture_config'
5
- require 'jekyll/minibundle/asset_file_registry'
6
-
7
- module Jekyll::Minibundle::Test
8
- class AssetFileRegistryTest < TestCase
9
- include FixtureConfig
10
-
11
- def setup
12
- AssetFileRegistry.clear_all
13
- end
14
-
15
- def test_register_returns_same_bundle_file_for_same_bundle_config
16
- with_fake_site do |site|
17
- first = AssetFileRegistry.register_bundle_file(site, bundle_config)
18
- second = AssetFileRegistry.register_bundle_file(site, bundle_config)
19
- assert_same(first, second)
20
- assert_equal(1, asset_file_registry_size)
21
- assert_contains_only(site.static_files, [first])
22
- end
23
- end
24
-
25
- def test_register_returns_same_development_file_collection_for_same_bundle_config
26
- with_fake_site do |site|
27
- first = AssetFileRegistry.register_development_file_collection(site, bundle_config)
28
- second = AssetFileRegistry.register_development_file_collection(site, bundle_config)
29
- assert_same(first, second)
30
- assert_equal(1, asset_file_registry_size)
31
- assert_contains_only(site.static_files, first.files)
32
- end
33
- end
34
-
35
- def test_register_returns_different_bundle_files_for_bundle_configs_with_different_destination_paths
36
- with_fake_site do |site|
37
- first = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest1'))
38
- second = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest2'))
39
- refute_same first, second
40
- assert_equal(2, asset_file_registry_size)
41
- assert_contains_only(site.static_files, [first, second])
42
- end
43
- end
44
-
45
- def test_register_returns_different_development_file_collections_for_bundle_configs_with_different_destination_paths
46
- with_fake_site do |site|
47
- first = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('destination_path' => 'assets/dest1'))
48
- second = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('destination_path' => 'assets/dest2'))
49
- refute_same first, second
50
- assert_equal(2, asset_file_registry_size)
51
- assert_contains_only(site.static_files, (first.files + second.files))
52
- end
53
- end
54
-
55
- def test_register_returns_different_bundle_files_for_bundle_configs_with_different_types
56
- with_fake_site do |site|
57
- FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'dependency.css'))
58
- FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'app.css'))
59
- first = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('type' => :css))
60
- second = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('type' => :js))
61
- refute_same first, second
62
- assert_equal(2, asset_file_registry_size)
63
- assert_contains_only(site.static_files, [first, second])
64
- end
65
- end
66
-
67
- def test_register_returns_different_development_file_collections_for_bundle_configs_with_different_types
68
- with_fake_site do |site|
69
- FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'dependency.css'))
70
- FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'app.css'))
71
- first = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('type' => :css))
72
- second = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('type' => :js))
73
- refute_same first, second
74
- assert_equal(2, asset_file_registry_size)
75
- assert_contains_only(site.static_files, (first.files + second.files))
76
- end
77
- end
78
-
79
- [
80
- {description: 'assets', config_diff: {'assets' => %w[b1 b2]}},
81
- {description: 'source_directory', config_diff: {'source_dir' => '_assets/src2'}}
82
- ].each do |spec|
83
- define_method :"test_raise_exception_if_registering_bundle_file_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
84
- with_fake_site do |site|
85
- first_config = bundle_config
86
- first_file = AssetFileRegistry.register_bundle_file(site, first_config)
87
- second_config = bundle_config.merge(spec[:config_diff])
88
- err = assert_raises(RuntimeError) do
89
- AssetFileRegistry.register_bundle_file(site, second_config)
90
- end
91
- assert_equal(<<~MESSAGE, err.to_s)
92
- Two or more minibundle blocks with the same destination path "assets/site.js", but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
93
- MESSAGE
94
- assert_equal(1, asset_file_registry_size)
95
- assert_contains_only(site.static_files, [first_file])
96
- end
97
- end
98
-
99
- define_method :"test_raise_exception_if_registering_development_file_collection_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
100
- with_fake_site do |site|
101
- first_config = bundle_config
102
- first_file = AssetFileRegistry.register_development_file_collection(site, first_config)
103
- second_config = bundle_config.merge(spec[:config_diff])
104
- err = assert_raises(RuntimeError) do
105
- AssetFileRegistry.register_development_file_collection(site, second_config)
106
- end
107
- assert_equal(<<~MESSAGE, err.to_s)
108
- Two or more minibundle blocks with the same destination path "assets/site.js", but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
109
- MESSAGE
110
- assert_equal(1, asset_file_registry_size)
111
- assert_contains_only(site.static_files, first_file.files)
112
- end
113
- end
114
- end
115
-
116
- [
117
- {description: 'stamp_file', method: :register_stamp_file},
118
- {description: 'development_file', method: :register_development_file}
119
- ].each do |spec|
120
- define_method :"test_register_returns_same_#{spec.fetch(:description)}_for_same_source_and_destination_paths" do
121
- with_fake_site do |site|
122
- first = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
123
- second = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
124
- assert_same(first, second)
125
- assert_equal(1, asset_file_registry_size)
126
- assert_contains_only(site.static_files, [first])
127
- end
128
- end
129
-
130
- define_method :"test_register_returns_different_#{spec.fetch(:description)}s_for_different_source_and_destination_paths" do
131
- with_fake_site do |site|
132
- first = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
133
- second = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest2.css')
134
- refute_same first, second
135
- assert_equal(2, asset_file_registry_size)
136
- assert_contains_only(site.static_files, [first, second])
137
- end
138
- end
139
-
140
- define_method :"test_raise_exception_if_registering_#{spec.fetch(:description)}s_with_different_source_and_same_destination_paths" do
141
- with_fake_site do |site|
142
- source_paths = %w[src1.css src2.css].map do |file|
143
- File.join(CSS_BUNDLE_SOURCE_DIR, file)
144
- end
145
- source_paths.each { |path| FileUtils.touch(path) }
146
- first = AssetFileRegistry.send(spec.fetch(:method), site, source_paths[0], 'assets/dest1.css')
147
- err = assert_raises(RuntimeError) do
148
- AssetFileRegistry.send(spec.fetch(:method), site, source_paths[1], 'assets/dest1.css')
149
- end
150
- assert_equal(<<~MESSAGE, err.to_s)
151
- Two or more ministamp tags with the same destination path "assets/dest1.css", but different asset source paths: "#{source_paths[1]}" vs. "#{source_paths[0]}"
152
- MESSAGE
153
- assert_equal(1, asset_file_registry_size)
154
- assert_contains_only(site.static_files, [first])
155
- end
156
- end
157
- end
158
-
159
- def test_raise_exception_if_registering_stamp_file_with_same_destination_path_as_existing_bundle_file
160
- with_fake_site do |site|
161
- FileUtils.touch('_assets/src.js')
162
- file = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest'))
163
- err = assert_raises(RuntimeError) do
164
- AssetFileRegistry.register_stamp_file(site, '_assets/src.js', 'assets/dest.js')
165
- end
166
- assert_equal('ministamp tag has the same destination path as a minibundle block: assets/dest.js', err.to_s)
167
- assert_equal(1, asset_file_registry_size)
168
- assert_contains_only(site.static_files, [file])
169
- end
170
- end
171
-
172
- def test_raise_exception_if_registering_bundle_file_with_same_destination_path_as_existing_stamp_file
173
- with_fake_site do |site|
174
- FileUtils.touch('_assets/src.js')
175
- file = AssetFileRegistry.register_stamp_file(site, '_assets/src.js', 'assets/dest.js')
176
- err = assert_raises(RuntimeError) do
177
- AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest'))
178
- end
179
- assert_equal('minibundle block has the same destination path as a ministamp tag: assets/dest.js', err.to_s)
180
- assert_equal(1, asset_file_registry_size)
181
- assert_contains_only(site.static_files, [file])
182
- end
183
- end
184
-
185
- [
186
- {description: 'bundle_file', method: :register_bundle_file},
187
- {description: 'development_file_collection', method: :register_development_file_collection}
188
- ].each do |spec|
189
- define_method :"test_remove_unused_#{spec.fetch(:description)}" do
190
- with_fake_site do |site|
191
- AssetFileRegistry.send(spec.fetch(:method), site, bundle_config)
192
- AssetFileRegistry.clear_unused
193
-
194
- assert_equal(1, asset_file_registry_size)
195
-
196
- AssetFileRegistry.clear_unused
197
-
198
- assert_equal(0, asset_file_registry_size)
199
- end
200
- end
201
- end
202
-
203
- [
204
- {description: 'stamp_file', method: :register_stamp_file},
205
- {description: 'development_file', method: :register_development_file}
206
- ].each do |spec|
207
- define_method :"test_remove_unused_#{spec.fetch(:description)}" do
208
- with_fake_site do |site|
209
- AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
210
- AssetFileRegistry.clear_unused
211
-
212
- assert_equal(1, asset_file_registry_size)
213
-
214
- AssetFileRegistry.clear_unused
215
-
216
- assert_equal(0, asset_file_registry_size)
217
- end
218
- end
219
- end
220
-
221
- private
222
-
223
- def bundle_config
224
- {
225
- 'type' => :js,
226
- 'source_dir' => JS_BUNDLE_SOURCE_DIR,
227
- 'assets' => %w[dependency app],
228
- 'destination_path' => JS_BUNDLE_DESTINATION_PATH,
229
- 'minifier_cmd' => 'unused_minifier_cmd'
230
- }
231
- end
232
-
233
- def asset_file_registry_size
234
- AssetFileRegistry.instance_variable_get(:@_files).size
235
- end
236
- end
237
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../support/test_case'
4
- require 'jekyll/minibundle/asset_tag_markup'
5
-
6
- module Jekyll::Minibundle::Test
7
- class AssetTagMarkupTest < TestCase
8
- def test_escape_url
9
- actual = AssetTagMarkup.make_markup(:css, 'https://example.com/path?a=this+"thing"&b=<br>', {})
10
- expected = %(<link rel="stylesheet" href="https://example.com/path?a=this+&quot;thing&quot;&amp;b=&lt;br&gt;">)
11
- assert_equal(expected, actual)
12
- end
13
-
14
- def test_escape_attribute_value
15
- attributes = {media: 'screen, projection', extra: '">attack<br'}
16
- actual = AssetTagMarkup.make_markup(:css, '/asset.css', attributes)
17
- expected = %(<link rel="stylesheet" href="/asset.css" media="screen, projection" extra="&quot;&gt;attack&lt;br">)
18
- assert_equal(expected, actual)
19
- end
20
-
21
- def test_output_just_attribute_name_for_nil_value
22
- actual = AssetTagMarkup.make_markup(:css, '/asset.css', async: nil)
23
- expected = %(<link rel="stylesheet" href="/asset.css" async>)
24
- assert_equal(expected, actual)
25
- end
26
-
27
- def test_convert_attribute_value_to_string
28
- actual = AssetTagMarkup.make_markup(:css, '/asset.css', boolean: false)
29
- expected = %(<link rel="stylesheet" href="/asset.css" boolean="false">)
30
- assert_equal(expected, actual)
31
- end
32
-
33
- def test_output_empty_attribute_value
34
- actual = AssetTagMarkup.make_markup(:css, '/asset.css', empty: '')
35
- expected = %(<link rel="stylesheet" href="/asset.css" empty="">)
36
- assert_equal(expected, actual)
37
- end
38
-
39
- def test_raise_exception_if_unknown_type
40
- err = assert_raises(ArgumentError) do
41
- AssetTagMarkup.make_markup(:unknown, '/asset', {})
42
- end
43
- assert_equal('Unknown type for generating bundle markup: unknown, /asset', err.to_s)
44
- end
45
- end
46
- end