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,108 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
require_relative '../support/static_file_config'
|
|
6
|
-
require 'jekyll/minibundle/bundle_file'
|
|
7
|
-
|
|
8
|
-
module Jekyll::Minibundle::Test
|
|
9
|
-
class BundleFilePropertiesTest < TestCase
|
|
10
|
-
include FixtureConfig
|
|
11
|
-
include StaticFileConfig
|
|
12
|
-
|
|
13
|
-
def setup
|
|
14
|
-
@@results ||= with_bundle_file do |file|
|
|
15
|
-
get_send_results(file, STATIC_FILE_PROPERTIES)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_basename
|
|
20
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}", @@results.fetch(:basename))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_data
|
|
24
|
-
assert_equal({}, @@results.fetch(:data))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_defaults
|
|
28
|
-
assert_equal({}, @@results.fetch(:defaults))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_destination_rel_dir
|
|
32
|
-
assert_equal('/assets', @@results.fetch(:destination_rel_dir))
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_extname
|
|
36
|
-
assert_equal('.js', @@results.fetch(:extname))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_modified_time
|
|
40
|
-
assert_instance_of(Time, @@results.fetch(:modified_time))
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_mtime
|
|
44
|
-
mtime = @@results.fetch(:modified_time)
|
|
45
|
-
assert_equal(mtime.to_i, @@results.fetch(:mtime))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_name
|
|
49
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", @@results.fetch(:name))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_path
|
|
53
|
-
assert_match(%r{\A/.+/jekyll-minibundle-.+\.js\z}, @@results.fetch(:path))
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_placeholders
|
|
57
|
-
assert_equal({}, @@results.fetch(:placeholders))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_relative_path
|
|
61
|
-
assert_match(%r{/jekyll-minibundle-.+\.js\z}, @@results.fetch(:relative_path))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_to_liquid
|
|
65
|
-
with_bundle_file do |file|
|
|
66
|
-
drop = file.to_liquid
|
|
67
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}.js", drop.name)
|
|
68
|
-
assert_equal('.js', drop.extname)
|
|
69
|
-
assert_equal("site-#{JS_BUNDLE_FINGERPRINT}", drop.basename)
|
|
70
|
-
assert_instance_of(Time, drop.modified_time)
|
|
71
|
-
assert_match(%r{/jekyll-minibundle-.+\.js\z}, drop.path)
|
|
72
|
-
assert_nil(drop.collection)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_type
|
|
77
|
-
assert_nil(@@results.fetch(:type))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_url
|
|
81
|
-
assert_equal(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH, @@results.fetch(:url))
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def test_write?
|
|
85
|
-
assert(@@results.fetch(:write?))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
def with_bundle_file(&block)
|
|
91
|
-
with_fake_site do |site|
|
|
92
|
-
file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments))
|
|
93
|
-
capture_io { file.destination_path_for_markup }
|
|
94
|
-
block.call(file)
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def bundle_config(minifier_cmd)
|
|
99
|
-
{
|
|
100
|
-
'type' => :js,
|
|
101
|
-
'source_dir' => JS_BUNDLE_SOURCE_DIR,
|
|
102
|
-
'assets' => %w[dependency app],
|
|
103
|
-
'destination_path' => JS_BUNDLE_DESTINATION_PATH,
|
|
104
|
-
'minifier_cmd' => minifier_cmd
|
|
105
|
-
}
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
require 'jekyll/minibundle/bundle_file'
|
|
6
|
-
|
|
7
|
-
module Jekyll::Minibundle::Test
|
|
8
|
-
class BundleFileWritingTest < TestCase
|
|
9
|
-
include FixtureConfig
|
|
10
|
-
|
|
11
|
-
def test_raise_error_if_source_directory_does_not_exist
|
|
12
|
-
err = assert_raises(ArgumentError) do
|
|
13
|
-
with_fake_site do |site|
|
|
14
|
-
make_bundle_file(site, 'source_dir' => STAMP_SOURCE_PATH)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
assert_match(%r{\ABundle source directory does not exist: .+/#{Regexp.escape(STAMP_SOURCE_PATH)}\z}, err.to_s)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_raise_error_if_asset_source_file_does_not_exist
|
|
21
|
-
err = assert_raises(ArgumentError) do
|
|
22
|
-
with_fake_site do |site|
|
|
23
|
-
make_bundle_file(site, 'assets' => %w[no-such])
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
assert_match(%r{\ABundle asset source file does not exist: .+/#{Regexp.escape(JS_BUNDLE_SOURCE_DIR)}/no-such.js\z}, err.to_s)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
|
|
30
|
-
with_fake_site do |site|
|
|
31
|
-
bundle_file = make_bundle_file(site)
|
|
32
|
-
source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
|
|
33
|
-
old_destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
34
|
-
org_markup_path, last_markup_path = nil
|
|
35
|
-
|
|
36
|
-
# the call to destination_path_for_markup determines the
|
|
37
|
-
# fingerprint
|
|
38
|
-
|
|
39
|
-
capture_io { org_markup_path = bundle_file.destination_path_for_markup }
|
|
40
|
-
|
|
41
|
-
assert(write_file(bundle_file))
|
|
42
|
-
|
|
43
|
-
org_mtime = file_mtime_of(old_destination)
|
|
44
|
-
|
|
45
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
46
|
-
|
|
47
|
-
last_markup_path = bundle_file.destination_path_for_markup
|
|
48
|
-
|
|
49
|
-
assert_equal(org_markup_path, last_markup_path)
|
|
50
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
51
|
-
|
|
52
|
-
# change content, but don't call destination_path_for_markup yet
|
|
53
|
-
|
|
54
|
-
ensure_file_mtime_changes { File.write(source, '(function() {})()') }
|
|
55
|
-
|
|
56
|
-
# preserve content's fingerprint
|
|
57
|
-
|
|
58
|
-
refute(write_file(bundle_file))
|
|
59
|
-
|
|
60
|
-
assert_equal(org_mtime, file_mtime_of(old_destination))
|
|
61
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
62
|
-
|
|
63
|
-
# see content's fingerprint to update after calling
|
|
64
|
-
# destination_path_for_markup
|
|
65
|
-
|
|
66
|
-
capture_io { last_markup_path = bundle_file.destination_path_for_markup }
|
|
67
|
-
|
|
68
|
-
refute_equal org_markup_path, last_markup_path
|
|
69
|
-
|
|
70
|
-
assert(write_file(bundle_file))
|
|
71
|
-
|
|
72
|
-
new_destination = destination_path('assets/site-375a0b430b0c5555d0edd2205d26c04d.js')
|
|
73
|
-
|
|
74
|
-
assert_operator(file_mtime_of(new_destination), :>, org_mtime)
|
|
75
|
-
assert_equal(2, get_minifier_cmd_count)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def test_many_consecutive_destination_path_for_markup_calls_trigger_one_destination_write
|
|
80
|
-
with_fake_site do |site|
|
|
81
|
-
bundle_file = make_bundle_file(site)
|
|
82
|
-
source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
|
|
83
|
-
destination = destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)
|
|
84
|
-
org_markup_path, last_markup_path = nil
|
|
85
|
-
capture_io { org_markup_path = bundle_file.destination_path_for_markup }
|
|
86
|
-
bundle_file.destination_path_for_markup
|
|
87
|
-
|
|
88
|
-
assert(write_file(bundle_file))
|
|
89
|
-
|
|
90
|
-
org_mtime = file_mtime_of(destination)
|
|
91
|
-
|
|
92
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
93
|
-
|
|
94
|
-
ensure_file_mtime_changes { FileUtils.touch(source) }
|
|
95
|
-
capture_io { last_markup_path = bundle_file.destination_path_for_markup }
|
|
96
|
-
bundle_file.destination_path_for_markup
|
|
97
|
-
|
|
98
|
-
assert(write_file(bundle_file))
|
|
99
|
-
assert_equal(org_markup_path, last_markup_path)
|
|
100
|
-
assert_operator(file_mtime_of(destination), :>, org_mtime)
|
|
101
|
-
assert_equal(2, get_minifier_cmd_count)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_calling_write_before_destination_path_for_markup_has_no_effect
|
|
106
|
-
with_fake_site do |site|
|
|
107
|
-
bundle_file = make_bundle_file(site)
|
|
108
|
-
|
|
109
|
-
refute(write_file(bundle_file))
|
|
110
|
-
assert_empty(Dir[destination_path('assets/*.js')])
|
|
111
|
-
assert_equal(0, get_minifier_cmd_count)
|
|
112
|
-
|
|
113
|
-
capture_io { bundle_file.destination_path_for_markup }
|
|
114
|
-
|
|
115
|
-
assert(write_file(bundle_file))
|
|
116
|
-
assert(File.file?(destination_path(JS_BUNDLE_DESTINATION_FINGERPRINT_PATH)))
|
|
117
|
-
assert_equal(1, get_minifier_cmd_count)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def test_modified_property_determines_if_write_would_succeed
|
|
122
|
-
with_fake_site do |site|
|
|
123
|
-
bundle_file = make_bundle_file(site)
|
|
124
|
-
|
|
125
|
-
refute(bundle_file.modified?)
|
|
126
|
-
refute(write_file(bundle_file))
|
|
127
|
-
|
|
128
|
-
capture_io { bundle_file.destination_path_for_markup }
|
|
129
|
-
|
|
130
|
-
assert(bundle_file.modified?)
|
|
131
|
-
assert(write_file(bundle_file))
|
|
132
|
-
|
|
133
|
-
refute(bundle_file.modified?)
|
|
134
|
-
refute(write_file(bundle_file))
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
private
|
|
139
|
-
|
|
140
|
-
def make_bundle_file(site, config = {})
|
|
141
|
-
bundle_config = {
|
|
142
|
-
'type' => :js,
|
|
143
|
-
'source_dir' => JS_BUNDLE_SOURCE_DIR,
|
|
144
|
-
'assets' => %w[dependency app],
|
|
145
|
-
'destination_path' => JS_BUNDLE_DESTINATION_PATH,
|
|
146
|
-
'minifier_cmd' => minifier_cmd_to_remove_comments_and_count
|
|
147
|
-
}
|
|
148
|
-
BundleFile.new(site, bundle_config.merge(config))
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def write_file(file)
|
|
152
|
-
file.write(File.join(Dir.pwd, '_site'))
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
require_relative '../support/static_file_config'
|
|
6
|
-
require 'jekyll/minibundle/development_file'
|
|
7
|
-
|
|
8
|
-
module Jekyll::Minibundle::Test
|
|
9
|
-
class DevelopmentFilePropertiesTest < TestCase
|
|
10
|
-
include FixtureConfig
|
|
11
|
-
include StaticFileConfig
|
|
12
|
-
|
|
13
|
-
def setup
|
|
14
|
-
@@results ||= with_development_file do |file|
|
|
15
|
-
get_send_results(file, STATIC_FILE_PROPERTIES)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_basename
|
|
20
|
-
assert_equal('screen', @@results.fetch(:basename))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_data
|
|
24
|
-
assert_equal({}, @@results.fetch(:data))
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_defaults
|
|
28
|
-
assert_equal({}, @@results.fetch(:defaults))
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_destination_rel_dir
|
|
32
|
-
assert_equal('/assets', @@results.fetch(:destination_rel_dir))
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_extname
|
|
36
|
-
assert_equal('.css', @@results.fetch(:extname))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_modified_time
|
|
40
|
-
assert_instance_of(Time, @@results.fetch(:modified_time))
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_mtime
|
|
44
|
-
mtime = @@results.fetch(:modified_time)
|
|
45
|
-
assert_equal(mtime.to_i, @@results.fetch(:mtime))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_name
|
|
49
|
-
assert_equal('screen.css', @@results.fetch(:name))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_path
|
|
53
|
-
assert_match(%r{\A/.+/#{STAMP_SOURCE_PATH}\z}, @@results.fetch(:path))
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_placeholders
|
|
57
|
-
assert_equal({}, @@results.fetch(:placeholders))
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def test_relative_path
|
|
61
|
-
assert_equal("/#{STAMP_SOURCE_PATH}", @@results.fetch(:relative_path))
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_to_liquid
|
|
65
|
-
with_development_file do |file|
|
|
66
|
-
drop = file.to_liquid
|
|
67
|
-
assert_equal('screen.css', drop.name)
|
|
68
|
-
assert_equal('.css', drop.extname)
|
|
69
|
-
assert_equal('screen', drop.basename)
|
|
70
|
-
assert_instance_of(Time, drop.modified_time)
|
|
71
|
-
assert_equal("/#{STAMP_SOURCE_PATH}", drop.path)
|
|
72
|
-
assert_nil(drop.collection)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_type
|
|
77
|
-
assert_nil(@@results.fetch(:type))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_url
|
|
81
|
-
assert_equal(STAMP_DESTINATION_PATH, @@results.fetch(:url))
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def test_write?
|
|
85
|
-
assert(@@results.fetch(:write?))
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
private
|
|
89
|
-
|
|
90
|
-
def with_development_file(&block)
|
|
91
|
-
with_fake_site do |site|
|
|
92
|
-
file = DevelopmentFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
|
|
93
|
-
block.call(file)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require_relative '../support/fixture_config'
|
|
5
|
-
require 'jekyll/minibundle/development_file'
|
|
6
|
-
|
|
7
|
-
module Jekyll::Minibundle::Test
|
|
8
|
-
class DevelopmentFileWritingTest < TestCase
|
|
9
|
-
include FixtureConfig
|
|
10
|
-
|
|
11
|
-
def test_raise_error_if_source_file_does_not_exist
|
|
12
|
-
err = assert_raises(ArgumentError) do
|
|
13
|
-
with_fake_site do |site|
|
|
14
|
-
DevelopmentFile.new(site, '_tmp', STAMP_DESTINATION_PATH)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
assert_match(%r{\ADevelopment source file does not exist: .+/_tmp\z}, err.to_s)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_modify_property_determines_if_write_would_succeed
|
|
21
|
-
with_fake_site do |site|
|
|
22
|
-
dev_file = make_development_file(site)
|
|
23
|
-
source = source_path(STAMP_SOURCE_PATH)
|
|
24
|
-
|
|
25
|
-
assert(dev_file.modified?)
|
|
26
|
-
assert(write_file(dev_file))
|
|
27
|
-
|
|
28
|
-
ensure_file_mtime_changes do
|
|
29
|
-
FileUtils.touch(source)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
assert(dev_file.modified?)
|
|
33
|
-
assert(write_file(dev_file))
|
|
34
|
-
|
|
35
|
-
refute(dev_file.modified?)
|
|
36
|
-
refute(write_file(dev_file))
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def make_development_file(site)
|
|
43
|
-
DevelopmentFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def write_file(file)
|
|
47
|
-
file.write(File.join(Dir.pwd, '_site'))
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require 'jekyll/minibundle/environment'
|
|
5
|
-
|
|
6
|
-
module Jekyll::Minibundle::Test
|
|
7
|
-
class EnvironmentTest < TestCase
|
|
8
|
-
def test_find_site_config_returns_value_when_found
|
|
9
|
-
assert_equal(1, Environment.find_site_config(make_site(top: {leaf: 1}), %i[top leaf], Integer))
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_find_site_config_returns_nil_when_not_found
|
|
13
|
-
assert_nil(Environment.find_site_config(make_site, %i[top leaf], Integer))
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_find_site_config_raises_exception_if_found_value_is_of_unexpected_type
|
|
17
|
-
err = assert_raises(RuntimeError) do
|
|
18
|
-
Environment.find_site_config(make_site(top: {leaf: '1'}), %i[top leaf], Integer)
|
|
19
|
-
end
|
|
20
|
-
assert_equal('Invalid site configuration for key top.leaf; expecting type Integer', err.to_s)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def make_site(config = {})
|
|
26
|
-
OpenStruct.new(config: config)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
data/test/unit/files_test.rb
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require 'jekyll/minibundle/files'
|
|
5
|
-
|
|
6
|
-
module Jekyll::Minibundle::Test
|
|
7
|
-
class FilesTest < TestCase
|
|
8
|
-
def test_copy_p
|
|
9
|
-
with_tmp_dir do
|
|
10
|
-
File.write('foo', 'content')
|
|
11
|
-
Files.copy_p('foo', 'bar/zap')
|
|
12
|
-
copied = File.read('bar/zap')
|
|
13
|
-
assert_equal('content', copied)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_read_last_with_non_existing_file_raises_exception
|
|
18
|
-
assert_raises(Errno::ENOENT) { Files.read_last('no-such-file', 4) }
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_read_last_with_empty_file_returns_empty
|
|
22
|
-
Tempfile.open('test') do |file|
|
|
23
|
-
file.close
|
|
24
|
-
|
|
25
|
-
assert_equal('', Files.read_last(file.path, 4))
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_read_last_with_file_bigger_than_max_size_returns_last_bytes
|
|
30
|
-
Tempfile.open('test') do |file|
|
|
31
|
-
file.write("1\n2\n3\n4")
|
|
32
|
-
file.close
|
|
33
|
-
|
|
34
|
-
assert_equal("\n3\n4", Files.read_last(file.path, 4))
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_read_last_with_file_smaller_than_max_size_returns_all_contents
|
|
39
|
-
Tempfile.open('test') do |file|
|
|
40
|
-
file.write("1\n2")
|
|
41
|
-
file.close
|
|
42
|
-
|
|
43
|
-
assert_equal("1\n2", Files.read_last(file.path, 100))
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def test_read_last_with_max_size_zero_or_negative_returns_empty
|
|
48
|
-
Tempfile.open('test') do |file|
|
|
49
|
-
file.write("1\n2")
|
|
50
|
-
file.close
|
|
51
|
-
|
|
52
|
-
assert_equal('', Files.read_last(file.path, 0))
|
|
53
|
-
assert_equal('', Files.read_last(file.path, -1))
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_strip_dot_slash_from_path_start
|
|
58
|
-
assert_equal('path', Files.strip_dot_slash_from_path_start('./path'))
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
data/test/unit/hashes_test.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../support/test_case'
|
|
4
|
-
require 'jekyll/minibundle/hashes'
|
|
5
|
-
|
|
6
|
-
module Jekyll::Minibundle::Test
|
|
7
|
-
class HashesTest < TestCase
|
|
8
|
-
def test_dig_returns_value_when_found
|
|
9
|
-
assert_equal(1, Hashes.dig({top: {middle: {leaf: 1}}}, :top, :middle, :leaf))
|
|
10
|
-
assert_equal(1, Hashes.dig({top: [{}, {leaf: 1}]}, :top, 1, :leaf))
|
|
11
|
-
assert_equal(1, Hashes.dig([{}, {middle: [{}, {leaf: 1}]}], 1, :middle, 1, :leaf))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_dig_returns_same_found_object
|
|
15
|
-
leaf_obj = {leaf: 1}
|
|
16
|
-
assert_same(leaf_obj, Hashes.dig({top: {middle: leaf_obj}}, :top, :middle))
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_dig_returns_nil_when_not_found
|
|
20
|
-
assert_nil(Hashes.dig({}, :no_such))
|
|
21
|
-
assert_nil(Hashes.dig([], 0))
|
|
22
|
-
assert_nil(Hashes.dig({top: {}}, :top, :no_such_leaf))
|
|
23
|
-
assert_nil(Hashes.dig({top: {leaf: 1}}, :top, :no_such_leaf))
|
|
24
|
-
assert_nil(Hashes.dig({top: []}, :top, 0))
|
|
25
|
-
assert_nil(Hashes.dig([{leaf: 1}], 0, :no_such))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def test_dig_returns_nil_for_nil
|
|
29
|
-
assert_nil(Hashes.dig(nil, :no_such_key))
|
|
30
|
-
assert_nil(Hashes.dig(nil, 0))
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_pick_returns_hash_with_specified_keys
|
|
34
|
-
assert_equal({}, Hashes.pick(a: 1, 'b' => 2, 'c' => 3))
|
|
35
|
-
assert_equal({}, Hashes.pick({}))
|
|
36
|
-
assert_equal({a: 1, 'c' => 3}, Hashes.pick({a: 1, 'b' => 2, 'c' => 3}, :a, 'c'))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_pick_raises_exception_if_key_does_not_exist
|
|
40
|
-
assert_raises(KeyError) { Hashes.pick({}, :no_such) }
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|