vite_rails 1.0.8 → 2.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 +27 -1
- data/CONTRIBUTING.md +0 -1
- data/README.md +57 -32
- data/lib/tasks/vite.rake +17 -0
- data/lib/vite_rails.rb +5 -93
- data/lib/vite_rails/config.rb +11 -100
- data/lib/vite_rails/engine.rb +7 -11
- data/lib/vite_rails/installation.rb +47 -0
- data/lib/vite_rails/tag_helpers.rb +61 -0
- data/lib/vite_rails/version.rb +2 -2
- data/{lib/install/config/vite.json → templates/config/rails-vite.json} +1 -0
- data/{lib/install/javascript → templates}/entrypoints/application.js +0 -0
- metadata +25 -129
- data/lib/install/bin/vite +0 -17
- data/lib/install/binstubs.rb +0 -6
- data/lib/install/config/vite.config.ts +0 -11
- data/lib/install/template.rb +0 -40
- data/lib/tasks/vite/binstubs.rake +0 -12
- data/lib/tasks/vite/build.rake +0 -33
- data/lib/tasks/vite/clean.rake +0 -25
- data/lib/tasks/vite/clobber.rake +0 -20
- data/lib/tasks/vite/info.rake +0 -20
- data/lib/tasks/vite/install.rake +0 -12
- data/lib/tasks/vite/install_dependencies.rake +0 -20
- data/lib/tasks/vite/verify_install.rake +0 -23
- data/lib/vite_rails/builder.rb +0 -113
- data/lib/vite_rails/commands.rb +0 -68
- data/lib/vite_rails/dev_server.rb +0 -23
- data/lib/vite_rails/dev_server_proxy.rb +0 -49
- data/lib/vite_rails/helper.rb +0 -67
- data/lib/vite_rails/manifest.rb +0 -138
- data/lib/vite_rails/runner.rb +0 -56
- data/package.json +0 -16
- data/package/default.vite.json +0 -15
- data/test/builder_test.rb +0 -72
- data/test/command_test.rb +0 -35
- data/test/configuration_test.rb +0 -80
- data/test/dev_server_runner_test.rb +0 -83
- data/test/dev_server_test.rb +0 -39
- data/test/engine_rake_tasks_test.rb +0 -42
- data/test/helper_test.rb +0 -138
- data/test/manifest_test.rb +0 -75
- data/test/mode_test.rb +0 -21
- data/test/mounted_app/Rakefile +0 -6
- data/test/mounted_app/test/dummy/Rakefile +0 -5
- data/test/mounted_app/test/dummy/bin/rails +0 -5
- data/test/mounted_app/test/dummy/bin/rake +0 -5
- data/test/mounted_app/test/dummy/config.ru +0 -7
- data/test/mounted_app/test/dummy/config/application.rb +0 -12
- data/test/mounted_app/test/dummy/config/environment.rb +0 -5
- data/test/mounted_app/test/dummy/config/vite.json +0 -20
- data/test/mounted_app/test/dummy/package.json +0 -7
- data/test/rake_tasks_test.rb +0 -74
- data/test/test_app/Rakefile +0 -5
- data/test/test_app/app/javascript/entrypoints/application.js +0 -2
- data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
- data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
- data/test/test_app/bin/vite +0 -17
- data/test/test_app/config.ru +0 -7
- data/test/test_app/config/application.rb +0 -13
- data/test/test_app/config/environment.rb +0 -6
- data/test/test_app/config/vite.json +0 -20
- data/test/test_app/config/vite_public_root.yml +0 -20
- data/test/test_app/package.json +0 -13
- data/test/test_app/public/vite/manifest.json +0 -36
- data/test/test_app/some.config.js +0 -0
- data/test/test_app/yarn.lock +0 -11
- data/test/test_helper.rb +0 -34
- data/test/vite_runner_test.rb +0 -59
- data/test/webpacker_test.rb +0 -15
data/test/dev_server_test.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class DevServerTest < ViteRails::Test
|
6
|
-
def test_running?
|
7
|
-
refute ViteRails.dev_server.running?
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_host
|
11
|
-
with_rails_env('development') do
|
12
|
-
assert_equal ViteRails.config.host, 'localhost'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_port
|
17
|
-
with_rails_env('development') do
|
18
|
-
assert_equal ViteRails.config.port, 3035
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_https?
|
23
|
-
with_rails_env('development') do
|
24
|
-
assert_equal ViteRails.config.https, false
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_protocol
|
29
|
-
with_rails_env('development') do
|
30
|
-
assert_equal ViteRails.config.protocol, 'http'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_host_with_port
|
35
|
-
with_rails_env('development') do
|
36
|
-
assert_equal ViteRails.config.host_with_port, 'localhost:3035'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class EngineRakeTasksTest < Minitest::Test
|
6
|
-
def setup
|
7
|
-
remove_vite_binstubs
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
remove_vite_binstubs
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_task_mounted
|
15
|
-
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
16
|
-
assert_includes output, 'app:vite'
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_binstubs
|
20
|
-
Dir.chdir(mounted_app_path) { `bundle exec rake app:vite:binstubs` }
|
21
|
-
vite_binstub_paths.each { |path| assert File.exist?(path) }
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def mounted_app_path
|
27
|
-
File.expand_path('mounted_app', __dir__)
|
28
|
-
end
|
29
|
-
|
30
|
-
def vite_binstub_paths
|
31
|
-
[
|
32
|
-
"#{ mounted_app_path }/test/dummy/bin/vite",
|
33
|
-
"#{ mounted_app_path }/test/dummy/bin/vite-dev-server",
|
34
|
-
]
|
35
|
-
end
|
36
|
-
|
37
|
-
def remove_vite_binstubs
|
38
|
-
vite_binstub_paths.each do |path|
|
39
|
-
File.delete(path) if File.exist?(path)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/test/helper_test.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class HelperTest < ActionView::TestCase
|
6
|
-
tests ViteRails::Helper
|
7
|
-
|
8
|
-
attr_reader :request
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@request = Class.new do
|
12
|
-
def send_early_hints(links) end
|
13
|
-
|
14
|
-
def base_url
|
15
|
-
'https://example.com'
|
16
|
-
end
|
17
|
-
end.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_asset_pack_path
|
21
|
-
assert_equal '/packs/bootstrap-300631c4f0e0f9c865bc.js', asset_pack_path('bootstrap.js')
|
22
|
-
assert_equal '/packs/bootstrap-c38deda30895059837cf.css', asset_pack_path('bootstrap.css')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_asset_pack_url
|
26
|
-
assert_equal 'https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js', asset_pack_url('bootstrap.js')
|
27
|
-
assert_equal 'https://example.com/packs/bootstrap-c38deda30895059837cf.css', asset_pack_url('bootstrap.css')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_image_pack_path
|
31
|
-
assert_equal '/packs/application-k344a6d59eef8632c9d1.png', image_pack_path('application.png')
|
32
|
-
assert_equal '/packs/media/images/image-c38deda30895059837cf.jpg', image_pack_path('image.jpg')
|
33
|
-
assert_equal '/packs/media/images/image-c38deda30895059837cf.jpg', image_pack_path('media/images/image.jpg')
|
34
|
-
assert_equal '/packs/media/images/nested/image-c38deda30895059837cf.jpg', image_pack_path('nested/image.jpg')
|
35
|
-
assert_equal '/packs/media/images/nested/image-c38deda30895059837cf.jpg', image_pack_path('media/images/nested/image.jpg')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_image_pack_url
|
39
|
-
assert_equal 'https://example.com/packs/application-k344a6d59eef8632c9d1.png', image_pack_url('application.png')
|
40
|
-
assert_equal 'https://example.com/packs/media/images/image-c38deda30895059837cf.jpg', image_pack_url('image.jpg')
|
41
|
-
assert_equal 'https://example.com/packs/media/images/image-c38deda30895059837cf.jpg', image_pack_url('media/images/image.jpg')
|
42
|
-
assert_equal 'https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg', image_pack_url('nested/image.jpg')
|
43
|
-
assert_equal 'https://example.com/packs/media/images/nested/image-c38deda30895059837cf.jpg', image_pack_url('media/images/nested/image.jpg')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_image_pack_tag
|
47
|
-
assert_equal \
|
48
|
-
'<img alt="Edit Entry" src="/packs/application-k344a6d59eef8632c9d1.png" width="16" height="10" />',
|
49
|
-
image_pack_tag('application.png', size: '16x10', alt: 'Edit Entry')
|
50
|
-
assert_equal \
|
51
|
-
'<img alt="Edit Entry" src="/packs/media/images/image-c38deda30895059837cf.jpg" width="16" height="10" />',
|
52
|
-
image_pack_tag('image.jpg', size: '16x10', alt: 'Edit Entry')
|
53
|
-
assert_equal \
|
54
|
-
'<img alt="Edit Entry" src="/packs/media/images/image-c38deda30895059837cf.jpg" width="16" height="10" />',
|
55
|
-
image_pack_tag('media/images/image.jpg', size: '16x10', alt: 'Edit Entry')
|
56
|
-
assert_equal \
|
57
|
-
'<img alt="Edit Entry" src="/packs/media/images/nested/image-c38deda30895059837cf.jpg" width="16" height="10" />',
|
58
|
-
image_pack_tag('nested/image.jpg', size: '16x10', alt: 'Edit Entry')
|
59
|
-
assert_equal \
|
60
|
-
'<img alt="Edit Entry" src="/packs/media/images/nested/image-c38deda30895059837cf.jpg" width="16" height="10" />',
|
61
|
-
image_pack_tag('media/images/nested/image.jpg', size: '16x10', alt: 'Edit Entry')
|
62
|
-
assert_equal \
|
63
|
-
'<img srcset="/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg 2x" src="/packs/media/images/image-c38deda30895059837cf.jpg" />',
|
64
|
-
image_pack_tag('media/images/image.jpg', srcset: { 'media/images/image-2x.jpg' => '2x' })
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_favicon_pack_tag
|
68
|
-
assert_equal \
|
69
|
-
'<link rel="apple-touch-icon" type="image/png" href="/packs/application-k344a6d59eef8632c9d1.png" />',
|
70
|
-
favicon_pack_tag('application.png', rel: 'apple-touch-icon', type: 'image/png')
|
71
|
-
assert_equal \
|
72
|
-
'<link rel="apple-touch-icon" type="image/png" href="/packs/media/images/mb-icon-c38deda30895059837cf.png" />',
|
73
|
-
favicon_pack_tag('mb-icon.png', rel: 'apple-touch-icon', type: 'image/png')
|
74
|
-
assert_equal \
|
75
|
-
'<link rel="apple-touch-icon" type="image/png" href="/packs/media/images/mb-icon-c38deda30895059837cf.png" />',
|
76
|
-
favicon_pack_tag('media/images/mb-icon.png', rel: 'apple-touch-icon', type: 'image/png')
|
77
|
-
assert_equal \
|
78
|
-
'<link rel="apple-touch-icon" type="image/png" href="/packs/media/images/nested/mb-icon-c38deda30895059837cf.png" />',
|
79
|
-
favicon_pack_tag('nested/mb-icon.png', rel: 'apple-touch-icon', type: 'image/png')
|
80
|
-
assert_equal \
|
81
|
-
'<link rel="apple-touch-icon" type="image/png" href="/packs/media/images/nested/mb-icon-c38deda30895059837cf.png" />',
|
82
|
-
favicon_pack_tag('media/images/nested/mb-icon.png', rel: 'apple-touch-icon', type: 'image/png')
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_javascript_pack_tag
|
86
|
-
assert_equal \
|
87
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
88
|
-
javascript_pack_tag('bootstrap.js')
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_javascript_pack_tag_symbol
|
92
|
-
assert_equal \
|
93
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>),
|
94
|
-
javascript_pack_tag(:bootstrap)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_javascript_pack_tag_splat
|
98
|
-
assert_equal \
|
99
|
-
%(<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>\n) +
|
100
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>),
|
101
|
-
javascript_pack_tag('bootstrap.js', 'application.js', defer: true)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_javascript_pack_tag_split_chunks
|
105
|
-
assert_equal \
|
106
|
-
%(<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>\n) +
|
107
|
-
%(<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>\n) +
|
108
|
-
%(<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>),
|
109
|
-
javascript_packs_with_chunks_tag('application')
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_stylesheet_pack_tag_split_chunks
|
113
|
-
assert_equal \
|
114
|
-
%(<link rel="stylesheet" media="screen" href="/packs/1-c20632e7baf2c81200d3.chunk.css" />\n) +
|
115
|
-
%(<link rel="stylesheet" media="screen" href="/packs/application-k344a6d59eef8632c9d1.chunk.css" />\n) +
|
116
|
-
%(<link rel="stylesheet" media="screen" href="/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css" />),
|
117
|
-
stylesheet_packs_with_chunks_tag('application', 'hello_stimulus')
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_stylesheet_pack_tag
|
121
|
-
assert_equal \
|
122
|
-
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
123
|
-
stylesheet_pack_tag('bootstrap.css')
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_stylesheet_pack_tag_symbol
|
127
|
-
assert_equal \
|
128
|
-
%(<link rel="stylesheet" media="screen" href="/packs/bootstrap-c38deda30895059837cf.css" />),
|
129
|
-
stylesheet_pack_tag(:bootstrap)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_stylesheet_pack_tag_splat
|
133
|
-
assert_equal \
|
134
|
-
%(<link rel="stylesheet" media="all" href="/packs/bootstrap-c38deda30895059837cf.css" />\n) +
|
135
|
-
%(<link rel="stylesheet" media="all" href="/packs/application-dd6b1cd38bfa093df600.css" />),
|
136
|
-
stylesheet_pack_tag('bootstrap.css', 'application.css', media: 'all')
|
137
|
-
end
|
138
|
-
end
|
data/test/manifest_test.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ManifestTest < Minitest::Test
|
6
|
-
def test_lookup_exception!
|
7
|
-
asset_file = 'calendar.js'
|
8
|
-
|
9
|
-
error = assert_raises_manifest_missing_entry_error do
|
10
|
-
ViteRails.manifest.lookup!(asset_file)
|
11
|
-
end
|
12
|
-
|
13
|
-
assert_match "ViteRails can't find #{ asset_file } in #{ manifest_path }", error.message
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_lookup_with_type_exception!
|
17
|
-
asset_file = 'calendar'
|
18
|
-
|
19
|
-
error = assert_raises_manifest_missing_entry_error do
|
20
|
-
ViteRails.manifest.lookup!(asset_file, type: :javascript)
|
21
|
-
end
|
22
|
-
|
23
|
-
assert_match "ViteRails can't find #{ asset_file }.js in #{ manifest_path }", error.message
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_lookup_success!
|
27
|
-
assert_equal ViteRails.manifest.lookup!('bootstrap.js'), '/packs/bootstrap-300631c4f0e0f9c865bc.js'
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_lookup_nil
|
31
|
-
assert_nil ViteRails.manifest.lookup('foo.js')
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_lookup_chunks_nil
|
35
|
-
assert_nil ViteRails.manifest.lookup_pack_with_chunks('foo.js')
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_lookup_success
|
39
|
-
assert_equal ViteRails.manifest.lookup('bootstrap.js'), '/packs/bootstrap-300631c4f0e0f9c865bc.js'
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_lookup_entrypoint_exception!
|
43
|
-
asset_file = 'calendar'
|
44
|
-
|
45
|
-
error = assert_raises_manifest_missing_entry_error do
|
46
|
-
ViteRails.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_match "ViteRails can't find #{ asset_file }.js in #{ manifest_path }", error.message
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_lookup_entrypoint
|
53
|
-
application_entrypoints = [
|
54
|
-
'/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js',
|
55
|
-
'/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js',
|
56
|
-
'/packs/application-k344a6d59eef8632c9d1.js',
|
57
|
-
]
|
58
|
-
|
59
|
-
assert_equal ViteRails.manifest.lookup_pack_with_chunks!('application', type: :javascript), application_entrypoints
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def assert_raises_manifest_missing_entry_error(&block)
|
65
|
-
error = nil
|
66
|
-
ViteRails.config.stub :compile?, false do
|
67
|
-
error = assert_raises ViteRails::Manifest::MissingEntryError, &block
|
68
|
-
end
|
69
|
-
error
|
70
|
-
end
|
71
|
-
|
72
|
-
def manifest_path
|
73
|
-
File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs', 'manifest.json').to_s
|
74
|
-
end
|
75
|
-
end
|
data/test/mode_test.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class ModeTest < ViteRails::Test
|
6
|
-
def test_current
|
7
|
-
assert_equal ViteRails.config.mode, Rails.env
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_custom_without_config
|
11
|
-
with_rails_env('foo') do
|
12
|
-
assert_equal ViteRails.config.mode, 'production'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_custom_with_config
|
17
|
-
with_rails_env('staging') do
|
18
|
-
assert_equal ViteRails.config.mode, 'staging'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/test/mounted_app/Rakefile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'action_controller/railtie'
|
4
|
-
require 'action_view/railtie'
|
5
|
-
require 'vite_rails'
|
6
|
-
|
7
|
-
module TestDummyApp
|
8
|
-
class Application < Rails::Application
|
9
|
-
config.secret_key_base = 'abcdef'
|
10
|
-
config.eager_load = true
|
11
|
-
end
|
12
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"development": {
|
3
|
-
"autoBuild": true,
|
4
|
-
"port": "3535",
|
5
|
-
"https": true,
|
6
|
-
"publicOutputDir": "vite-development"
|
7
|
-
},
|
8
|
-
"test": {
|
9
|
-
"autoBuild": true,
|
10
|
-
"publicOutputDir": "vite-test"
|
11
|
-
},
|
12
|
-
"production": {
|
13
|
-
"autoBuild": false,
|
14
|
-
"publicOutputDir": "vite-production"
|
15
|
-
},
|
16
|
-
"staging": {
|
17
|
-
"autoBuild": false,
|
18
|
-
"publicOutputDir": "vite-staging"
|
19
|
-
}
|
20
|
-
}
|
data/test/rake_tasks_test.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RakeTasksTest < Minitest::Test
|
6
|
-
def test_rake_tasks
|
7
|
-
output = Dir.chdir(test_app_path) { `rake -T` }
|
8
|
-
assert_includes output, 'vite_rails'
|
9
|
-
assert_includes output, 'vite:check_binstubs'
|
10
|
-
assert_includes output, 'vite:check_node'
|
11
|
-
assert_includes output, 'vite:check_yarn'
|
12
|
-
assert_includes output, 'vite:clean'
|
13
|
-
assert_includes output, 'vite:clobber'
|
14
|
-
assert_includes output, 'vite:compile'
|
15
|
-
assert_includes output, 'vite:install'
|
16
|
-
assert_includes output, 'vite:verify_install'
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_rake_task_vite_check_binstubs
|
20
|
-
output = Dir.chdir(test_app_path) { `rake vite:check_binstubs 2>&1` }
|
21
|
-
refute_includes output, 'vite binstub not found.'
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_check_node_version
|
25
|
-
output = Dir.chdir(test_app_path) { `rake vite:check_node 2>&1` }
|
26
|
-
refute_includes output, 'ViteRails requires Node.js'
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_check_yarn_version
|
30
|
-
output = Dir.chdir(test_app_path) { `rake vite:check_yarn 2>&1` }
|
31
|
-
refute_includes output, 'Yarn not installed'
|
32
|
-
refute_includes output, 'ViteRails requires Yarn'
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_rake_vite_install_dependencies_in_non_production_environments
|
36
|
-
assert_includes test_app_dev_dependencies, 'right-pad'
|
37
|
-
|
38
|
-
ViteRails.with_node_env('test') do
|
39
|
-
Dir.chdir(test_app_path) do
|
40
|
-
`bundle exec rake vite:install_dependencies`
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_includes installed_node_module_names, 'right-pad',
|
45
|
-
'Expected dev dependencies to be installed'
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_rake_vite_install_dependencies_in_production_environment
|
49
|
-
ViteRails.with_node_env('production') do
|
50
|
-
Dir.chdir(test_app_path) do
|
51
|
-
`bundle exec rake vite:install_dependencies`
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
refute_includes installed_node_module_names, 'right-pad',
|
56
|
-
'Expected only production dependencies to be installed'
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def test_app_path
|
62
|
-
File.expand_path('test_app', __dir__)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_app_dev_dependencies
|
66
|
-
package_json = File.expand_path('package.json', test_app_path)
|
67
|
-
JSON.parse(File.read(package_json))['devDependencies']
|
68
|
-
end
|
69
|
-
|
70
|
-
def installed_node_module_names
|
71
|
-
node_modules_path = File.expand_path('node_modules', test_app_path)
|
72
|
-
Dir.chdir(node_modules_path) { Dir.glob('*') }
|
73
|
-
end
|
74
|
-
end
|