diff --git a/.rubocop.yml b/.rubocop.yml
index c290453c..6b0592f2 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -5,6 +5,9 @@ require:
- rubocop-performance
- rubocop-minitest
+inherit_gem:
+ standard: config/ruby-3.0.yml
+
inherit_mode:
merge:
- Exclude
diff --git a/test/dev_server_proxy_test.rb b/test/dev_server_proxy_test.rb
index 280959fb..fd22c9d5 100644
--- a/test/dev_server_proxy_test.rb
+++ b/test/dev_server_proxy_test.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'test_helper'
+require "test_helper"
class DevServerProxyTest < ViteRuby::Test
include Rack::Test::Methods
@@ -8,10 +8,10 @@ class DevServerProxyTest < ViteRuby::Test
def app
# Capture all changes to the env made by the proxy.
capture_app = Rack::Builder.new.run(->(env) {
- [200, { 'Content-Type' => 'application/json' }, env.to_json]
+ [200, {"Content-Type" => "application/json"}, env.to_json]
})
# Avoid actually using the proxy.
- if RUBY_VERSION.start_with?('2.4')
+ if RUBY_VERSION.start_with?("2.4")
Rack::Proxy.send(:remove_method, :perform_request) if Rack::Proxy.method_defined?(:perform_request)
Rack::Proxy.send(:define_method, :perform_request) { |env| capture_app.call(env) }
else
@@ -23,126 +23,126 @@ def app
end
def test_non_asset
- get_with_dev_server_running '/'
+ get_with_dev_server_running "/"
assert_not_forwarded
end
def test_non_vite_asset
- get_with_dev_server_running '/fake_import.js'
+ get_with_dev_server_running "/fake_import.js"
assert_not_forwarded
end
def test_vite_asset
- get_with_dev_server_running '/vite-production/application.js'
+ get_with_dev_server_running "/vite-production/application.js"
- assert_forwarded to: '/vite-production/application.js'
+ assert_forwarded to: "/vite-production/application.js"
end
def test_vite_client
- get_with_dev_server_running '/@vite/client'
+ get_with_dev_server_running "/@vite/client"
assert_not_forwarded
end
def test_vite_client_with_empty_prefix
- refresh_config(public_output_dir: '')
- get_with_dev_server_running '/@vite/client'
+ refresh_config(public_output_dir: "")
+ get_with_dev_server_running "/@vite/client"
- assert_forwarded to: '/@vite/client'
+ assert_forwarded to: "/@vite/client"
end
def test_vite_import
- get_with_dev_server_running '/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css'
+ get_with_dev_server_running "/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css"
assert_not_forwarded
end
def test_vite_import_with_empty_prefix
- refresh_config(public_output_dir: '')
- get_with_dev_server_running '/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css'
+ refresh_config(public_output_dir: "")
+ get_with_dev_server_running "/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css"
- assert_forwarded to: '/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css'
+ assert_forwarded to: "/@fs//package/example/app/frontend/App.vue?import&t=1611322300214&vue&type=style&index=0&lang.css"
end
def test_hmr_for_stylesheet
- get_with_dev_server_running '/entrypoints/colored.css?t=1611322562923'
+ get_with_dev_server_running "/entrypoints/colored.css?t=1611322562923"
- assert_forwarded to: '/entrypoints/colored.css?t=1611322562923'
+ assert_forwarded to: "/entrypoints/colored.css?t=1611322562923"
end
def test_hmr_for_imported_entrypoint
- get_with_dev_server_running '/entrypoints/colored.css?import&t=1611322562923'
+ get_with_dev_server_running "/entrypoints/colored.css?import&t=1611322562923"
- assert_forwarded to: '/entrypoints/colored.css?import&t=1611322562923'
+ assert_forwarded to: "/entrypoints/colored.css?import&t=1611322562923"
end
def test_entrypoint_imported_from_entrypoint
- header 'Referer', 'http://localhost:3000/vite-production/application.js'
- get_with_dev_server_running '/entrypoints/example_import.js'
+ header "Referer", "http://localhost:3000/vite-production/application.js"
+ get_with_dev_server_running "/entrypoints/example_import.js"
- assert_forwarded to: '/entrypoints/example_import.js'
+ assert_forwarded to: "/entrypoints/example_import.js"
end
def test_scss_with_extra_css
- get_with_dev_server_running '/vite-production/entrypoints/sassy.scss.css'
+ get_with_dev_server_running "/vite-production/entrypoints/sassy.scss.css"
- assert_forwarded to: '/vite-production/entrypoints/sassy.scss'
+ assert_forwarded to: "/vite-production/entrypoints/sassy.scss"
end
def test_stylus_with_extra_css
- get_with_dev_server_running '/vite-production/entrypoints/sassy.stylus.css'
+ get_with_dev_server_running "/vite-production/entrypoints/sassy.stylus.css"
- assert_forwarded to: '/vite-production/entrypoints/sassy.stylus'
+ assert_forwarded to: "/vite-production/entrypoints/sassy.stylus"
end
def test_min_css
- get_with_dev_server_running '/vite-production/colored.min.css'
+ get_with_dev_server_running "/vite-production/colored.min.css"
- assert_forwarded to: '/vite-production/colored.min.css'
+ assert_forwarded to: "/vite-production/colored.min.css"
end
def test_module_css
- get_with_dev_server_running '/vite-production/colored.module.css'
+ get_with_dev_server_running "/vite-production/colored.module.css"
- assert_forwarded to: '/vite-production/colored.module.css'
+ assert_forwarded to: "/vite-production/colored.module.css"
end
def test_random_extension_css
- get_with_dev_server_running '/vite-production/colored.bubble.css'
+ get_with_dev_server_running "/vite-production/colored.bubble.css"
- assert_forwarded to: '/vite-production/colored.bubble.css'
+ assert_forwarded to: "/vite-production/colored.bubble.css"
end
def test_without_dev_server_running
- get '/vite-production/application.js'
+ get "/vite-production/application.js"
assert_not_forwarded
- get '/entrypoints/colored.css?import&t=1611322562923'
+ get "/entrypoints/colored.css?import&t=1611322562923"
assert_not_forwarded
- header 'Referer', 'http://localhost:3000/vite-production/application.js'
- get '/entrypoints/example_import.js'
+ header "Referer", "http://localhost:3000/vite-production/application.js"
+ get "/entrypoints/example_import.js"
assert_not_forwarded
end
def test_empty_public_output_dir
- refresh_config(public_output_dir: '')
- get_with_dev_server_running '/'
+ refresh_config(public_output_dir: "")
+ get_with_dev_server_running "/"
assert_not_forwarded
- get_with_dev_server_running '/entrypoints/application.js'
+ get_with_dev_server_running "/entrypoints/application.js"
- assert_forwarded to: '/entrypoints/application.js'
+ assert_forwarded to: "/entrypoints/application.js"
- get_with_dev_server_running '/entrypoints/sassy.scss.css'
+ get_with_dev_server_running "/entrypoints/sassy.scss.css"
- assert_forwarded to: '/entrypoints/sassy.scss'
+ assert_forwarded to: "/entrypoints/sassy.scss"
end
private
@@ -157,23 +157,23 @@ def assert_not_forwarded
assert_predicate last_response, :ok?
env = JSON.parse(last_response.body)
- assert_nil env['HTTP_X_FORWARDED_HOST']
- assert_nil env['HTTP_X_FORWARDED_PORT']
+ assert_nil env["HTTP_X_FORWARDED_HOST"]
+ assert_nil env["HTTP_X_FORWARDED_PORT"]
end
def assert_forwarded(to: nil)
assert_predicate last_response, :ok?
env = JSON.parse(last_response.body)
- assert_equal ViteRuby.config.host, env['HTTP_X_FORWARDED_HOST']
- assert_equal ViteRuby.config.port, Integer(env['HTTP_X_FORWARDED_PORT'])
+ assert_equal ViteRuby.config.host, env["HTTP_X_FORWARDED_HOST"]
+ assert_equal ViteRuby.config.port, Integer(env["HTTP_X_FORWARDED_PORT"])
return unless to
- path, query = to.split('?')
+ path, query = to.split("?")
- assert_equal path, env['PATH_INFO']
- assert_equal query.to_s, env['QUERY_STRING'].to_s
- assert_equal to, env['REQUEST_URI']
+ assert_equal path, env["PATH_INFO"]
+ assert_equal query.to_s, env["QUERY_STRING"].to_s
+ assert_equal to, env["REQUEST_URI"]
end
end
diff --git a/test/helper_test.rb b/test/helper_test.rb
index 4006358f..bfb7b099 100644
--- a/test/helper_test.rb
+++ b/test/helper_test.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'test_helper'
+require "test_helper"
-require 'vite_plugin_legacy'
+require "vite_plugin_legacy"
class HelperTestCase < ActionView::TestCase
include ViteRubyTestHelpers
@@ -12,33 +12,34 @@ class HelperTestCase < ActionView::TestCase
def setup
super
@request = Class.new do
- def send_early_hints(links) end
+ def send_early_hints(links)
+ end
def base_url
- 'https://example.com'
+ "https://example.com"
end
end.new
end
protected
- def link(href:, rel: 'stylesheet', media: 'screen', crossorigin: nil)
+ def link(href:, rel: "stylesheet", media: "screen", crossorigin: nil)
attrs = [%(media="#{media}"), %(href="#{href}"), (%(crossorigin="#{crossorigin}") if crossorigin)].compact
- attrs[1], attrs[2] = attrs[2], attrs[1] if Rails.gem_version > Gem::Version.new('6.1') && Rails.gem_version < Gem::Version.new('6.2') && attrs[2]
- attrs.reverse! if Rails.gem_version > Gem::Version.new('6.2')
- %()
+ attrs[1], attrs[2] = attrs[2], attrs[1] if Rails.gem_version > Gem::Version.new("6.1") && Rails.gem_version < Gem::Version.new("6.2") && attrs[2]
+ attrs.reverse! if Rails.gem_version > Gem::Version.new("6.2")
+ %()
end
def assert_similar(*args)
assert_equal(*args.map { |str|
- return str.tr("\n", '').gsub('" />', '">').gsub('"/>', '">') if RUBY_VERSION.start_with?('2.4')
+ return str.tr("\n", "").gsub('" />', '">').gsub('"/>', '">') if RUBY_VERSION.start_with?("2.4")
- str.tr("\n", '')
+ str.tr("\n", "")
})
end
def with_dev_server_running(&block)
- refresh_config(mode: 'development')
+ refresh_config(mode: "development")
super
end
end
@@ -50,9 +51,9 @@ class LegacyHelperTest < HelperTestCase
})
def test_plugin_legacy
- assert_includes vite_legacy_javascript_tag('/app/assets/external'), '/vite-production/assets/external.a35ee0db-legacy.js'
- assert_includes vite_legacy_typescript_tag('main.ts'), '/vite-production/assets/main.20bbd3a5-legacy.js'
- assert_includes vite_legacy_polyfill_tag, '/vite-production/assets/polyfills-legacy.07477394.js'
+ assert_includes vite_legacy_javascript_tag("/app/assets/external"), "/vite-production/assets/external.a35ee0db-legacy.js"
+ assert_includes vite_legacy_typescript_tag("main.ts"), "/vite-production/assets/main.20bbd3a5-legacy.js"
+ assert_includes vite_legacy_polyfill_tag, "/vite-production/assets/polyfills-legacy.07477394.js"
end
end
@@ -60,7 +61,7 @@ class HelperTest < HelperTestCase
tests ViteRails::TagHelpers
def content_security_policy_nonce
- 'iyhD0Yc0W+c='
+ "iyhD0Yc0W+c="
end
def test_vite_client_tag
@@ -71,42 +72,42 @@ def test_vite_client_tag
end
def test_vite_asset_path
- assert_equal '/vite-production/assets/main.9dcad042.js', vite_asset_path('main.ts')
- assert_equal '/vite-production/assets/app.517bf154.css', vite_asset_path('app.css')
- assert_equal '/vite-production/assets/logo.322aae0c.svg', vite_asset_path('images/logo.svg')
- assert_equal '/vite-production/assets/theme.e6d9734b.css', vite_asset_path('/app/assets/theme.css')
+ assert_equal "/vite-production/assets/main.9dcad042.js", vite_asset_path("main.ts")
+ assert_equal "/vite-production/assets/app.517bf154.css", vite_asset_path("app.css")
+ assert_equal "/vite-production/assets/logo.322aae0c.svg", vite_asset_path("images/logo.svg")
+ assert_equal "/vite-production/assets/theme.e6d9734b.css", vite_asset_path("/app/assets/theme.css")
with_dev_server_running {
- assert_equal '/vite-dev/entrypoints/main.ts', vite_asset_path('main.ts')
- assert_equal '/vite-dev/entrypoints/app.css', vite_asset_path('app.css')
- assert_equal '/vite-dev/images/logo.png', vite_asset_path('images/logo.png')
+ assert_equal "/vite-dev/entrypoints/main.ts", vite_asset_path("main.ts")
+ assert_equal "/vite-dev/entrypoints/app.css", vite_asset_path("app.css")
+ assert_equal "/vite-dev/images/logo.png", vite_asset_path("images/logo.png")
}
end
def test_vite_asset_url
- assert_equal 'https://example.com/vite-production/assets/main.9dcad042.js', vite_asset_url('main.ts')
+ assert_equal "https://example.com/vite-production/assets/main.9dcad042.js", vite_asset_url("main.ts")
with_dev_server_running {
- assert_equal 'https://example.com/vite-dev/entrypoints/main.ts', vite_asset_url('main.ts')
+ assert_equal "https://example.com/vite-dev/entrypoints/main.ts", vite_asset_url("main.ts")
}
end
def test_vite_stylesheet_tag
- assert_similar link(href: '/vite-production/assets/app.517bf154.css'), vite_stylesheet_tag('app')
- assert_equal vite_stylesheet_tag('app'), vite_stylesheet_tag('app.css')
- assert_similar link(href: '/vite-production/assets/sassy.3560956f.css'), vite_stylesheet_tag('sassy.scss')
+ assert_similar link(href: "/vite-production/assets/app.517bf154.css"), vite_stylesheet_tag("app")
+ assert_equal vite_stylesheet_tag("app"), vite_stylesheet_tag("app.css")
+ assert_similar link(href: "/vite-production/assets/sassy.3560956f.css"), vite_stylesheet_tag("sassy.scss")
with_dev_server_running {
- assert_similar link(href: '/vite-dev/entrypoints/app.css'), vite_stylesheet_tag('app')
- assert_equal vite_stylesheet_tag('app'), vite_stylesheet_tag('app.css')
+ assert_similar link(href: "/vite-dev/entrypoints/app.css"), vite_stylesheet_tag("app")
+ assert_equal vite_stylesheet_tag("app"), vite_stylesheet_tag("app.css")
if Rails::VERSION::MAJOR >= 7
- assert_similar link(href: '/vite-dev/entrypoints/sassy.scss'), vite_stylesheet_tag('sassy.scss')
+ assert_similar link(href: "/vite-dev/entrypoints/sassy.scss"), vite_stylesheet_tag("sassy.scss")
else
- assert_similar link(href: '/vite-dev/entrypoints/sassy.scss.css'), vite_stylesheet_tag('sassy.scss')
+ assert_similar link(href: "/vite-dev/entrypoints/sassy.scss.css"), vite_stylesheet_tag("sassy.scss")
end
}
end
def test_vite_preload_tag
- assert_includes vite_typescript_tag('main', host: 'example.com', protocol: 'https'), [
+ assert_includes vite_typescript_tag("main", host: "example.com", protocol: "https"), [
%(),
%(),
%(),
@@ -119,23 +120,23 @@ def test_vite_javascript_tag
%(),
%(),
%(),
- link(href: '/vite-production/assets/app.517bf154.css'),
- link(href: '/vite-production/assets/theme.e6d9734b.css'),
- link(href: '/vite-production/assets/vue.ec0a97cc.css'),
- ].join, vite_typescript_tag('main')
+ link(href: "/vite-production/assets/app.517bf154.css"),
+ link(href: "/vite-production/assets/theme.e6d9734b.css"),
+ link(href: "/vite-production/assets/vue.ec0a97cc.css"),
+ ].join, vite_typescript_tag("main")
- assert_equal vite_javascript_tag('main.ts'),
- vite_typescript_tag('main')
+ assert_equal vite_javascript_tag("main.ts"),
+ vite_typescript_tag("main")
- assert_equal vite_javascript_tag('entrypoints/frameworks/vue'),
- vite_javascript_tag('~/entrypoints/frameworks/vue.js')
+ assert_equal vite_javascript_tag("entrypoints/frameworks/vue"),
+ vite_javascript_tag("~/entrypoints/frameworks/vue.js")
with_dev_server_running {
assert_equal %(),
- vite_javascript_tag('entrypoints/frameworks/vue')
+ vite_javascript_tag("entrypoints/frameworks/vue")
assert_equal %(),
- vite_typescript_tag('main')
+ vite_typescript_tag("main")
}
end
@@ -176,22 +177,22 @@ def test_vite_react_refresh_tag_with_nonce_by_default
def test_vite_image_tag
assert_equal %(),
- vite_image_tag('images/logo.png', class: 'test', alt: 'Logo')
+ vite_image_tag("images/logo.png", class: "test", alt: "Logo")
assert_equal %(),
- vite_image_tag('images/logo.png', srcset: { 'images/logo-2x.png' => '2x' }, alt: 'Logo')
+ vite_image_tag("images/logo.png", srcset: {"images/logo-2x.png" => "2x"}, alt: "Logo")
with_dev_server_running {
- assert_equal %(), vite_image_tag('images/logo.png', alt: 'Logo')
+ assert_equal %(), vite_image_tag("images/logo.png", alt: "Logo")
assert_equal %(),
- vite_image_tag('images/logo.png', srcset: { 'images/logo-2x.png' => '2x' }, alt: 'Logo')
+ vite_image_tag("images/logo.png", srcset: {"images/logo-2x.png" => "2x"}, alt: "Logo")
}
end
def test_vite_picture_tag
- if Rails.gem_version >= Gem::Version.new('7.1.0')
- assert_equal <<~HTML.gsub(/\n\s*/, ''), vite_picture_tag('images/logo.svg', 'images/logo.png', class: 'test', image: { alt: 'Logo' })
+ if Rails.gem_version >= Gem::Version.new("7.1.0")
+ assert_equal <<~HTML.gsub(/\n\s*/, ""), vite_picture_tag("images/logo.svg", "images/logo.png", class: "test", image: {alt: "Logo"})