shakapacker 6.2.0 → 6.3.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.
data/test/helper_test.rb CHANGED
@@ -115,6 +115,28 @@ class HelperTest < ActionView::TestCase
115
115
  javascript_pack_tag("application", "bootstrap", defer: false)
116
116
  end
117
117
 
118
+ def test_javascript_pack_with_append
119
+ append_javascript_pack_tag("bootstrap", defer: false)
120
+ assert_equal \
121
+ %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
122
+ %(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>\n) +
123
+ %(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>\n) +
124
+ %(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
125
+ javascript_pack_tag("application")
126
+ end
127
+
128
+ def test_append_javascript_pack_tag_raises
129
+ error = assert_raises do
130
+ javascript_pack_tag("application")
131
+ append_javascript_pack_tag("bootstrap", defer: false)
132
+ end
133
+
134
+ assert_equal \
135
+ "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
136
+ "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
137
+ error.message
138
+ end
139
+
118
140
  def test_javascript_pack_tag_splat
119
141
  assert_equal \
120
142
  %(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>\n) +
@@ -8,7 +8,7 @@ class ManifestTest < Minitest::Test
8
8
  Webpacker.manifest.lookup!(asset_file)
9
9
  end
10
10
 
11
- assert_match "Webpacker can't find #{asset_file} in #{manifest_path}", error.message
11
+ assert_match "Shakapacker can't find #{asset_file} in #{manifest_path}", error.message
12
12
  end
13
13
 
14
14
  def test_lookup_with_type_exception!
@@ -18,7 +18,7 @@ class ManifestTest < Minitest::Test
18
18
  Webpacker.manifest.lookup!(asset_file, type: :javascript)
19
19
  end
20
20
 
21
- assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
21
+ assert_match "Shakapacker can't find #{asset_file}.js in #{manifest_path}", error.message
22
22
  end
23
23
 
24
24
  def test_lookup_success!
@@ -60,7 +60,7 @@ class ManifestTest < Minitest::Test
60
60
  Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
61
61
  end
62
62
 
63
- assert_match "Webpacker can't find #{asset_file}.js in #{manifest_path}", error.message
63
+ assert_match "Shakapacker can't find #{asset_file}.js in #{manifest_path}", error.message
64
64
  end
65
65
 
66
66
  def test_lookup_entrypoint
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ class MtimeStrategyTest < Minitest::Test
4
+ def setup
5
+ @mtime_strategy = Webpacker::MtimeStrategy.new
6
+ @manifest_timestamp = Time.parse("2021-01-01 12:34:56 UTC")
7
+ end
8
+
9
+ def with_stubs(latest_timestamp:, manifest_exists: true)
10
+ @mtime_strategy.stub :latest_modified_timestamp, latest_timestamp do
11
+ FileTest.stub :exist?, manifest_exists do
12
+ File.stub :mtime, @manifest_timestamp do
13
+ yield
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def test_freshness_when_manifest_missing
20
+ latest_timestamp = @manifest_timestamp + 3600
21
+
22
+ with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
23
+ assert @mtime_strategy.stale?
24
+ end
25
+ end
26
+
27
+ def test_freshness_when_manifest_older
28
+ latest_timestamp = @manifest_timestamp + 3600
29
+
30
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
31
+ assert @mtime_strategy.stale?
32
+ end
33
+ end
34
+
35
+ def test_freshness_when_manifest_newer
36
+ latest_timestamp = @manifest_timestamp - 3600
37
+
38
+ with_stubs(latest_timestamp: latest_timestamp.to_i) do
39
+ assert @mtime_strategy.fresh?
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ # Note: You must restart bin/webpacker-dev-server for changes to take effect
2
+
3
+ default: &default
4
+ webpacker_precompile: false
5
+
6
+ production:
7
+ <<: *default