Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Fix ShopifyCLI::Theme::DevServer::CdnFonts class to support any font (
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro authored and amcaplan committed Dec 21, 2021
1 parent 0a6b7f1 commit 3352b29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
* [#1812](https://github.com/Shopify/shopify-cli/pull/1812): App creation with Rails 7
* [#1821](https://github.com/Shopify/shopify-cli/pull/1821): Fix Shopify hosted fonts to load via the local preview URL
* [#1830](https://github.com/Shopify/shopify-cli/pull/1830): Fix hot reload when users update many files "simultaneously"
* [#1837](https://github.com/Shopify/shopify-cli/pull/1837): Fix `ShopifyCLI::Theme::DevServer::CdnFonts` class to support any font

## Version 2.7.2
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_cli/theme/dev_server/cdn_fonts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Theme
module DevServer
class CdnFonts
FONTS_PATH = "/fonts"
FONTS_CDN = "https://fonts.shopifycdn.com/assistant"
FONTS_CDN = "https://fonts.shopifycdn.com"
FONTS_REGEX = %r{#{FONTS_CDN}}

def initialize(app, theme:)
Expand Down
28 changes: 23 additions & 5 deletions test/shopify-cli/theme/dev_server/cdn_fonts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ShopifyCLI
module Theme
module DevServer
class CdnFontsTest < Minitest::Test
def test_replace_local_fonts_in_reponse_body
def test_replace_local_assistant_n4_font_in_reponse_body
original_html = <<~HTML
<html>
<head>
Expand All @@ -18,7 +18,25 @@ def test_replace_local_fonts_in_reponse_body
expected_html = <<~HTML
<html>
<head>
<link rel="preload" as="font" href="/fonts/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin="">
<link rel="preload" as="font" href="/fonts/assistant/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin="">
</head>
</html>
HTML
assert_equal(expected_html, serve(original_html).body)
end

def test_replace_local_firasans_n4_font_in_reponse_body
original_html = <<~HTML
<html>
<head>
<link rel="preload" as="font" href="https://fonts.shopifycdn.com/fira_sans/firasans_n4.1b65c27c1439cf29ece2163ea4a810840646dbdc.woff?&hmac=67f25fee11d74ab8def16edf19d274a09843e99443cbf63edc49aecf070d7ec8" type="font/woff2" crossorigin="">
</head>
</html>
HTML
expected_html = <<~HTML
<html>
<head>
<link rel="preload" as="font" href="/fonts/fira_sans/firasans_n4.1b65c27c1439cf29ece2163ea4a810840646dbdc.woff?&hmac=67f25fee11d74ab8def16edf19d274a09843e99443cbf63edc49aecf070d7ec8" type="font/woff2" crossorigin="">
</head>
</html>
HTML
Expand All @@ -36,7 +54,7 @@ def test_replace_local_fonts_on_same_line
expected_html = <<~HTML
<html>
<head>
<link rel="preload" as="font" href="/fonts/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin=""><link rel="preload" as="font" href="/fonts/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin="">
<link rel="preload" as="font" href="/fonts/assistant/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin=""><link rel="preload" as="font" href="/fonts/assistant/assistant_n4.bcd3d09dcb631dec5544b8fb7b154ff234a44630.woff2?hmac=0a2e92d6956b1312ef7d59f4850549a6e43a908ccf24df47f07b0b4c6da5837d" type="font/woff2" crossorigin="">
</head>
</html>
HTML
Expand Down Expand Up @@ -64,7 +82,7 @@ def test_serve_font_from_fonts_cdn
})
.to_return(status: 200, body: expected_body, headers: {})

response = serve(path: "/fonts/font.123.woff2?hmac=456")
response = serve(path: "/fonts/assistant/font.123.woff2?hmac=456")
actual_body = response.body

assert_equal expected_body, actual_body
Expand All @@ -78,7 +96,7 @@ def test_404_on_missing_cdn_fonts
})
.to_return(status: 404, body: "Not found", headers: {})

response = serve(path: "/fonts/missing.123.woff2?hmac=456")
response = serve(path: "/fonts/assistant/missing.123.woff2?hmac=456")

assert_equal(404, response.status)
assert_equal("Not found", response.body)
Expand Down

0 comments on commit 3352b29

Please sign in to comment.