vite_rails 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/CONTRIBUTING.md +0 -1
  4. data/lib/install/template.rb +1 -1
  5. data/lib/tasks/vite/build.rake +1 -5
  6. data/lib/tasks/vite/clean.rake +1 -3
  7. data/lib/tasks/vite/verify_install.rake +3 -3
  8. data/lib/vite_rails.rb +14 -25
  9. data/lib/vite_rails/builder.rb +11 -4
  10. data/lib/vite_rails/commands.rb +50 -10
  11. data/lib/vite_rails/config.rb +35 -23
  12. data/lib/vite_rails/dev_server_proxy.rb +27 -18
  13. data/lib/vite_rails/helper.rb +4 -2
  14. data/lib/vite_rails/manifest.rb +4 -3
  15. data/lib/vite_rails/runner.rb +2 -5
  16. data/lib/vite_rails/version.rb +1 -1
  17. data/package.json +1 -1
  18. data/test/builder_test.rb +27 -22
  19. data/test/commands_test.rb +67 -0
  20. data/test/configuration_test.rb +88 -46
  21. data/test/dev_server_proxy_test.rb +101 -0
  22. data/test/dev_server_test.rb +0 -30
  23. data/test/engine_rake_tasks_test.rb +55 -17
  24. data/test/helper_test.rb +37 -105
  25. data/test/manifest_test.rb +33 -29
  26. data/test/mode_test.rb +6 -11
  27. data/test/mounted_app/test/dummy/config/vite.json +5 -11
  28. data/test/mounted_app/test/dummy/package.json +2 -1
  29. data/test/mounted_app/test/dummy/yarn.lock +208 -0
  30. data/test/rake_tasks_test.rb +5 -19
  31. data/test/runner_test.rb +31 -0
  32. data/test/test_app/app/{javascript → frontend}/entrypoints/application.js +0 -0
  33. data/test/test_app/config/vite.json +0 -2
  34. data/test/test_app/config/vite_additional_paths.json +5 -0
  35. data/test/test_app/config/vite_public_dir.json +5 -0
  36. data/test/test_app/public/vite-production/manifest.json +22 -0
  37. data/test/test_helper.rb +48 -14
  38. metadata +21 -23
  39. data/test/command_test.rb +0 -35
  40. data/test/dev_server_runner_test.rb +0 -83
  41. data/test/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
  42. data/test/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
  43. data/test/test_app/config/vite_public_root.yml +0 -20
  44. data/test/test_app/public/vite/manifest.json +0 -36
  45. data/test/vite_runner_test.rb +0 -59
  46. data/test/webpacker_test.rb +0 -15
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class CommandTest < Minitest::Test
6
- def test_compile_command_returns_success_status_when_stale
7
- ViteRails.builder.stub :stale?, true do
8
- ViteRails.builder.stub :run_vite, true do
9
- assert_equal true, ViteRails.commands.compile
10
- end
11
- end
12
- end
13
-
14
- def test_compile_command_returns_success_status_when_fresh
15
- ViteRails.builder.stub :stale?, false do
16
- ViteRails.builder.stub :run_vite, true do
17
- assert_equal true, ViteRails.commands.compile
18
- end
19
- end
20
- end
21
-
22
- def test_compile_command_returns_failure_status_when_stale
23
- ViteRails.builder.stub :stale?, true do
24
- ViteRails.builder.stub :run_vite, false do
25
- assert_equal false, ViteRails.commands.compile
26
- end
27
- end
28
- end
29
-
30
- def test_clean_command_works_with_nested_hashes_and_without_any_compiled_files
31
- File.stub :delete, true do
32
- assert ViteRails.commands.clean
33
- end
34
- end
35
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class DevServerRunnerTest < ViteRails::Test
6
- def setup
7
- @original_node_env, ENV['NODE_ENV'] = ENV['NODE_ENV'], 'development'
8
- @original_rails_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'development'
9
- end
10
-
11
- def teardown
12
- ENV['NODE_ENV'] = @original_node_env
13
- ENV['RAILS_ENV'] = @original_rails_env
14
- end
15
-
16
- def test_run_cmd_via_node_modules
17
- cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--mode', 'development']
18
-
19
- verify_command(cmd, use_node_modules: true)
20
- end
21
-
22
- def test_run_cmd_via_yarn
23
- cmd = ['yarn', 'vite', '--mode', 'development']
24
-
25
- verify_command(cmd, use_node_modules: false)
26
- end
27
-
28
- def test_run_cmd_argv
29
- cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--quiet', '--mode', 'development']
30
-
31
- verify_command(cmd, argv: ['--quiet'])
32
- end
33
-
34
- def test_run_cmd_argv_with_https
35
- cmd = ["#{ test_app_path }/node_modules/.bin/vite", '--https', '--mode', 'development']
36
-
37
- dev_server = ViteRails::DevServer.new({})
38
- def dev_server.host
39
- 'localhost'
40
- end
41
-
42
- def dev_server.port
43
- '3035'
44
- end
45
-
46
- def dev_server.pretty?
47
- false
48
- end
49
-
50
- def dev_server.https?
51
- true
52
- end
53
- ViteRails::DevServer.stub(:new, dev_server) do
54
- verify_command(cmd, argv: ['--https'])
55
- end
56
- end
57
-
58
- private
59
-
60
- def test_app_path
61
- File.expand_path('test_app', __dir__)
62
- end
63
-
64
- def verify_command(cmd, use_node_modules: true, argv: [])
65
- cwd = Dir.pwd
66
- Dir.chdir(test_app_path)
67
-
68
- klass = ViteRails::Runner
69
- instance = klass.new(argv)
70
- mock = Minitest::Mock.new
71
- mock.expect(:call, nil, [ViteRails.env, *cmd])
72
-
73
- klass.stub(:new, instance) do
74
- instance.stub(:executable_exists?, use_node_modules) do
75
- Kernel.stub(:exec, mock) { ViteRails.run(argv) }
76
- end
77
- end
78
-
79
- mock.verify
80
- ensure
81
- Dir.chdir(cwd)
82
- end
83
- end
@@ -1,4 +0,0 @@
1
- /*
2
- * Dummy file #1 for Multi File Entry points: https://vite.js.org/guides/entry-advanced/
3
- * This file must be named the same
4
- */
@@ -1,4 +0,0 @@
1
- /*
2
- * Dummy file #2 for Multi File Entry points: https://vite.js.org/guides/entry-advanced/
3
- * This file must be named the same
4
- */
@@ -1,20 +0,0 @@
1
- {
2
- "development": {
3
- "autoBuild": true,
4
- "port": "3535",
5
- "https": true,
6
- "publicDir": "../public"
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
- }
@@ -1,36 +0,0 @@
1
- {
2
- "bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
3
- "application.css": "/packs/application-dd6b1cd38bfa093df600.css",
4
- "bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
5
- "application.js": "/packs/application-k344a6d59eef8632c9d1.js",
6
- "application.png": "/packs/application-k344a6d59eef8632c9d1.png",
7
- "fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
8
- "media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
9
- "media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
10
- "media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
11
- "media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
12
- "media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
13
- "entrypoints": {
14
- "application": {
15
- "assets": {
16
- "js": [
17
- "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
18
- "/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
19
- "/packs/application-k344a6d59eef8632c9d1.js"
20
- ],
21
- "css": [
22
- "/packs/1-c20632e7baf2c81200d3.chunk.css",
23
- "/packs/application-k344a6d59eef8632c9d1.chunk.css"
24
- ]
25
- }
26
- },
27
- "hello_stimulus": {
28
- "assets": {
29
- "css": [
30
- "/packs/1-c20632e7baf2c81200d3.chunk.css",
31
- "/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
32
- ]
33
- }
34
- }
35
- }
36
- }
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ViteRunnerTest < ViteRails::Test
6
- def setup
7
- @original_node_env, ENV['NODE_ENV'] = ENV['NODE_ENV'], 'development'
8
- @original_rails_env, ENV['RAILS_ENV'] = ENV['RAILS_ENV'], 'development'
9
- end
10
-
11
- def teardown
12
- ENV['NODE_ENV'] = @original_node_env
13
- ENV['RAILS_ENV'] = @original_rails_env
14
- end
15
-
16
- def test_run_cmd_via_node_modules
17
- cmd = ["#{ test_app_path }/node_modules/.bin/vite", 'build', '--mode', 'development']
18
-
19
- verify_command(cmd, use_node_modules: true)
20
- end
21
-
22
- def test_run_cmd_via_yarn
23
- cmd = ['yarn', 'vite', 'build', '--mode', 'development']
24
-
25
- verify_command(cmd, use_node_modules: false)
26
- end
27
-
28
- def test_run_cmd_argv
29
- cmd = ["#{ test_app_path }/node_modules/.bin/vite", 'build', '--mode', 'development', '--emptyOutDir']
30
-
31
- verify_command(cmd, argv: ['--emptyOutDir'])
32
- end
33
-
34
- private
35
-
36
- def test_app_path
37
- File.expand_path('test_app', __dir__)
38
- end
39
-
40
- def verify_command(cmd, use_node_modules: true, argv: [])
41
- cwd = Dir.pwd
42
- Dir.chdir(test_app_path)
43
-
44
- klass = ViteRails::ViteRunner
45
- instance = klass.new(argv)
46
- mock = Minitest::Mock.new
47
- mock.expect(:call, nil, [ViteRails::Compiler.env, *cmd])
48
-
49
- klass.stub(:new, instance) do
50
- instance.stub(:executable_exists?, use_node_modules) do
51
- Kernel.stub(:exec, mock) { klass.run(argv) }
52
- end
53
- end
54
-
55
- mock.verify
56
- ensure
57
- Dir.chdir(cwd)
58
- end
59
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
-
5
- class ViteRailsTest < ViteRails::Test
6
- def test_config_params
7
- assert_equal Rails.env, ViteRails.config.mode
8
- assert_equal ViteRails.instance.root_path, ViteRails.config.root_path
9
- assert_equal ViteRails.instance.config_path, ViteRails.config.config_path
10
-
11
- with_rails_env('test') do
12
- assert_equal 'test', ViteRails.config.env
13
- end
14
- end
15
- end