jekyll-minibundle 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ module Jekyll::Minibundle::Test
3
3
  STATIC_FILE_API_PROPERTIES = [
4
4
  :defaults,
5
5
  :destination_rel_dir,
6
+ :name,
6
7
  :extname,
7
8
  :modified_time,
8
9
  :mtime,
@@ -40,10 +40,14 @@ module Jekyll::Minibundle::Test
40
40
  IO.write(file, YAML.load_file(file).merge(hash).to_yaml)
41
41
  end
42
42
 
43
- def mtime_of(path)
43
+ def file_mtime_of(path)
44
44
  File.stat(path).mtime
45
45
  end
46
46
 
47
+ def file_permissions_of(path)
48
+ File.stat(path).mode & 0o777
49
+ end
50
+
47
51
  def with_env(env)
48
52
  org_env = {}
49
53
  env.each do |k, v|
@@ -55,12 +59,24 @@ module Jekyll::Minibundle::Test
55
59
  org_env.each { |k, v| ENV[k] = v }
56
60
  end
57
61
 
58
- def with_site_dir(&block)
62
+ def with_umask(cmask)
63
+ org_cmask = File.umask
64
+ File.umask(cmask)
65
+ yield
66
+ ensure
67
+ File.umask(org_cmask)
68
+ end
69
+
70
+ def with_tmp_dir(&block)
59
71
  Dir.mktmpdir('jekyll-minibundle-test-site-') do |dir|
60
- Dir.chdir(dir) do
61
- _copy_fixture_site_dir(Dir.pwd)
62
- block.call(dir)
63
- end
72
+ Dir.chdir(dir, &block)
73
+ end
74
+ end
75
+
76
+ def with_site_dir(&block)
77
+ with_tmp_dir do |dir|
78
+ _copy_fixture_site_dir(dir)
79
+ block.call(dir)
64
80
  end
65
81
  end
66
82
 
@@ -9,54 +9,61 @@ module Jekyll::Minibundle::Test
9
9
  include StaticFileAPIConfig
10
10
 
11
11
  def setup
12
- @results ||= with_fake_site do |site|
12
+ @@results ||= with_fake_site do |site|
13
13
  file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments))
14
+ capture_io { file.destination_path_for_markup }
14
15
  get_send_results(file, STATIC_FILE_API_PROPERTIES)
15
16
  end
16
17
  end
17
18
 
18
19
  def test_defaults
19
- assert_equal({}, @results.fetch(:defaults))
20
+ assert_equal({}, @@results.fetch(:defaults))
20
21
  end
21
22
 
22
23
  def test_destination_rel_dir
23
- assert_equal 'assets', @results.fetch(:destination_rel_dir)
24
+ assert_equal 'assets', @@results.fetch(:destination_rel_dir)
25
+ end
26
+
27
+ def test_name
28
+ assert_equal "site-#{JS_BUNDLE_FINGERPRINT}.js", @@results.fetch(:name)
24
29
  end
25
30
 
26
31
  def test_extname
27
- assert_equal '.js', @results.fetch(:extname)
32
+ assert_equal '.js', @@results.fetch(:extname)
28
33
  end
29
34
 
30
35
  def test_modified_time
31
- assert_instance_of Time, @results.fetch(:modified_time)
36
+ assert_instance_of Time, @@results.fetch(:modified_time)
32
37
  end
33
38
 
34
39
  def test_mtime
35
- mtime = @results.fetch(:modified_time)
36
- assert_equal mtime.to_i, @results.fetch(:mtime)
40
+ mtime = @@results.fetch(:modified_time)
41
+ assert_equal mtime.to_i, @@results.fetch(:mtime)
37
42
  end
38
43
 
39
44
  def test_placeholders
40
- assert_equal({}, @results.fetch(:placeholders))
45
+ assert_equal({}, @@results.fetch(:placeholders))
41
46
  end
42
47
 
43
48
  def test_relative_path
44
- assert_match(%r{/jekyll-minibundle-.+\.js\z}, @results.fetch(:relative_path))
49
+ assert_match(%r{/jekyll-minibundle-.+\.js\z}, @@results.fetch(:relative_path))
45
50
  end
46
51
 
47
52
  def test_to_liquid
48
- hash = @results.fetch(:to_liquid)
49
- assert_match(%r{/jekyll-minibundle-.+\.js\z}, hash['path'])
50
- assert_instance_of Time, hash['modified_time']
51
- assert_equal '.js', hash['extname']
53
+ hash = @@results.fetch(:to_liquid)
54
+ assert_equal "site-#{JS_BUNDLE_FINGERPRINT}", hash.fetch('basename')
55
+ assert_equal "site-#{JS_BUNDLE_FINGERPRINT}.js", hash.fetch('name')
56
+ assert_equal '.js', hash.fetch('extname')
57
+ assert_instance_of Time, hash.fetch('modified_time')
58
+ assert_match(%r{/jekyll-minibundle-.+\.js\z}, hash.fetch('path'))
52
59
  end
53
60
 
54
61
  def test_type
55
- assert_nil @results.fetch(:type)
62
+ assert_nil @@results.fetch(:type)
56
63
  end
57
64
 
58
65
  def test_write?
59
- assert @results.fetch(:write?)
66
+ assert @@results.fetch(:write?)
60
67
  end
61
68
 
62
69
  private
@@ -6,7 +6,7 @@ module Jekyll::Minibundle::Test
6
6
  class BundleFileWritingTest < TestCase
7
7
  include FixtureConfig
8
8
 
9
- def test_calling_markup_determines_fingerprint_and_destination_write
9
+ def test_calling_destination_path_for_markup_determines_fingerprint_and_destination_write
10
10
  with_fake_site do |site|
11
11
  bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
12
12
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
@@ -16,7 +16,7 @@ module Jekyll::Minibundle::Test
16
16
 
17
17
  assert bundle_file.write('_site')
18
18
 
19
- org_mtime = mtime_of(old_destination)
19
+ org_mtime = file_mtime_of(old_destination)
20
20
 
21
21
  assert_equal 1, get_minifier_cmd_count
22
22
 
@@ -26,7 +26,7 @@ module Jekyll::Minibundle::Test
26
26
  # preserve fingerprint and content seen in last markup phase
27
27
  refute bundle_file.write('_site')
28
28
  assert_equal org_markup_path, last_markup_path
29
- assert_equal org_mtime, mtime_of(old_destination)
29
+ assert_equal org_mtime, file_mtime_of(old_destination)
30
30
  assert_equal 1, get_minifier_cmd_count
31
31
 
32
32
  capture_io { last_markup_path = bundle_file.destination_path_for_markup }
@@ -37,12 +37,12 @@ module Jekyll::Minibundle::Test
37
37
 
38
38
  # see updated fingerprint in the next round
39
39
  refute_equal org_markup_path, last_markup_path
40
- assert_operator mtime_of(new_destination), :>, org_mtime
40
+ assert_operator file_mtime_of(new_destination), :>, org_mtime
41
41
  assert_equal 2, get_minifier_cmd_count
42
42
  end
43
43
  end
44
44
 
45
- def test_many_consecutive_markup_calls_trigger_one_destination_write
45
+ def test_many_consecutive_destination_path_for_markup_calls_trigger_one_destination_write
46
46
  with_fake_site do |site|
47
47
  bundle_file = BundleFile.new(site, bundle_config(minifier_cmd_to_remove_comments_and_count))
48
48
  source = source_path(JS_BUNDLE_SOURCE_DIR, 'app.js')
@@ -53,7 +53,7 @@ module Jekyll::Minibundle::Test
53
53
 
54
54
  assert bundle_file.write('_site')
55
55
 
56
- org_mtime = mtime_of(destination)
56
+ org_mtime = file_mtime_of(destination)
57
57
 
58
58
  assert_equal 1, get_minifier_cmd_count
59
59
 
@@ -63,7 +63,7 @@ module Jekyll::Minibundle::Test
63
63
 
64
64
  assert bundle_file.write('_site')
65
65
  assert_equal org_markup_path, last_markup_path
66
- assert_operator mtime_of(destination), :>, org_mtime
66
+ assert_operator file_mtime_of(destination), :>, org_mtime
67
67
  assert_equal 2, get_minifier_cmd_count
68
68
  end
69
69
  end
@@ -9,7 +9,7 @@ module Jekyll::Minibundle::Test
9
9
  include StaticFileAPIConfig
10
10
 
11
11
  def setup
12
- @results ||= with_fake_site do |site|
12
+ @@results ||= with_fake_site do |site|
13
13
  files = DevelopmentFileCollection.new(site, bundle_config).instance_variable_get('@files')
14
14
  {
15
15
  dependency: get_send_results(files[0], STATIC_FILE_API_PROPERTIES),
@@ -19,63 +19,72 @@ module Jekyll::Minibundle::Test
19
19
  end
20
20
 
21
21
  def test_defaults
22
- assert_equal({}, @results.fetch(:dependency).fetch(:defaults))
23
- assert_equal({}, @results.fetch(:app).fetch(:defaults))
22
+ assert_equal({}, @@results.fetch(:dependency).fetch(:defaults))
23
+ assert_equal({}, @@results.fetch(:app).fetch(:defaults))
24
24
  end
25
25
 
26
26
  def test_destination_rel_dir
27
- assert_equal 'assets/site', @results.fetch(:dependency).fetch(:destination_rel_dir)
28
- assert_equal 'assets/site', @results.fetch(:app).fetch(:destination_rel_dir)
27
+ assert_equal 'assets/site', @@results.fetch(:dependency).fetch(:destination_rel_dir)
28
+ assert_equal 'assets/site', @@results.fetch(:app).fetch(:destination_rel_dir)
29
+ end
30
+
31
+ def test_name
32
+ assert_equal 'dependency.js', @@results.fetch(:dependency).fetch(:name)
33
+ assert_equal 'app.js', @@results.fetch(:app).fetch(:name)
29
34
  end
30
35
 
31
36
  def test_extname
32
- assert_equal '.js', @results.fetch(:dependency).fetch(:extname)
33
- assert_equal '.js', @results.fetch(:app).fetch(:extname)
37
+ assert_equal '.js', @@results.fetch(:dependency).fetch(:extname)
38
+ assert_equal '.js', @@results.fetch(:app).fetch(:extname)
34
39
  end
35
40
 
36
41
  def test_modified_time
37
- assert_instance_of Time, @results.fetch(:dependency).fetch(:modified_time)
38
- assert_instance_of Time, @results.fetch(:app).fetch(:modified_time)
42
+ assert_instance_of Time, @@results.fetch(:dependency).fetch(:modified_time)
43
+ assert_instance_of Time, @@results.fetch(:app).fetch(:modified_time)
39
44
  end
40
45
 
41
46
  def test_mtime
42
- dep_mtime = @results.fetch(:dependency).fetch(:modified_time)
43
- assert_equal dep_mtime.to_i, @results.fetch(:dependency).fetch(:mtime)
47
+ dep_mtime = @@results.fetch(:dependency).fetch(:modified_time)
48
+ assert_equal dep_mtime.to_i, @@results.fetch(:dependency).fetch(:mtime)
44
49
 
45
- app_mtime = @results.fetch(:app).fetch(:modified_time)
46
- assert_equal app_mtime.to_i, @results.fetch(:app).fetch(:mtime)
50
+ app_mtime = @@results.fetch(:app).fetch(:modified_time)
51
+ assert_equal app_mtime.to_i, @@results.fetch(:app).fetch(:mtime)
47
52
  end
48
53
 
49
54
  def test_placeholders
50
- assert_equal({}, @results.fetch(:dependency).fetch(:placeholders))
51
- assert_equal({}, @results.fetch(:app).fetch(:placeholders))
55
+ assert_equal({}, @@results.fetch(:dependency).fetch(:placeholders))
56
+ assert_equal({}, @@results.fetch(:app).fetch(:placeholders))
52
57
  end
53
58
 
54
59
  def test_relative_path
55
- assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/dependency.js", @results.fetch(:dependency).fetch(:relative_path)
56
- assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/app.js", @results.fetch(:app).fetch(:relative_path)
60
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/dependency.js", @@results.fetch(:dependency).fetch(:relative_path)
61
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/app.js", @@results.fetch(:app).fetch(:relative_path)
57
62
  end
58
63
 
59
64
  def test_to_liquid
60
- hash = @results.fetch(:dependency).fetch(:to_liquid)
61
- assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/dependency.js", hash['path']
62
- assert_instance_of Time, hash['modified_time']
63
- assert_equal '.js', hash['extname']
64
-
65
- hash = @results.fetch(:app).fetch(:to_liquid)
66
- assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/app.js", hash['path']
67
- assert_instance_of Time, hash['modified_time']
68
- assert_equal '.js', hash['extname']
65
+ hash = @@results.fetch(:dependency).fetch(:to_liquid)
66
+ assert_equal 'dependency', hash.fetch('basename')
67
+ assert_equal 'dependency.js', hash.fetch('name')
68
+ assert_equal '.js', hash.fetch('extname')
69
+ assert_instance_of Time, hash.fetch('modified_time')
70
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/dependency.js", hash.fetch('path')
71
+
72
+ hash = @@results.fetch(:app).fetch(:to_liquid)
73
+ assert_equal 'app', hash.fetch('basename')
74
+ assert_equal 'app.js', hash.fetch('name')
75
+ assert_equal '.js', hash.fetch('extname')
76
+ assert_instance_of Time, hash.fetch('modified_time')
77
+ assert_equal "/#{JS_BUNDLE_SOURCE_DIR}/app.js", hash.fetch('path')
69
78
  end
70
79
 
71
80
  def test_type
72
- assert_nil @results.fetch(:dependency).fetch(:type)
73
- assert_nil @results.fetch(:app).fetch(:type)
81
+ assert_nil @@results.fetch(:dependency).fetch(:type)
82
+ assert_nil @@results.fetch(:app).fetch(:type)
74
83
  end
75
84
 
76
85
  def test_write?
77
- assert @results.fetch(:dependency).fetch(:write?)
78
- assert @results.fetch(:app).fetch(:write?)
86
+ assert @@results.fetch(:dependency).fetch(:write?)
87
+ assert @@results.fetch(:app).fetch(:write?)
79
88
  end
80
89
 
81
90
  private
@@ -17,10 +17,81 @@ module Jekyll::Minibundle::Test
17
17
  assert_empty missing_api_methods(StampFile)
18
18
  end
19
19
 
20
+ def test_development_file_has_same_to_liquid_hash_keys_as_static_file
21
+ with_empty_site do |site|
22
+ FileUtils.touch('static.txt')
23
+ FileUtils.touch('dev.js')
24
+
25
+ expected_keys = make_static_file(site, 'static.txt').to_liquid.keys.sort
26
+ actual_keys = make_development_file(site, 'dev.js').to_liquid.keys.sort
27
+
28
+ assert_equal expected_keys, actual_keys
29
+ end
30
+ end
31
+
32
+ def test_bundle_file_has_same_to_liquid_hash_keys_as_static_file
33
+ with_empty_site do |site|
34
+ FileUtils.touch('static.txt')
35
+ FileUtils.touch('dependency.js')
36
+ FileUtils.touch('app.js')
37
+
38
+ expected_keys = make_static_file(site, 'static.txt').to_liquid.keys.sort
39
+ actual_keys = make_bundle_file(site, %w{dependency app}).to_liquid.keys.sort
40
+
41
+ assert_equal expected_keys, actual_keys
42
+ end
43
+ end
44
+
45
+ def test_stamp_file_has_same_to_liquid_hash_keys_as_static_file
46
+ with_empty_site do |site|
47
+ FileUtils.touch('static.txt')
48
+ FileUtils.touch('stamp.js')
49
+
50
+ expected_keys = make_static_file(site, 'static.txt').to_liquid.keys.sort
51
+ actual_keys = make_stamp_file(site, 'stamp.js').to_liquid.keys.sort
52
+
53
+ assert_equal expected_keys, actual_keys
54
+ end
55
+ end
56
+
20
57
  private
21
58
 
22
59
  def missing_api_methods(clazz)
23
60
  Jekyll::StaticFile.public_instance_methods - clazz.public_instance_methods
24
61
  end
62
+
63
+ def with_empty_site(&block)
64
+ with_tmp_dir do |dir|
65
+ block.call(new_fake_site(dir))
66
+ end
67
+ end
68
+
69
+ def make_static_file(site, filename)
70
+ ::Jekyll::StaticFile.new(
71
+ site,
72
+ nil,
73
+ nil,
74
+ filename
75
+ )
76
+ end
77
+
78
+ def make_development_file(site, filename)
79
+ DevelopmentFile.new(site, filename, filename)
80
+ end
81
+
82
+ def make_bundle_file(site, assets)
83
+ BundleFile.new(
84
+ site,
85
+ 'type' => :js,
86
+ 'source_dir' => '',
87
+ 'assets' => assets,
88
+ 'destination_path' => 'bundle.js',
89
+ 'minifier_cmd' => 'false'
90
+ )
91
+ end
92
+
93
+ def make_stamp_file(site, filename)
94
+ StampFile.new(site, filename, filename)
95
+ end
25
96
  end
26
97
  end
@@ -9,54 +9,61 @@ module Jekyll::Minibundle::Test
9
9
  include StaticFileAPIConfig
10
10
 
11
11
  def setup
12
- @results ||= with_fake_site do |site|
12
+ @@results ||= with_fake_site do |site|
13
13
  file = StampFile.new(site, STAMP_SOURCE_PATH, STAMP_DESTINATION_PATH)
14
+ file.destination_path_for_markup
14
15
  get_send_results(file, STATIC_FILE_API_PROPERTIES)
15
16
  end
16
17
  end
17
18
 
18
19
  def test_defaults
19
- assert_equal({}, @results.fetch(:defaults))
20
+ assert_equal({}, @@results.fetch(:defaults))
20
21
  end
21
22
 
22
23
  def test_destination_rel_dir
23
- assert_equal 'assets', @results.fetch(:destination_rel_dir)
24
+ assert_equal 'assets', @@results.fetch(:destination_rel_dir)
25
+ end
26
+
27
+ def test_name
28
+ assert_equal "screen-#{STAMP_FINGERPRINT}.css", @@results.fetch(:name)
24
29
  end
25
30
 
26
31
  def test_extname
27
- assert_equal '.css', @results.fetch(:extname)
32
+ assert_equal '.css', @@results.fetch(:extname)
28
33
  end
29
34
 
30
35
  def test_modified_time
31
- assert_instance_of Time, @results.fetch(:modified_time)
36
+ assert_instance_of Time, @@results.fetch(:modified_time)
32
37
  end
33
38
 
34
39
  def test_mtime
35
- mtime = @results.fetch(:modified_time)
36
- assert_equal mtime.to_i, @results.fetch(:mtime)
40
+ mtime = @@results.fetch(:modified_time)
41
+ assert_equal mtime.to_i, @@results.fetch(:mtime)
37
42
  end
38
43
 
39
44
  def test_placeholders
40
- assert_equal({}, @results.fetch(:placeholders))
45
+ assert_equal({}, @@results.fetch(:placeholders))
41
46
  end
42
47
 
43
48
  def test_relative_path
44
- assert_equal "/#{STAMP_SOURCE_PATH}", @results.fetch(:relative_path)
49
+ assert_equal "/#{STAMP_SOURCE_PATH}", @@results.fetch(:relative_path)
45
50
  end
46
51
 
47
52
  def test_to_liquid
48
- hash = @results.fetch(:to_liquid)
49
- assert_equal "/#{STAMP_SOURCE_PATH}", hash['path']
50
- assert_instance_of Time, hash['modified_time']
51
- assert_equal '.css', hash['extname']
53
+ hash = @@results.fetch(:to_liquid)
54
+ assert_equal "screen-#{STAMP_FINGERPRINT}", hash.fetch('basename')
55
+ assert_equal "screen-#{STAMP_FINGERPRINT}.css", hash.fetch('name')
56
+ assert_equal '.css', hash.fetch('extname')
57
+ assert_instance_of Time, hash.fetch('modified_time')
58
+ assert_equal "/#{STAMP_SOURCE_PATH}", hash.fetch('path')
52
59
  end
53
60
 
54
61
  def test_type
55
- assert_nil @results.fetch(:type)
62
+ assert_nil @@results.fetch(:type)
56
63
  end
57
64
 
58
65
  def test_write?
59
- assert @results.fetch(:write?)
66
+ assert @@results.fetch(:write?)
60
67
  end
61
68
  end
62
69
  end