railpack 1.2.6 → 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 +4 -4
- data/CHANGELOG.md +9 -8
- data/lib/railpack/bundler.rb +1 -1
- data/lib/railpack/version.rb +1 -1
- data/test/config_test.rb +178 -0
- data/test/railpack_test.rb +0 -97
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26a629014375c6614d4b3c2e4f9673ff7df37152cb504cc236913d817f147123
|
|
4
|
+
data.tar.gz: ad53fdfe5e81b6cab82e71b423104979d20c6ed49df64fab037861af6a6a47ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 706d8c94a84dc23d1b3bd7bf88a6df3ef7f075770ef168efef448e4ac136ae82255c33007b4b8aee70ffcda1321fc26bdc1b8a79b447e74349745bdab097e839
|
|
7
|
+
data.tar.gz: e3f6fb48000ad925127355df341824429091c19cb78299bcaa7caf3bcfd4c5a4a277d12a3c7c995dde3f5a8761d64303fef99a0586258e53e01839df96e4e2b3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
-
## [1.2.
|
|
4
|
-
|
|
5
|
-
- Add dedicated
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
- Test
|
|
9
|
-
-
|
|
10
|
-
-
|
|
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
|
|
11
12
|
|
|
12
13
|
## [1.2.4] - 2026-01-26
|
|
13
14
|
|
data/lib/railpack/bundler.rb
CHANGED
data/lib/railpack/version.rb
CHANGED
data/test/config_test.rb
ADDED
|
@@ -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
|
data/test/railpack_test.rb
CHANGED
|
@@ -38,104 +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
|
-
|
|
53
|
-
|
|
54
|
-
def test_manager_bundle_size_calculation
|
|
55
|
-
# Create test output directory with fake assets
|
|
56
|
-
outdir = File.join(@temp_dir, 'builds')
|
|
57
|
-
FileUtils.mkdir_p(outdir)
|
|
58
|
-
|
|
59
|
-
# Create fake JS and CSS files
|
|
60
|
-
File.write(File.join(outdir, 'app.js'), 'console.log("test");')
|
|
61
|
-
File.write(File.join(outdir, 'app.css'), 'body { color: red; }')
|
|
62
|
-
File.write(File.join(outdir, 'app.js.map'), '{"version":3}')
|
|
63
|
-
|
|
64
|
-
config = { 'outdir' => outdir }
|
|
65
|
-
manager = Railpack::Manager.new
|
|
66
|
-
|
|
67
|
-
size = manager.send(:calculate_bundle_size, config)
|
|
68
|
-
assert size.is_a?(Float)
|
|
69
|
-
assert size > 0
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_manager_asset_manifest_generation
|
|
73
|
-
outdir = File.join(@temp_dir, 'builds')
|
|
74
|
-
FileUtils.mkdir_p(outdir)
|
|
75
|
-
|
|
76
|
-
# Create fake built assets
|
|
77
|
-
File.write(File.join(outdir, 'application.js'), 'console.log("app");')
|
|
78
|
-
File.write(File.join(outdir, 'application.css'), 'body { color: blue; }')
|
|
79
|
-
|
|
80
|
-
config = { 'outdir' => outdir }
|
|
81
|
-
manager = Railpack::Manager.new
|
|
82
|
-
|
|
83
|
-
manager.send(:generate_asset_manifest, config)
|
|
84
41
|
|
|
85
|
-
manifest_path = File.join(outdir, '.manifest.json')
|
|
86
|
-
assert File.exist?(manifest_path)
|
|
87
|
-
|
|
88
|
-
manifest = JSON.parse(File.read(manifest_path))
|
|
89
|
-
assert manifest.key?('application.js')
|
|
90
|
-
assert manifest.key?('application.css')
|
|
91
|
-
assert manifest['application.js']['logical_path'] == 'application.js'
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_bundler_base_class
|
|
95
|
-
bundler = Railpack::Bundler.new({})
|
|
96
|
-
|
|
97
|
-
assert_respond_to bundler, :build!
|
|
98
|
-
assert_respond_to bundler, :watch
|
|
99
|
-
assert_respond_to bundler, :install!
|
|
100
|
-
assert_respond_to bundler, :name
|
|
101
|
-
assert_respond_to bundler, :commands
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_bun_bundler_commands
|
|
105
|
-
bundler = Railpack::BunBundler.new({})
|
|
106
|
-
commands = bundler.send(:commands)
|
|
107
|
-
|
|
108
|
-
assert_equal 'bun run build', commands[:build]
|
|
109
|
-
assert_equal 'bun run watch', commands[:watch]
|
|
110
|
-
assert_equal 'bun install', commands[:install]
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def test_esbuild_bundler_commands
|
|
114
|
-
bundler = Railpack::EsbuildBundler.new({})
|
|
115
|
-
commands = bundler.send(:commands)
|
|
116
|
-
|
|
117
|
-
assert_equal 'esbuild', commands[:build]
|
|
118
|
-
assert_equal 'esbuild --watch', commands[:watch]
|
|
119
|
-
assert_equal 'npm install', commands[:install]
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def test_rollup_bundler_commands
|
|
123
|
-
bundler = Railpack::RollupBundler.new({})
|
|
124
|
-
commands = bundler.send(:commands)
|
|
125
|
-
|
|
126
|
-
assert_equal 'rollup', commands[:build]
|
|
127
|
-
assert_equal 'rollup --watch', commands[:watch]
|
|
128
|
-
assert_equal 'npm install', commands[:install]
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def test_webpack_bundler_commands
|
|
132
|
-
bundler = Railpack::WebpackBundler.new({})
|
|
133
|
-
commands = bundler.send(:commands)
|
|
134
|
-
|
|
135
|
-
assert_equal 'webpack', commands[:build]
|
|
136
|
-
assert_equal 'webpack --watch', commands[:watch]
|
|
137
|
-
assert_equal 'npm install', commands[:install]
|
|
138
|
-
end
|
|
139
42
|
|
|
140
43
|
def test_event_hooks
|
|
141
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.
|
|
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:
|