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 %(Logo), - vite_image_tag('images/logo.png', class: 'test', alt: 'Logo') + vite_image_tag("images/logo.png", class: "test", alt: "Logo") assert_equal %(Logo), - 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 %(Logo), vite_image_tag('images/logo.png', alt: 'Logo') + assert_equal %(Logo), vite_image_tag("images/logo.png", alt: "Logo") assert_equal %(Logo), - 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"}) diff --git a/test/manifest_test.rb b/test/manifest_test.rb index 6982469b..b2461c2f 100644 --- a/test/manifest_test.rb +++ b/test/manifest_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class ManifestTest < ViteRuby::Test def setup @@ -13,60 +13,60 @@ def teardown super end - delegate :path_for, :lookup, :lookup!, :resolve_entry_name, :vite_client_src, to: 'ViteRuby.instance.manifest' + delegate :path_for, :lookup, :lookup!, :resolve_entry_name, :vite_client_src, to: "ViteRuby.instance.manifest" def test_resolve_entry_name - assert_equal 'entrypoints/application.js', resolve_entry_name('application', type: :javascript) - assert_equal 'entrypoints/application.js', resolve_entry_name('application.js', type: :javascript) - assert_equal 'entrypoints/application.js', resolve_entry_name('application.js') - assert_equal 'entrypoints/application.ts', resolve_entry_name('application', type: :typescript) - assert_equal 'entrypoints/application.ts', resolve_entry_name('application.ts', type: :typescript) - - assert_equal 'entrypoints/styles.css', resolve_entry_name('styles', type: :stylesheet) - assert_equal 'entrypoints/styles.css', resolve_entry_name('styles.css', type: :stylesheet) - assert_equal 'entrypoints/styles.css', resolve_entry_name('styles.css') - assert_equal 'entrypoints/styles.scss', resolve_entry_name('styles.scss', type: :stylesheet) - - assert_equal 'entrypoints/logo.svg', resolve_entry_name('logo.svg') - assert_equal 'images/logo.svg', resolve_entry_name('images/logo.svg') - assert_equal 'images/logo.svg', resolve_entry_name('~/images/logo.svg') - assert_equal 'favicon.ico', resolve_entry_name('~/favicon.ico') - assert_equal '../../package.json', resolve_entry_name('/package.json') - assert_equal '../../images/logo.svg', resolve_entry_name('/images/logo.svg') - assert_equal '../assets/theme.css', resolve_entry_name('/app/assets/theme.css') + assert_equal "entrypoints/application.js", resolve_entry_name("application", type: :javascript) + assert_equal "entrypoints/application.js", resolve_entry_name("application.js", type: :javascript) + assert_equal "entrypoints/application.js", resolve_entry_name("application.js") + assert_equal "entrypoints/application.ts", resolve_entry_name("application", type: :typescript) + assert_equal "entrypoints/application.ts", resolve_entry_name("application.ts", type: :typescript) + + assert_equal "entrypoints/styles.css", resolve_entry_name("styles", type: :stylesheet) + assert_equal "entrypoints/styles.css", resolve_entry_name("styles.css", type: :stylesheet) + assert_equal "entrypoints/styles.css", resolve_entry_name("styles.css") + assert_equal "entrypoints/styles.scss", resolve_entry_name("styles.scss", type: :stylesheet) + + assert_equal "entrypoints/logo.svg", resolve_entry_name("logo.svg") + assert_equal "images/logo.svg", resolve_entry_name("images/logo.svg") + assert_equal "images/logo.svg", resolve_entry_name("~/images/logo.svg") + assert_equal "favicon.ico", resolve_entry_name("~/favicon.ico") + assert_equal "../../package.json", resolve_entry_name("/package.json") + assert_equal "../../images/logo.svg", resolve_entry_name("/images/logo.svg") + assert_equal "../assets/theme.css", resolve_entry_name("/app/assets/theme.css") with_dev_server_running { - assert_equal 'entrypoints/logo.svg', resolve_entry_name('logo.svg') - assert_equal 'images/logo.svg', resolve_entry_name('images/logo.svg') - assert_equal 'images/logo.svg', resolve_entry_name('~/images/logo.svg') - assert_equal 'favicon.ico', resolve_entry_name('~/favicon.ico') - assert_equal "/@fs#{ViteRuby.config.root}/package.json", resolve_entry_name('/package.json') - assert_equal "/@fs#{ViteRuby.config.root}/images/logo.svg", resolve_entry_name('/images/logo.svg') - assert_equal "/@fs#{ViteRuby.config.root}/app/assets/theme.css", resolve_entry_name('/app/assets/theme.css') + assert_equal "entrypoints/logo.svg", resolve_entry_name("logo.svg") + assert_equal "images/logo.svg", resolve_entry_name("images/logo.svg") + assert_equal "images/logo.svg", resolve_entry_name("~/images/logo.svg") + assert_equal "favicon.ico", resolve_entry_name("~/favicon.ico") + assert_equal "/@fs#{ViteRuby.config.root}/package.json", resolve_entry_name("/package.json") + assert_equal "/@fs#{ViteRuby.config.root}/images/logo.svg", resolve_entry_name("/images/logo.svg") + assert_equal "/@fs#{ViteRuby.config.root}/app/assets/theme.css", resolve_entry_name("/app/assets/theme.css") } - assert_equal 'entrypoints/application.js', resolve_entry_name('entrypoints/application.js') + assert_equal "entrypoints/application.js", resolve_entry_name("entrypoints/application.js") end def test_lookup_exception! stub_builder(build_successful: true) { - asset_file = 'calendar.js' + asset_file = "calendar.js" error = assert_raises_manifest_missing_entry_error { path_for(asset_file) } assert_match "Vite Ruby can't find entrypoints/#{asset_file} in the manifests", error.message assert_match '"autoBuild" is set to `false`', error.message - asset_file = 'images/logo.gif' + asset_file = "images/logo.gif" error = assert_raises_manifest_missing_entry_error { path_for(asset_file) } assert_match "Vite Ruby can't find #{asset_file} in the manifests", error.message - asset_file = '/app/styles/theme.css' + asset_file = "/app/styles/theme.css" error = assert_raises_manifest_missing_entry_error { path_for(asset_file) } assert_match "Vite Ruby can't find ../styles/theme.css in the manifests", error.message - asset_file = '~/favicon.ico' + asset_file = "~/favicon.ico" error = assert_raises_manifest_missing_entry_error { path_for(asset_file) } assert_match "Vite Ruby can't find favicon.ico in the manifests", error.message @@ -77,38 +77,38 @@ def test_lookup_exception! def test_lookup_exception_when_auto_build stub_builder(build_successful: true) { - asset_file = 'calendar.js' + asset_file = "calendar.js" error = assert_raises_manifest_missing_entry_error(auto_build: true) do path_for(asset_file) end assert_match "Vite Ruby can't find entrypoints/#{asset_file} in the manifests", error.message - assert_match 'The file path is incorrect.', error.message + assert_match "The file path is incorrect.", error.message } end def test_lookup_exception_when_build_failed error_lines = [ - 'SyntaxError: Hero.jsx: Unexpected token (6:6)', - ' 4 | return <>', + "SyntaxError: Hero.jsx: Unexpected token (6:6)", + " 4 | return <>", ] stub_builder(build_successful: false, build_errors: error_lines.join("\n")) { - asset_file = 'calendar.js' + asset_file = "calendar.js" error = assert_raises_manifest_missing_entry_error do path_for(asset_file) end assert_match "Vite Ruby can't find entrypoints/#{asset_file} in the manifests", error.message - assert_match 'The last build failed.', error.message + assert_match "The last build failed.", error.message assert_match " #{error_lines[0]}", error.message assert_match " #{error_lines[1]}", error.message } end def test_lookup_with_type_exception! - asset_file = 'calendar' + asset_file = "calendar" error = assert_raises_manifest_missing_entry_error do path_for(asset_file, type: :javascript) @@ -119,115 +119,115 @@ def test_lookup_with_type_exception! def test_lookup_success! entry = { - 'file' => prefixed('main.9dcad042.js'), - 'src' => 'entrypoints/main.ts', - 'isEntry' => true, - 'imports' => [ - { 'file' => prefixed('log.818edfb8.js') }, + "file" => prefixed("main.9dcad042.js"), + "src" => "entrypoints/main.ts", + "isEntry" => true, + "imports" => [ + {"file" => prefixed("log.818edfb8.js")}, { - 'file' => prefixed('vue.3002ada6.js'), - 'src' => 'entrypoints/frameworks/vue.js', - 'isEntry' => true, - 'imports' => [ - { 'file' => prefixed('vendor.0f7c0ec3.js') }, + "file" => prefixed("vue.3002ada6.js"), + "src" => "entrypoints/frameworks/vue.js", + "isEntry" => true, + "imports" => [ + {"file" => prefixed("vendor.0f7c0ec3.js")}, ], - 'css' => [ - prefixed('vue.ec0a97cc.css'), + "css" => [ + prefixed("vue.ec0a97cc.css"), ], - 'assets' => [ - prefixed('logo.322aae0c.svg'), + "assets" => [ + prefixed("logo.322aae0c.svg"), ], }, - { 'file' => prefixed('vendor.0f7c0ec3.js') }, + {"file" => prefixed("vendor.0f7c0ec3.js")}, ], - 'css' => [ - prefixed('app.517bf154.css'), - prefixed('theme.e6d9734b.css'), + "css" => [ + prefixed("app.517bf154.css"), + prefixed("theme.e6d9734b.css"), ], } - assert_equal entry['file'], path_for('main', type: :typescript) - assert_equal entry, lookup!('main.ts', type: :javascript) - assert_equal lookup!('main', type: :typescript), lookup!('main.ts', type: :javascript) - assert_equal lookup!('entrypoints/main', type: :typescript), lookup!('main.ts') + assert_equal entry["file"], path_for("main", type: :typescript) + assert_equal entry, lookup!("main.ts", type: :javascript) + assert_equal lookup!("main", type: :typescript), lookup!("main.ts", type: :javascript) + assert_equal lookup!("entrypoints/main", type: :typescript), lookup!("main.ts") end def test_lookup_success_with_dev_server_running! - refresh_config(mode: 'development') + refresh_config(mode: "development") with_dev_server_running { - entry = { 'file' => '/vite-dev/entrypoints/application.js' } + entry = {"file" => "/vite-dev/entrypoints/application.js"} - assert_equal entry, lookup!('application.js', type: :javascript) - assert_equal entry, lookup!('entrypoints/application.js') + assert_equal entry, lookup!("application.js", type: :javascript) + assert_equal entry, lookup!("entrypoints/application.js") - assert_equal '/vite-dev/entrypoints/application.ts', - path_for('application', type: :typescript) + assert_equal "/vite-dev/entrypoints/application.ts", + path_for("application", type: :typescript) - assert_equal '/vite-dev/entrypoints/styles.css', - path_for('styles', type: :stylesheet) + assert_equal "/vite-dev/entrypoints/styles.css", + path_for("styles", type: :stylesheet) - assert_equal '/vite-dev/image/logo.png', - path_for('image/logo.png') + assert_equal "/vite-dev/image/logo.png", + path_for("image/logo.png") - assert_equal '/vite-dev/logo.png', - path_for('~/logo.png') + assert_equal "/vite-dev/logo.png", + path_for("~/logo.png") assert_equal "/vite-dev/@fs#{ViteRuby.config.root}/app/assets/theme.css", - path_for('/app/assets/theme', type: :stylesheet) + path_for("/app/assets/theme", type: :stylesheet) } end def test_vite_client_src - refresh_config(mode: 'development') + refresh_config(mode: "development") assert_nil vite_client_src with_dev_server_running { - assert_equal '/vite-dev/@vite/client', vite_client_src + assert_equal "/vite-dev/@vite/client", vite_client_src } - refresh_config(asset_host: 'http://example.com', mode: 'development') + refresh_config(asset_host: "http://example.com", mode: "development") with_dev_server_running { - assert_equal 'http://example.com/vite-dev/@vite/client', vite_client_src + assert_equal "http://example.com/vite-dev/@vite/client", vite_client_src } end def test_lookup_nil - assert_nil lookup('foo.js') + assert_nil lookup("foo.js") end def test_lookup_nested_entrypoint # Because it's a nested dir, it won't be prefixed automatically and it must # be explicitly disambiguated. - assert_nil lookup('frameworks/vue.js') + assert_nil lookup("frameworks/vue.js") - file = prefixed('vue.3002ada6.js') + file = prefixed("vue.3002ada6.js") - assert_equal file, path_for('entrypoints/frameworks/vue.js') - assert_equal file, path_for('~/entrypoints/frameworks/vue.js') - assert_equal lookup('~/entrypoints/frameworks/vue', type: :javascript), lookup('entrypoints/frameworks/vue.js') + assert_equal file, path_for("entrypoints/frameworks/vue.js") + assert_equal file, path_for("~/entrypoints/frameworks/vue.js") + assert_equal lookup("~/entrypoints/frameworks/vue", type: :javascript), lookup("entrypoints/frameworks/vue.js") end def test_path_for_assets - assert_equal prefixed('logo.f42fb7ea.png'), path_for('images/logo.png') - assert_equal prefixed('logo.f42fb7ea.png'), path_for('~/images/logo.png') + assert_equal prefixed("logo.f42fb7ea.png"), path_for("images/logo.png") + assert_equal prefixed("logo.f42fb7ea.png"), path_for("~/images/logo.png") - assert_equal prefixed('external.d1ae13f1.js'), path_for('/app/assets/external', type: :javascript) - assert_equal prefixed('logo.03d6d6da.png'), path_for('/app/assets/logo.png') - assert_equal prefixed('theme.e6d9734b.css'), path_for('/app/assets/theme', type: :stylesheet) + assert_equal prefixed("external.d1ae13f1.js"), path_for("/app/assets/external", type: :javascript) + assert_equal prefixed("logo.03d6d6da.png"), path_for("/app/assets/logo.png") + assert_equal prefixed("theme.e6d9734b.css"), path_for("/app/assets/theme", type: :stylesheet) end def test_lookup_success - entry = { 'file' => prefixed('app.517bf154.css'), 'src' => 'entrypoints/app.css' } + entry = {"file" => prefixed("app.517bf154.css"), "src" => "entrypoints/app.css"} - assert_equal entry, lookup('app.css') - assert_equal entry, lookup('app.css', type: :stylesheet) - assert_equal entry, lookup('app', type: :stylesheet) + assert_equal entry, lookup("app.css") + assert_equal entry, lookup("app.css", type: :stylesheet) + assert_equal entry, lookup("app", type: :stylesheet) - entry = { 'file' => prefixed('logo.322aae0c.svg'), 'src' => 'images/logo.svg' } + entry = {"file" => prefixed("logo.322aae0c.svg"), "src" => "images/logo.svg"} - assert_equal entry, lookup('images/logo.svg') + assert_equal entry, lookup("images/logo.svg") end private @@ -241,7 +241,7 @@ def assert_raises_manifest_missing_entry_error(auto_build: false, &block) end def manifest_path - 'public/vite-production/.vite/manifest.json' + "public/vite-production/.vite/manifest.json" end def prefixed(file) diff --git a/vite_hanami/lib/vite_hanami/tag_helpers.rb b/vite_hanami/lib/vite_hanami/tag_helpers.rb index c0cf9685..aba341ff 100644 --- a/vite_hanami/lib/vite_hanami/tag_helpers.rb +++ b/vite_hanami/lib/vite_hanami/tag_helpers.rb @@ -6,7 +6,7 @@ module ViteHanami::TagHelpers def vite_client return unless src = vite_manifest.vite_client_src - html.script(src: src, type: 'module') + html.script(src: src, type: "module") end # Public: Renders a script tag to enable HMR with React Refresh. @@ -25,12 +25,12 @@ def vite_asset_path(name, **options) # Public: Renders a ".html_safe + "".html_safe end # Public: Renders a script tag to enable HMR with React Refresh. @@ -32,13 +32,13 @@ def vite_asset_url(name, **options) # Public: Renders a