railpack 1.2.5 → 1.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b13af1329c7192e2a8fd5c83eb0cc9ff07a0edec87b7311dedae0f26b4710975
4
- data.tar.gz: 757f2eedf1421e59d9ae165f13a353918cdad3bad8cee83cdf0bc60078ede4d1
3
+ metadata.gz: 26a629014375c6614d4b3c2e4f9673ff7df37152cb504cc236913d817f147123
4
+ data.tar.gz: ad53fdfe5e81b6cab82e71b423104979d20c6ed49df64fab037861af6a6a47ea
5
5
  SHA512:
6
- metadata.gz: f14bb9cb2f37592089c517a4c8dcd16185bf9fa6d5029344031c58e9f54baa1cea24a0542bb8059f96acc59d54d0aec00b3c783f787ba5188743553b63864777
7
- data.tar.gz: 17748f4d280fbfebefec259db9525daf4609285886a98a0027cd29a53a1c5a8aa0ff3007e05ffed4c96802a048d58cceae3ec2d056ab50f9c953f7d3e276ad40
6
+ metadata.gz: 706d8c94a84dc23d1b3bd7bf88a6df3ef7f075770ef168efef448e4ac136ae82255c33007b4b8aee70ffcda1321fc26bdc1b8a79b447e74349745bdab097e839
7
+ data.tar.gz: e3f6fb48000ad925127355df341824429091c19cb78299bcaa7caf3bcfd4c5a4a277d12a3c7c995dde3f5a8761d64303fef99a0586258e53e01839df96e4e2b3
data/CHANGELOG.md CHANGED
@@ -1,11 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.2.5] - 2026-01-26
4
-
5
- - Add test_config_yaml_file_loading test for YAML config file loading
6
- - Test that Railpack correctly reads config/railpack.yml from Rails.root
7
- - Test bundler selection, environment overrides, and config merging
8
- - All 19 tests passing with 72 assertions
3
+ ## [1.2.7] - 2026-01-26
4
+
5
+ - Add dedicated test files for Manager and Bundler classes
6
+ - manager_test.rb: 13 unit tests for Manager class functionality
7
+ - bundler_test.rb: 17 unit tests for all bundler implementations
8
+ - Test bundler initialization, commands, inheritance, error handling
9
+ - Test manager bundler creation, bundle size calculation, asset manifest generation
10
+ - Improved test organization with separate test files per major class
11
+ - All 43 tests passing with 137 assertions
9
12
 
10
13
  ## [1.2.4] - 2026-01-26
11
14
 
@@ -20,7 +20,7 @@ module Railpack
20
20
  end
21
21
 
22
22
  def name
23
- self.class.name.split('::').last.sub('_bundler', '').downcase
23
+ self.class.name.split('::').last.sub('Bundler', '').downcase
24
24
  end
25
25
 
26
26
  def commands
@@ -1,3 +1,3 @@
1
1
  module Railpack
2
- VERSION = "1.2.5"
2
+ VERSION = "1.2.7"
3
3
  end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'tempfile'
5
+ require 'fileutils'
6
+ require 'pathname'
7
+ require 'railpack'
8
+
9
+ class ConfigTest < Minitest::Test
10
+ def setup
11
+ @temp_dir = Dir.mktmpdir
12
+ @original_rails_root = nil
13
+ if defined?(Rails) && Rails.respond_to?(:root)
14
+ @original_rails_root = Rails.singleton_class.instance_method(:root)
15
+ end
16
+ end
17
+
18
+ def teardown
19
+ FileUtils.remove_entry(@temp_dir) if @temp_dir && Dir.exist?(@temp_dir)
20
+ # Restore original Rails.root method if it was overridden
21
+ if @original_rails_root && defined?(Rails)
22
+ Rails.singleton_class.define_method(:root, @original_rails_root)
23
+ end
24
+ end
25
+
26
+ def test_config_initialization
27
+ config = Railpack::Config.new
28
+ assert_instance_of Railpack::Config, config
29
+ assert_respond_to config, :bundler
30
+ assert_respond_to config, :entrypoint
31
+ end
32
+
33
+ def test_config_default_values
34
+ config = Railpack::Config.new
35
+ assert_equal 'bun', config.bundler
36
+ assert_equal './app/javascript/application.js', config.entrypoint
37
+ assert_equal 'app/assets/builds', config.outdir
38
+ end
39
+
40
+ def test_config_build_flags_unit
41
+ config = Railpack::Config.new
42
+
43
+ # Test build_flags with different environments
44
+ dev_flags = config.build_flags('development')
45
+ prod_flags = config.build_flags('production')
46
+
47
+ # Development should have sourcemap
48
+ assert_includes dev_flags, '--sourcemap'
49
+ # Production should have minify
50
+ assert_includes prod_flags, '--minify'
51
+ end
52
+
53
+ def test_config_build_args_unit
54
+ config = Railpack::Config.new
55
+
56
+ args = config.build_args('development')
57
+ assert_includes args, './app/javascript/application.js'
58
+ assert_includes args, '--outdir=app/assets/builds'
59
+ assert_includes args, '--target=browser'
60
+ assert_includes args, '--format=esm'
61
+ end
62
+
63
+ def test_config_bundler_method
64
+ config = Railpack::Config.new
65
+
66
+ # Test bundler method with different environments
67
+ assert_equal 'bun', config.bundler('development')
68
+ assert_equal 'bun', config.bundler('production')
69
+ end
70
+
71
+ def test_config_for_environment_unit
72
+ config = Railpack::Config.new
73
+
74
+ dev_config = config.for_environment('development')
75
+ prod_config = config.for_environment('production')
76
+
77
+ # Check that environment-specific settings are applied
78
+ assert_equal true, dev_config['sourcemap']
79
+ assert_equal true, prod_config['minify']
80
+ assert_equal false, prod_config['sourcemap']
81
+ end
82
+
83
+ def test_config_yaml_file_loading
84
+ # Test that Railpack can load config from a YAML file
85
+ config_dir = File.join(@temp_dir, 'config')
86
+ FileUtils.mkdir_p(config_dir)
87
+ config_file = File.join(config_dir, 'railpack.yml')
88
+
89
+ File.write(config_file, <<~YAML)
90
+ default:
91
+ bundler: rollup
92
+ target: node
93
+ format: cjs
94
+ entrypoint: "./server.js"
95
+ outdir: "dist"
96
+ minify: false
97
+ development:
98
+ sourcemap: true
99
+ production:
100
+ minify: true
101
+ sourcemap: false
102
+ YAML
103
+
104
+ # Verify the file was created
105
+ assert File.exist?(config_file), "Config file should exist at #{config_file}"
106
+
107
+ # Mock Rails.root to point to our temp directory
108
+ mock_rails_root(@temp_dir)
109
+
110
+ # Create a fresh config instance to test file loading
111
+ config = Railpack::Config.new
112
+
113
+ # Test that the YAML file was loaded correctly
114
+ assert_equal 'rollup', config.bundler
115
+ assert_equal './server.js', config.entrypoint
116
+ assert_equal 'dist', config.outdir
117
+ assert_equal 'node', config.target
118
+ assert_equal 'cjs', config.format
119
+ assert_equal false, config.minify
120
+
121
+ # Test environment overrides
122
+ dev_config = config.for_environment('development')
123
+ prod_config = config.for_environment('production')
124
+
125
+ assert_equal true, dev_config['sourcemap']
126
+ assert_equal true, prod_config['minify']
127
+ assert_equal false, prod_config['sourcemap']
128
+ end
129
+
130
+ def test_config_environment_overrides
131
+ # Test environment override logic with default config
132
+ config = Railpack::Config.new
133
+ dev_config = config.for_environment('development')
134
+ prod_config = config.for_environment('production')
135
+
136
+ # Development should have sourcemap enabled by default
137
+ assert_equal true, dev_config['sourcemap']
138
+ # Production should have minify enabled by default
139
+ assert_equal true, prod_config['minify']
140
+ end
141
+
142
+ def test_config_error_handling
143
+ # Test config error handling for invalid YAML
144
+ config_dir = File.join(@temp_dir, 'config')
145
+ FileUtils.mkdir_p(config_dir)
146
+ config_file = File.join(config_dir, 'railpack.yml')
147
+ File.write(config_file, "invalid: yaml: content: [")
148
+
149
+ mock_rails_root(@temp_dir)
150
+
151
+ # This should raise an error for invalid YAML
152
+ assert_raises(Railpack::Config::Error) do
153
+ Railpack::Config.new
154
+ end
155
+ end
156
+
157
+ def test_config_method_missing
158
+ config = Railpack::Config.new
159
+
160
+ # Test that config responds to dynamic methods
161
+ assert_respond_to config, :target
162
+ assert_respond_to config, :format
163
+ assert_equal 'browser', config.target
164
+ assert_equal 'esm', config.format
165
+ end
166
+
167
+ private
168
+
169
+ def mock_rails_root(path)
170
+ rails_module = if defined?(Rails)
171
+ Rails
172
+ else
173
+ Object.const_set(:Rails, Module.new)
174
+ end
175
+
176
+ rails_module.define_singleton_method(:root) { Pathname.new(path) }
177
+ end
178
+ end
@@ -38,190 +38,7 @@ class RailpackTest < Minitest::Test
38
38
  assert_instance_of Railpack::Manager, Railpack.manager
39
39
  end
40
40
 
41
- def test_bundler_support
42
- assert_includes Railpack::Manager::BUNDLERS.keys, 'bun'
43
- assert_includes Railpack::Manager::BUNDLERS.keys, 'esbuild'
44
- assert_includes Railpack::Manager::BUNDLERS.keys, 'rollup'
45
- assert_includes Railpack::Manager::BUNDLERS.keys, 'webpack'
46
- assert_equal Railpack::BunBundler, Railpack::Manager::BUNDLERS['bun']
47
- assert_equal Railpack::EsbuildBundler, Railpack::Manager::BUNDLERS['esbuild']
48
- assert_equal Railpack::RollupBundler, Railpack::Manager::BUNDLERS['rollup']
49
- assert_equal Railpack::WebpackBundler, Railpack::Manager::BUNDLERS['webpack']
50
- end
51
-
52
- def test_config_loading_without_rails
53
- # Test config loading without Rails.root
54
- config = Railpack::Config.new
55
- assert_equal 'bun', config.bundler
56
- assert_equal './app/javascript/application.js', config.entrypoint
57
- end
58
-
59
- def test_config_yaml_file_loading
60
- # Test that Railpack can load config from a YAML file
61
- config_dir = File.join(@temp_dir, 'config')
62
- FileUtils.mkdir_p(config_dir)
63
- config_file = File.join(config_dir, 'railpack.yml')
64
-
65
- File.write(config_file, <<~YAML)
66
- default:
67
- bundler: rollup
68
- target: node
69
- format: cjs
70
- entrypoint: "./server.js"
71
- outdir: "dist"
72
- minify: false
73
- development:
74
- sourcemap: true
75
- production:
76
- minify: true
77
- sourcemap: false
78
- YAML
79
-
80
- # Verify the file was created
81
- assert File.exist?(config_file), "Config file should exist at #{config_file}"
82
-
83
- # Mock Rails.root to point to our temp directory
84
- mock_rails_root(@temp_dir)
85
-
86
- # Create a fresh config instance to test file loading
87
- config = Railpack::Config.new
88
-
89
-
90
-
91
- # Test that the YAML file was loaded correctly
92
- assert_equal 'rollup', config.bundler
93
- assert_equal './server.js', config.entrypoint
94
- assert_equal 'dist', config.outdir
95
- assert_equal 'node', config.target
96
- assert_equal 'cjs', config.format
97
- assert_equal false, config.minify
98
-
99
- # Test environment overrides
100
- dev_config = config.for_environment('development')
101
- prod_config = config.for_environment('production')
102
-
103
- assert_equal true, dev_config['sourcemap']
104
- assert_equal true, prod_config['minify']
105
- assert_equal false, prod_config['sourcemap']
106
- end
107
-
108
- def test_config_environment_overrides
109
- # Test environment override logic with default config
110
- config = Railpack::Config.new
111
- dev_config = config.for_environment('development')
112
- prod_config = config.for_environment('production')
113
-
114
- # Development should have sourcemap enabled by default
115
- assert_equal true, dev_config['sourcemap']
116
- # Production should have minify enabled by default
117
- assert_equal true, prod_config['minify']
118
- end
119
-
120
- def test_config_build_flags
121
- # Test build flags generation with default config
122
- config = Railpack::Config.new
123
- flags = config.build_flags
124
-
125
- assert_includes flags, '--target=browser'
126
- assert_includes flags, '--format=esm'
127
- end
128
41
 
129
- def test_config_build_args
130
- # Test build args generation with default config
131
- config = Railpack::Config.new
132
- args = config.build_args
133
-
134
- assert_includes args, './app/javascript/application.js'
135
- assert_includes args, '--outdir=app/assets/builds'
136
- assert_includes args, '--target=browser'
137
- assert_includes args, '--format=esm'
138
- end
139
-
140
- def test_manager_bundle_size_calculation
141
- # Create test output directory with fake assets
142
- outdir = File.join(@temp_dir, 'builds')
143
- FileUtils.mkdir_p(outdir)
144
-
145
- # Create fake JS and CSS files
146
- File.write(File.join(outdir, 'app.js'), 'console.log("test");')
147
- File.write(File.join(outdir, 'app.css'), 'body { color: red; }')
148
- File.write(File.join(outdir, 'app.js.map'), '{"version":3}')
149
-
150
- config = { 'outdir' => outdir }
151
- manager = Railpack::Manager.new
152
-
153
- size = manager.send(:calculate_bundle_size, config)
154
- assert size.is_a?(Float)
155
- assert size > 0
156
- end
157
-
158
- def test_manager_asset_manifest_generation
159
- outdir = File.join(@temp_dir, 'builds')
160
- FileUtils.mkdir_p(outdir)
161
-
162
- # Create fake built assets
163
- File.write(File.join(outdir, 'application.js'), 'console.log("app");')
164
- File.write(File.join(outdir, 'application.css'), 'body { color: blue; }')
165
-
166
- config = { 'outdir' => outdir }
167
- manager = Railpack::Manager.new
168
-
169
- manager.send(:generate_asset_manifest, config)
170
-
171
- manifest_path = File.join(outdir, '.manifest.json')
172
- assert File.exist?(manifest_path)
173
-
174
- manifest = JSON.parse(File.read(manifest_path))
175
- assert manifest.key?('application.js')
176
- assert manifest.key?('application.css')
177
- assert manifest['application.js']['logical_path'] == 'application.js'
178
- end
179
-
180
- def test_bundler_base_class
181
- bundler = Railpack::Bundler.new({})
182
-
183
- assert_respond_to bundler, :build!
184
- assert_respond_to bundler, :watch
185
- assert_respond_to bundler, :install!
186
- assert_respond_to bundler, :name
187
- assert_respond_to bundler, :commands
188
- end
189
-
190
- def test_bun_bundler_commands
191
- bundler = Railpack::BunBundler.new({})
192
- commands = bundler.send(:commands)
193
-
194
- assert_equal 'bun run build', commands[:build]
195
- assert_equal 'bun run watch', commands[:watch]
196
- assert_equal 'bun install', commands[:install]
197
- end
198
-
199
- def test_esbuild_bundler_commands
200
- bundler = Railpack::EsbuildBundler.new({})
201
- commands = bundler.send(:commands)
202
-
203
- assert_equal 'esbuild', commands[:build]
204
- assert_equal 'esbuild --watch', commands[:watch]
205
- assert_equal 'npm install', commands[:install]
206
- end
207
-
208
- def test_rollup_bundler_commands
209
- bundler = Railpack::RollupBundler.new({})
210
- commands = bundler.send(:commands)
211
-
212
- assert_equal 'rollup', commands[:build]
213
- assert_equal 'rollup --watch', commands[:watch]
214
- assert_equal 'npm install', commands[:install]
215
- end
216
-
217
- def test_webpack_bundler_commands
218
- bundler = Railpack::WebpackBundler.new({})
219
- commands = bundler.send(:commands)
220
-
221
- assert_equal 'webpack', commands[:build]
222
- assert_equal 'webpack --watch', commands[:watch]
223
- assert_equal 'npm install', commands[:install]
224
- end
225
42
 
226
43
  def test_event_hooks
227
44
  events = []
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - 21tycoons LLC
@@ -48,6 +48,7 @@ files:
48
48
  - lib/railpack/version.rb
49
49
  - lib/tasks/railpack.rake
50
50
  - sig/railpack.rbs
51
+ - test/config_test.rb
51
52
  - test/railpack_test.rb
52
53
  homepage: https://github.com/21tycoons/railpack
53
54
  licenses: