vite_rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTING.md +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/lib/install/binstubs.rb +6 -0
- data/lib/install/template.rb +62 -0
- data/lib/vite_rails.rb +91 -0
- data/lib/vite_rails/builder.rb +113 -0
- data/lib/vite_rails/commands.rb +68 -0
- data/lib/vite_rails/config.rb +106 -0
- data/lib/vite_rails/dev_server.rb +23 -0
- data/lib/vite_rails/dev_server_proxy.rb +47 -0
- data/lib/vite_rails/engine.rb +40 -0
- data/lib/vite_rails/helper.rb +41 -0
- data/lib/vite_rails/manifest.rb +134 -0
- data/lib/vite_rails/runner.rb +56 -0
- data/lib/vite_rails/version.rb +5 -0
- data/package.json +28 -0
- data/package/default.vite.json +15 -0
- data/test/builder_test.rb +72 -0
- data/test/command_test.rb +35 -0
- data/test/configuration_test.rb +80 -0
- data/test/dev_server_runner_test.rb +83 -0
- data/test/dev_server_test.rb +39 -0
- data/test/engine_rake_tasks_test.rb +42 -0
- data/test/helper_test.rb +138 -0
- data/test/manifest_test.rb +75 -0
- data/test/mode_test.rb +21 -0
- data/test/mounted_app/Rakefile +6 -0
- data/test/mounted_app/test/dummy/Rakefile +5 -0
- data/test/mounted_app/test/dummy/bin/rails +5 -0
- data/test/mounted_app/test/dummy/bin/rake +5 -0
- data/test/mounted_app/test/dummy/config.ru +7 -0
- data/test/mounted_app/test/dummy/config/application.rb +12 -0
- data/test/mounted_app/test/dummy/config/environment.rb +5 -0
- data/test/mounted_app/test/dummy/config/vite.json +20 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +74 -0
- data/test/test_app/Rakefile +5 -0
- data/test/test_app/app/javascript/entrypoints/application.js +10 -0
- data/test/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/test/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/test/test_app/bin/vite +17 -0
- data/test/test_app/config.ru +7 -0
- data/test/test_app/config/application.rb +13 -0
- data/test/test_app/config/environment.rb +6 -0
- data/test/test_app/config/vite.json +20 -0
- data/test/test_app/config/vite_public_root.yml +20 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/vite/manifest.json +36 -0
- data/test/test_app/some.config.js +0 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +34 -0
- data/test/vite_runner_test.rb +59 -0
- data/test/webpacker_test.rb +15 -0
- metadata +234 -0
data/package.json
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"name": "only-for-workflows",
|
3
|
+
"version": "unknown",
|
4
|
+
"scripts": {
|
5
|
+
"test": "jest",
|
6
|
+
"lint": "eslint package/"
|
7
|
+
},
|
8
|
+
"dependencies": {
|
9
|
+
"vite": "^2.0.0-beta.30",
|
10
|
+
"vite-plugin-ruby": "1.0.0"
|
11
|
+
},
|
12
|
+
"devDependencies": {
|
13
|
+
"@vitejs/plugin-vue": "^1.0.6",
|
14
|
+
"eslint": "^7.16.0",
|
15
|
+
"eslint-config-airbnb": "^18.2.0",
|
16
|
+
"eslint-config-prettier": "^7.1.0",
|
17
|
+
"eslint-plugin-import": "^2.22.1",
|
18
|
+
"eslint-plugin-jsx-a11y": "^6.3.1",
|
19
|
+
"eslint-plugin-react": "^7.21.4",
|
20
|
+
"jest": "^26.5.3"
|
21
|
+
},
|
22
|
+
"jest": {
|
23
|
+
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
24
|
+
"roots": [
|
25
|
+
"<rootDir>/package"
|
26
|
+
]
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"assetsDir": "assets",
|
3
|
+
"autoBuild": false,
|
4
|
+
"buildCacheDir": "tmp/cache/vite",
|
5
|
+
"publicOutputDir": "vite",
|
6
|
+
"configPath": "config/vite.json",
|
7
|
+
"publicDir": "public",
|
8
|
+
"entrypointsDir": "entrypoints",
|
9
|
+
"sourceCodeDir": "app/javascript",
|
10
|
+
"host": "localhost",
|
11
|
+
"https": null,
|
12
|
+
"port": 3036,
|
13
|
+
"hideBuildConsoleOutput": false,
|
14
|
+
"watchAdditionalPaths": []
|
15
|
+
}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class BuilderTest < Minitest::Test
|
6
|
+
def remove_files_digest_path
|
7
|
+
ViteRails.builder.send(:files_digest_path).tap do |path|
|
8
|
+
path.delete if path.exist?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
remove_files_digest_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
remove_files_digest_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_custom_environment_variables
|
21
|
+
assert_nil ViteRails.builder.send(:vite_env)['FOO']
|
22
|
+
ViteRails.env['FOO'] = 'BAR'
|
23
|
+
assert ViteRails.builder.send(:vite_env)['FOO'] == 'BAR'
|
24
|
+
ensure
|
25
|
+
ViteRails.env = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_freshness
|
29
|
+
assert ViteRails.builder.stale?
|
30
|
+
assert !ViteRails.builder.fresh?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_build
|
34
|
+
assert !ViteRails.builder.build
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_freshness_on_build_success
|
38
|
+
status = OpenStruct.new(success?: true)
|
39
|
+
|
40
|
+
assert ViteRails.builder.stale?
|
41
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
42
|
+
ViteRails.builder.build
|
43
|
+
assert ViteRails.builder.fresh?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_freshness_on_build_fail
|
48
|
+
status = OpenStruct.new(success?: false)
|
49
|
+
|
50
|
+
assert ViteRails.builder.stale?
|
51
|
+
Open3.stub :capture3, [:sterr, :stdout, status] do
|
52
|
+
ViteRails.builder.build
|
53
|
+
assert ViteRails.builder.fresh?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_files_digest_path
|
58
|
+
assert_equal ViteRails.builder.send(:files_digest_path).basename.to_s, "last-compilation-digest-#{ ViteRails.config.mode }"
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_external_env_variables
|
62
|
+
ViteRails.env = {}
|
63
|
+
assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_MODE'], 'production'
|
64
|
+
assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_ROOT'], Rails.root.to_s
|
65
|
+
|
66
|
+
ENV['VITE_RUBY_MODE'] = 'foo.bar'
|
67
|
+
ENV['VITE_RUBY_ROOT'] = '/baz'
|
68
|
+
|
69
|
+
assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_MODE'], 'foo.bar'
|
70
|
+
assert_equal ViteRails.builder.send(:vite_env)['VITE_RUBY_ROOT'], '/baz'
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ConfigurationTest < ViteRails::Test
|
6
|
+
def setup
|
7
|
+
@config = ViteRails::Configuration.new(
|
8
|
+
root_path: Pathname.new(File.expand_path('test_app', __dir__)),
|
9
|
+
config_path: Pathname.new(File.expand_path('./test_app/config/vite.yml', __dir__)),
|
10
|
+
env: 'production',
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_source_path
|
15
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/app/javascript').to_s
|
16
|
+
assert_equal source_path, @config.source_path.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_source_entry_path
|
20
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/app/javascript', 'packs').to_s
|
21
|
+
assert_equal @config.source_entry_path.to_s, source_entry_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_public_root_path
|
25
|
+
public_root_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public').to_s
|
26
|
+
assert_equal @config.public_path.to_s, public_root_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_public_output_path
|
30
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs').to_s
|
31
|
+
assert_equal @config.public_output_path.to_s, public_output_path
|
32
|
+
|
33
|
+
@config = ViteRails::Configuration.new(
|
34
|
+
root_path: @config.root_path,
|
35
|
+
config_path: Pathname.new(File.expand_path('./test_app/config/vite_public_root.yml', __dir__)),
|
36
|
+
env: 'production',
|
37
|
+
)
|
38
|
+
|
39
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), 'public/packs').to_s
|
40
|
+
assert_equal @config.public_output_path.to_s, public_output_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_public_manifest_path
|
44
|
+
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/public/packs', 'manifest.json').to_s
|
45
|
+
assert_equal @config.public_manifest_path.to_s, public_manifest_path
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_cache_path
|
49
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), 'test_app/tmp/cache/vite').to_s
|
50
|
+
assert_equal @config.cache_path.to_s, cache_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_additional_paths
|
54
|
+
assert_equal @config.additional_paths, ['app/assets', '/etc/yarn', 'some.config.js', 'app/elm']
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_cache_manifest?
|
58
|
+
assert @config.cache_manifest?
|
59
|
+
|
60
|
+
with_rails_env('development') do
|
61
|
+
refute ViteRails.config.cache_manifest?
|
62
|
+
end
|
63
|
+
|
64
|
+
with_rails_env('test') do
|
65
|
+
refute ViteRails.config.cache_manifest?
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_compile?
|
70
|
+
refute @config.compile?
|
71
|
+
|
72
|
+
with_rails_env('development') do
|
73
|
+
assert ViteRails.config.compile?
|
74
|
+
end
|
75
|
+
|
76
|
+
with_rails_env('test') do
|
77
|
+
assert ViteRails.config.compile?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,83 @@
|
|
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
|
@@ -0,0 +1,39 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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
ADDED
@@ -0,0 +1,138 @@
|
|
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
|