jekyll-minibundle 2.1.2 → 2.2.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 +96 -42
- data/LICENSE.txt +1 -1
- data/README.md +232 -52
- data/Rakefile +16 -0
- data/jekyll-minibundle.gemspec +7 -6
- data/lib/jekyll/minibundle/asset_bundle.rb +3 -3
- data/lib/jekyll/minibundle/asset_file_drop.rb +45 -0
- data/lib/jekyll/minibundle/asset_file_properties.rb +12 -8
- data/lib/jekyll/minibundle/asset_file_registry.rb +4 -4
- data/lib/jekyll/minibundle/asset_tag_markup.rb +21 -20
- data/lib/jekyll/minibundle/bundle_file.rb +6 -1
- data/lib/jekyll/minibundle/development_file.rb +2 -1
- data/lib/jekyll/minibundle/development_file_collection.rb +2 -2
- data/lib/jekyll/minibundle/environment.rb +13 -15
- data/lib/jekyll/minibundle/files.rb +16 -18
- data/lib/jekyll/minibundle/hashes.rb +10 -12
- data/lib/jekyll/minibundle/log.rb +5 -7
- data/lib/jekyll/minibundle/mini_bundle_block.rb +35 -12
- data/lib/jekyll/minibundle/mini_stamp_tag.rb +108 -16
- data/lib/jekyll/minibundle/stamp_file.rb +1 -0
- data/lib/jekyll/minibundle/variable_template.rb +145 -0
- data/lib/jekyll/minibundle/variable_template_registry.rb +19 -0
- data/lib/jekyll/minibundle/version.rb +1 -1
- data/test/fixture/site/_bin/with_count +1 -1
- data/test/integration/minibundle_development_mode_test.rb +146 -61
- data/test/integration/minibundle_production_mode_test.rb +271 -143
- data/test/integration/ministamp_development_mode_test.rb +66 -25
- data/test/integration/ministamp_production_mode_test.rb +129 -37
- data/test/integration/static_files_as_asset_sources_test.rb +10 -10
- data/test/support/assertions.rb +1 -1
- data/test/support/{static_file_api_config.rb → static_file_config.rb} +6 -3
- data/test/support/test_case.rb +7 -4
- data/test/unit/asset_bundle_test.rb +6 -6
- data/test/unit/asset_file_drop_test.rb +65 -0
- data/test/unit/asset_file_registry_test.rb +136 -98
- data/test/unit/asset_tag_markup_test.rb +11 -5
- data/test/unit/bundle_file_properties_test.rb +44 -23
- data/test/unit/bundle_file_writing_test.rb +50 -32
- data/test/unit/development_file_properties_test.rb +95 -0
- data/test/unit/development_file_writing_test.rb +15 -6
- data/test/unit/environment_test.rb +3 -3
- data/test/unit/files_test.rb +7 -7
- data/test/unit/hashes_test.rb +12 -12
- data/test/unit/jekyll_static_file_api_test.rb +91 -20
- data/test/unit/mini_bundle_block_test.rb +59 -9
- data/test/unit/mini_stamp_tag_test.rb +37 -6
- data/test/unit/stamp_file_properties_test.rb +47 -24
- data/test/unit/stamp_file_writing_test.rb +33 -24
- data/test/unit/variable_template_test.rb +121 -0
- metadata +27 -6
- data/test/unit/development_file_collection_properties_test.rb +0 -106
@@ -13,7 +13,7 @@ module Jekyll::Minibundle::Test
|
|
13
13
|
destination_path(CSS_BUNDLE_DESTINATION_FINGERPRINT_PATH),
|
14
14
|
destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
15
15
|
].sort
|
16
|
-
assert_equal
|
16
|
+
assert_equal(expected, actual)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -28,9 +28,9 @@ module Jekyll::Minibundle::Test
|
|
28
28
|
|
29
29
|
asset_files = Dir[destination_path('assets') + '/screen*.css']
|
30
30
|
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
33
|
-
assert_equal
|
31
|
+
assert_equal(1, asset_files.size)
|
32
|
+
assert_equal(contents, File.read(destination_path('assets/shared.css')))
|
33
|
+
assert_equal(contents, File.read(asset_files.first))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -45,8 +45,8 @@ module Jekyll::Minibundle::Test
|
|
45
45
|
|
46
46
|
generate_site(:development)
|
47
47
|
|
48
|
-
assert_equal
|
49
|
-
assert_equal
|
48
|
+
assert_equal(dep_contents, File.read(destination_path('assets/dependency.js')))
|
49
|
+
assert_equal(app_contents, File.read(destination_path('assets/app.js')))
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -63,10 +63,10 @@ module Jekyll::Minibundle::Test
|
|
63
63
|
|
64
64
|
asset_files = Dir[destination_path('assets/site-*.js')]
|
65
65
|
|
66
|
-
assert_equal
|
67
|
-
assert_equal
|
68
|
-
assert_equal
|
69
|
-
assert_equal
|
66
|
+
assert_equal(1, asset_files.size)
|
67
|
+
assert_equal(dep_contents, File.read(destination_path('assets/dependency.js')))
|
68
|
+
assert_equal(app_contents, File.read(destination_path('assets/app.js')))
|
69
|
+
assert_equal(bundled_contents, File.read(asset_files.first))
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
data/test/support/assertions.rb
CHANGED
@@ -17,7 +17,7 @@ module Jekyll::Minibundle::Test
|
|
17
17
|
end
|
18
18
|
|
19
19
|
assert(remaining.empty?, lambda do
|
20
|
-
"Expected
|
20
|
+
"Expected\n\n#{mu_pp(collection)}\n\nto include only\n\n#{mu_pp(expected_elements)}"
|
21
21
|
end)
|
22
22
|
end
|
23
23
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
module Jekyll::Minibundle::Test
|
2
|
-
module
|
3
|
-
|
2
|
+
module StaticFileConfig
|
3
|
+
STATIC_FILE_PROPERTIES = [
|
4
|
+
:basename,
|
5
|
+
:data,
|
4
6
|
:defaults,
|
5
7
|
:destination_rel_dir,
|
6
|
-
:name,
|
7
8
|
:extname,
|
8
9
|
:modified_time,
|
9
10
|
:mtime,
|
11
|
+
:name,
|
10
12
|
:path,
|
11
13
|
:placeholders,
|
12
14
|
:relative_path,
|
13
15
|
:to_liquid,
|
14
16
|
:type,
|
17
|
+
:url,
|
15
18
|
:write?
|
16
19
|
].freeze
|
17
20
|
end
|
data/test/support/test_case.rb
CHANGED
@@ -84,10 +84,10 @@ module Jekyll::Minibundle::Test
|
|
84
84
|
OpenStruct.new(source: dir, static_files: [])
|
85
85
|
end
|
86
86
|
|
87
|
-
def make_real_site
|
87
|
+
def make_real_site(dir = Dir.pwd)
|
88
88
|
config = nil
|
89
89
|
capture_io do
|
90
|
-
config = Jekyll.configuration('source' =>
|
90
|
+
config = Jekyll.configuration('source' => dir, 'destination' => '_site')
|
91
91
|
end
|
92
92
|
Jekyll::Site.new(config)
|
93
93
|
end
|
@@ -125,7 +125,7 @@ module Jekyll::Minibundle::Test
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def get_minifier_cmd_count(count_file = 'minifier_cmd_count')
|
128
|
-
if File.
|
128
|
+
if File.file?(count_file)
|
129
129
|
File.read(count_file).to_i
|
130
130
|
else
|
131
131
|
0
|
@@ -162,7 +162,10 @@ module Jekyll::Minibundle::Test
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def _generate_site(test_options)
|
165
|
-
|
165
|
+
if test_options.fetch(:clear_cache, true)
|
166
|
+
AssetFileRegistry.clear_all
|
167
|
+
VariableTemplateRegistry.clear
|
168
|
+
end
|
166
169
|
site = make_real_site
|
167
170
|
capture_io { site.process }
|
168
171
|
end
|
@@ -6,7 +6,7 @@ module Jekyll::Minibundle::Test
|
|
6
6
|
def test_raise_exception_if_bundle_command_fails
|
7
7
|
capture_io do
|
8
8
|
err = assert_raises(RuntimeError) { make_bundle('read _ignore ; false') }
|
9
|
-
assert_equal "
|
9
|
+
assert_equal('Bundling "assets/site.js" failed with exit status 1, command: "read _ignore ; false"', err.to_s)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -16,27 +16,27 @@ module Jekyll::Minibundle::Test
|
|
16
16
|
assert_raises(RuntimeError) { make_bundle(cmd) }
|
17
17
|
end
|
18
18
|
expected_stderr = <<-END
|
19
|
-
Minibundle: Bundling assets/site.js failed with exit status 1, command:
|
19
|
+
Minibundle: Bundling "assets/site.js" failed with exit status 1, command: #{cmd.inspect}, last 16 bytes of minifier output:
|
20
20
|
Minibundle: line 1\\x07
|
21
21
|
Minibundle: line 2\\xa4
|
22
22
|
END
|
23
|
-
assert_equal
|
23
|
+
assert_equal(expected_stderr, actual_stderr.gsub(/\e\[\d+m/, '').gsub(/^ +/, ''))
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_raise_exception_if_bundle_command_not_found
|
27
27
|
err = assert_raises(RuntimeError) { make_bundle('no-such-jekyll-minibundle-cmd') }
|
28
|
-
assert_equal
|
28
|
+
assert_equal('Bundling "assets/site.js" failed: No such file or directory - no-such-jekyll-minibundle-cmd', err.to_s)
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_raise_exception_if_bundle_command_not_configured
|
32
32
|
err = assert_raises(RuntimeError) { make_bundle(nil) }
|
33
33
|
expected_errmsg = <<-END
|
34
|
-
Missing minification command for bundling assets/site.js. Specify it in
|
34
|
+
Missing minification command for bundling "assets/site.js". Specify it in
|
35
35
|
1) minibundle.minifier_commands.js setting in _config.yml,
|
36
36
|
2) $JEKYLL_MINIBUNDLE_CMD_JS environment variable, or
|
37
37
|
3) minifier_cmd setting inside minibundle block.
|
38
38
|
END
|
39
|
-
assert_equal
|
39
|
+
assert_equal(expected_errmsg, err.to_s)
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'support/test_case'
|
3
|
+
require 'support/fixture_config'
|
4
|
+
require 'jekyll/minibundle/asset_file_drop'
|
5
|
+
require 'jekyll/minibundle/stamp_file'
|
6
|
+
|
7
|
+
module Jekyll::Minibundle::Test
|
8
|
+
class AssetFileDropTest < TestCase
|
9
|
+
include FixtureConfig
|
10
|
+
|
11
|
+
def test_method_access_via_subscript_method
|
12
|
+
with_drop do |drop|
|
13
|
+
assert_equal("screen-#{STAMP_FINGERPRINT}.css", drop['name'])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_method_access_via_forwarding
|
18
|
+
with_drop do |drop|
|
19
|
+
assert_equal("screen-#{STAMP_FINGERPRINT}.css", drop['name'])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_key?
|
24
|
+
with_drop do |drop|
|
25
|
+
assert(drop.key?('name'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_to_h
|
30
|
+
with_drop do |drop|
|
31
|
+
hash = drop.to_h
|
32
|
+
assert_equal(AssetFileDrop::KEYS.sort, hash.keys.sort)
|
33
|
+
assert_equal("screen-#{STAMP_FINGERPRINT}.css", hash['name'])
|
34
|
+
assert_equal('.css', hash['extname'])
|
35
|
+
assert_equal("screen-#{STAMP_FINGERPRINT}", hash['basename'])
|
36
|
+
assert_instance_of(Time, hash['modified_time'])
|
37
|
+
assert_equal("/#{STAMP_SOURCE_PATH}", hash['path'])
|
38
|
+
assert_nil(hash['collection'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_to_hash
|
43
|
+
with_drop do |drop|
|
44
|
+
assert_equal(drop.to_h, drop.to_hash)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_inspect
|
49
|
+
with_drop do |drop|
|
50
|
+
assert_equal(drop.to_h.keys, JSON.parse(drop.inspect).keys)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def with_drop(&block)
|
57
|
+
with_fake_site do |site|
|
58
|
+
file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
|
59
|
+
file.destination_path_for_markup
|
60
|
+
drop = AssetFileDrop.new(file)
|
61
|
+
block.call(drop)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,59 +1,77 @@
|
|
1
1
|
require 'support/test_case'
|
2
|
+
require 'support/fixture_config'
|
2
3
|
require 'jekyll/minibundle/asset_file_registry'
|
3
4
|
|
4
5
|
module Jekyll::Minibundle::Test
|
5
6
|
class AssetFileRegistryTest < TestCase
|
7
|
+
include FixtureConfig
|
8
|
+
|
6
9
|
def setup
|
7
10
|
AssetFileRegistry.clear_all
|
8
|
-
@site = make_site
|
9
11
|
end
|
10
12
|
|
11
13
|
def test_register_returns_same_bundle_file_for_same_bundle_config
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
with_fake_site do |site|
|
15
|
+
first = AssetFileRegistry.register_bundle_file(site, bundle_config)
|
16
|
+
second = AssetFileRegistry.register_bundle_file(site, bundle_config)
|
17
|
+
assert_same(first, second)
|
18
|
+
assert_equal(1, asset_file_registry_size)
|
19
|
+
assert_contains_only(site.static_files, [first])
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def test_register_returns_same_development_file_collection_for_same_bundle_config
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
with_fake_site do |site|
|
25
|
+
first = AssetFileRegistry.register_development_file_collection(site, bundle_config)
|
26
|
+
second = AssetFileRegistry.register_development_file_collection(site, bundle_config)
|
27
|
+
assert_same(first, second)
|
28
|
+
assert_equal(1, asset_file_registry_size)
|
29
|
+
assert_contains_only(site.static_files, first.files)
|
30
|
+
end
|
25
31
|
end
|
26
32
|
|
27
33
|
def test_register_returns_different_bundle_files_for_bundle_configs_with_different_destination_paths
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
with_fake_site do |site|
|
35
|
+
first = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest1'))
|
36
|
+
second = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest2'))
|
37
|
+
refute_same first, second
|
38
|
+
assert_equal(2, asset_file_registry_size)
|
39
|
+
assert_contains_only(site.static_files, [first, second])
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
def test_register_returns_different_development_file_collections_for_bundle_configs_with_different_destination_paths
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
with_fake_site do |site|
|
45
|
+
first = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('destination_path' => 'assets/dest1'))
|
46
|
+
second = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('destination_path' => 'assets/dest2'))
|
47
|
+
refute_same first, second
|
48
|
+
assert_equal(2, asset_file_registry_size)
|
49
|
+
assert_contains_only(site.static_files, (first.files + second.files))
|
50
|
+
end
|
41
51
|
end
|
42
52
|
|
43
53
|
def test_register_returns_different_bundle_files_for_bundle_configs_with_different_types
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
54
|
+
with_fake_site do |site|
|
55
|
+
FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'dependency.css'))
|
56
|
+
FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'app.css'))
|
57
|
+
first = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('type' => :css))
|
58
|
+
second = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('type' => :js))
|
59
|
+
refute_same first, second
|
60
|
+
assert_equal(2, asset_file_registry_size)
|
61
|
+
assert_contains_only(site.static_files, [first, second])
|
62
|
+
end
|
49
63
|
end
|
50
64
|
|
51
65
|
def test_register_returns_different_development_file_collections_for_bundle_configs_with_different_types
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
with_fake_site do |site|
|
67
|
+
FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'dependency.css'))
|
68
|
+
FileUtils.touch(File.join(JS_BUNDLE_SOURCE_DIR, 'app.css'))
|
69
|
+
first = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('type' => :css))
|
70
|
+
second = AssetFileRegistry.register_development_file_collection(site, bundle_config.merge('type' => :js))
|
71
|
+
refute_same first, second
|
72
|
+
assert_equal(2, asset_file_registry_size)
|
73
|
+
assert_contains_only(site.static_files, (first.files + second.files))
|
74
|
+
end
|
57
75
|
end
|
58
76
|
|
59
77
|
[
|
@@ -61,17 +79,19 @@ module Jekyll::Minibundle::Test
|
|
61
79
|
{description: 'source_directory', config_diff: {'source_dir' => '_assets/src2'}}
|
62
80
|
].each do |spec|
|
63
81
|
define_method :"test_raise_exception_if_registering_bundle_file_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
82
|
+
with_fake_site do |site|
|
83
|
+
first_config = bundle_config
|
84
|
+
first_file = AssetFileRegistry.register_bundle_file(site, first_config)
|
85
|
+
second_config = bundle_config.merge(spec[:config_diff])
|
86
|
+
err = assert_raises(RuntimeError) do
|
87
|
+
AssetFileRegistry.register_bundle_file(site, second_config)
|
88
|
+
end
|
89
|
+
assert_equal(<<-END, err.to_s)
|
90
|
+
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}
|
91
|
+
END
|
92
|
+
assert_equal(1, asset_file_registry_size)
|
93
|
+
assert_contains_only(site.static_files, [first_file])
|
69
94
|
end
|
70
|
-
assert_equal <<-END, err.to_s
|
71
|
-
Two or more minibundle blocks with the same destination path 'assets/dest.css', but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
|
72
|
-
END
|
73
|
-
assert_equal 1, asset_file_registry_size
|
74
|
-
assert_contains_only @site.static_files, [first_file]
|
75
95
|
end
|
76
96
|
end
|
77
97
|
|
@@ -80,17 +100,19 @@ Two or more minibundle blocks with the same destination path 'assets/dest.css',
|
|
80
100
|
{description: 'source_directory', config_diff: {'source_dir' => '_assets/src2'}}
|
81
101
|
].each do |spec|
|
82
102
|
define_method :"test_raise_exception_if_registering_development_file_collection_with_same_destination_path_but_with_different_#{spec.fetch(:description)}" do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
with_fake_site do |site|
|
104
|
+
first_config = bundle_config
|
105
|
+
first_file = AssetFileRegistry.register_development_file_collection(site, first_config)
|
106
|
+
second_config = bundle_config.merge(spec[:config_diff])
|
107
|
+
err = assert_raises(RuntimeError) do
|
108
|
+
AssetFileRegistry.register_development_file_collection(site, second_config)
|
109
|
+
end
|
110
|
+
assert_equal(<<-END, err.to_s)
|
111
|
+
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}
|
112
|
+
END
|
113
|
+
assert_equal(1, asset_file_registry_size)
|
114
|
+
assert_contains_only(site.static_files, first_file.files)
|
88
115
|
end
|
89
|
-
assert_equal <<-END, err.to_s
|
90
|
-
Two or more minibundle blocks with the same destination path 'assets/dest.css', but having different asset configuration: #{second_config.inspect} vs. #{first_config.inspect}
|
91
|
-
END
|
92
|
-
assert_equal 1, asset_file_registry_size
|
93
|
-
assert_contains_only @site.static_files, first_file.files
|
94
116
|
end
|
95
117
|
end
|
96
118
|
|
@@ -99,52 +121,68 @@ Two or more minibundle blocks with the same destination path 'assets/dest.css',
|
|
99
121
|
{description: 'development_file', method: :register_development_file}
|
100
122
|
].each do |spec|
|
101
123
|
define_method :"test_register_returns_same_#{spec.fetch(:description)}_for_same_source_and_destination_paths" do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
124
|
+
with_fake_site do |site|
|
125
|
+
first = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
|
126
|
+
second = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
|
127
|
+
assert_same(first, second)
|
128
|
+
assert_equal(1, asset_file_registry_size)
|
129
|
+
assert_contains_only(site.static_files, [first])
|
130
|
+
end
|
107
131
|
end
|
108
132
|
|
109
133
|
define_method :"test_register_returns_different_#{spec.fetch(:description)}s_for_different_source_and_destination_paths" do
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
134
|
+
with_fake_site do |site|
|
135
|
+
first = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest1.css')
|
136
|
+
second = AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, 'assets/dest2.css')
|
137
|
+
refute_same first, second
|
138
|
+
assert_equal(2, asset_file_registry_size)
|
139
|
+
assert_contains_only(site.static_files, [first, second])
|
140
|
+
end
|
115
141
|
end
|
116
142
|
|
117
143
|
define_method :"test_raise_exception_if_registering_#{spec.fetch(:description)}s_with_different_source_and_same_destination_paths" do
|
118
|
-
|
119
|
-
|
120
|
-
|
144
|
+
with_fake_site do |site|
|
145
|
+
source_paths = %w{src1.css src2.css}.map do |file|
|
146
|
+
File.join(CSS_BUNDLE_SOURCE_DIR, file)
|
147
|
+
end
|
148
|
+
source_paths.each { |path| FileUtils.touch(path) }
|
149
|
+
first = AssetFileRegistry.send(spec.fetch(:method), site, source_paths[0], 'assets/dest1.css')
|
150
|
+
err = assert_raises(RuntimeError) do
|
151
|
+
AssetFileRegistry.send(spec.fetch(:method), site, source_paths[1], 'assets/dest1.css')
|
152
|
+
end
|
153
|
+
assert_equal(<<-END, err.to_s)
|
154
|
+
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]}"
|
155
|
+
END
|
156
|
+
assert_equal(1, asset_file_registry_size)
|
157
|
+
assert_contains_only(site.static_files, [first])
|
121
158
|
end
|
122
|
-
assert_equal <<-END, err.to_s
|
123
|
-
Two or more ministamp tags with the same destination path 'assets/dest1.css', but different asset source paths: '_assets/src2.css' vs. '_assets/src1.css'
|
124
|
-
END
|
125
|
-
assert_equal 1, asset_file_registry_size
|
126
|
-
assert_contains_only @site.static_files, [first]
|
127
159
|
end
|
128
160
|
end
|
129
161
|
|
130
162
|
def test_raise_exception_if_registering_stamp_file_with_same_destination_path_as_existing_bundle_file
|
131
|
-
|
132
|
-
|
133
|
-
AssetFileRegistry.
|
163
|
+
with_fake_site do |site|
|
164
|
+
FileUtils.touch('_assets/src.js')
|
165
|
+
file = AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest'))
|
166
|
+
err = assert_raises(RuntimeError) do
|
167
|
+
AssetFileRegistry.register_stamp_file(site, '_assets/src.js', 'assets/dest.js')
|
168
|
+
end
|
169
|
+
assert_equal('ministamp tag has the same destination path as a minibundle block: assets/dest.js', err.to_s)
|
170
|
+
assert_equal(1, asset_file_registry_size)
|
171
|
+
assert_contains_only(site.static_files, [file])
|
134
172
|
end
|
135
|
-
assert_equal "ministamp tag has the same destination path as a minibundle block: 'assets/dest.css'", err.to_s
|
136
|
-
assert_equal 1, asset_file_registry_size
|
137
|
-
assert_contains_only @site.static_files, [file]
|
138
173
|
end
|
139
174
|
|
140
175
|
def test_raise_exception_if_registering_bundle_file_with_same_destination_path_as_existing_stamp_file
|
141
|
-
|
142
|
-
|
143
|
-
AssetFileRegistry.
|
176
|
+
with_fake_site do |site|
|
177
|
+
FileUtils.touch('_assets/src.js')
|
178
|
+
file = AssetFileRegistry.register_stamp_file(site, '_assets/src.js', 'assets/dest.js')
|
179
|
+
err = assert_raises(RuntimeError) do
|
180
|
+
AssetFileRegistry.register_bundle_file(site, bundle_config.merge('destination_path' => 'assets/dest'))
|
181
|
+
end
|
182
|
+
assert_equal('minibundle block has the same destination path as a ministamp tag: assets/dest.js', err.to_s)
|
183
|
+
assert_equal(1, asset_file_registry_size)
|
184
|
+
assert_contains_only(site.static_files, [file])
|
144
185
|
end
|
145
|
-
assert_equal "minibundle block has the same destination path as a ministamp tag: 'assets/dest.css'", err.to_s
|
146
|
-
assert_equal 1, asset_file_registry_size
|
147
|
-
assert_contains_only @site.static_files, [file]
|
148
186
|
end
|
149
187
|
|
150
188
|
[
|
@@ -152,14 +190,16 @@ Two or more ministamp tags with the same destination path 'assets/dest1.css', bu
|
|
152
190
|
{description: 'development_file_collection', method: :register_development_file_collection}
|
153
191
|
].each do |spec|
|
154
192
|
define_method :"test_remove_unused_#{spec.fetch(:description)}" do
|
155
|
-
|
156
|
-
|
193
|
+
with_fake_site do |site|
|
194
|
+
AssetFileRegistry.send(spec.fetch(:method), site, bundle_config)
|
195
|
+
AssetFileRegistry.clear_unused
|
157
196
|
|
158
|
-
|
197
|
+
assert_equal(1, asset_file_registry_size)
|
159
198
|
|
160
|
-
|
199
|
+
AssetFileRegistry.clear_unused
|
161
200
|
|
162
|
-
|
201
|
+
assert_equal(0, asset_file_registry_size)
|
202
|
+
end
|
163
203
|
end
|
164
204
|
end
|
165
205
|
|
@@ -168,14 +208,16 @@ Two or more ministamp tags with the same destination path 'assets/dest1.css', bu
|
|
168
208
|
{description: 'development_file', method: :register_development_file}
|
169
209
|
].each do |spec|
|
170
210
|
define_method :"test_remove_unused_#{spec.fetch(:description)}" do
|
171
|
-
|
172
|
-
|
211
|
+
with_fake_site do |site|
|
212
|
+
AssetFileRegistry.send(spec.fetch(:method), site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
|
213
|
+
AssetFileRegistry.clear_unused
|
173
214
|
|
174
|
-
|
215
|
+
assert_equal(1, asset_file_registry_size)
|
175
216
|
|
176
|
-
|
217
|
+
AssetFileRegistry.clear_unused
|
177
218
|
|
178
|
-
|
219
|
+
assert_equal(0, asset_file_registry_size)
|
220
|
+
end
|
179
221
|
end
|
180
222
|
end
|
181
223
|
|
@@ -183,10 +225,10 @@ Two or more ministamp tags with the same destination path 'assets/dest1.css', bu
|
|
183
225
|
|
184
226
|
def bundle_config
|
185
227
|
{
|
186
|
-
'type' => :
|
187
|
-
'source_dir' =>
|
228
|
+
'type' => :js,
|
229
|
+
'source_dir' => JS_BUNDLE_SOURCE_DIR,
|
188
230
|
'assets' => %w{dependency app},
|
189
|
-
'destination_path' =>
|
231
|
+
'destination_path' => JS_BUNDLE_DESTINATION_PATH,
|
190
232
|
'minifier_cmd' => 'unused_minifier_cmd'
|
191
233
|
}
|
192
234
|
end
|
@@ -194,9 +236,5 @@ Two or more ministamp tags with the same destination path 'assets/dest1.css', bu
|
|
194
236
|
def asset_file_registry_size
|
195
237
|
AssetFileRegistry.instance_variable_get(:@_files).size
|
196
238
|
end
|
197
|
-
|
198
|
-
def make_site
|
199
|
-
make_fake_site('.')
|
200
|
-
end
|
201
239
|
end
|
202
240
|
end
|