Skip to content

Commit

Permalink
Mute logger in tests
Browse files Browse the repository at this point in the history
Adapt test output to write to a StringIO.

This cleans up the the logging output.
  • Loading branch information
ewalk153 committed Jan 24, 2023
1 parent e8e4c5f commit 904c2a8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/clients/graphql/admin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def build_client
if !defined?("@api_version")
ShopifyAPI::Clients::Graphql::Admin.new(session: @session)
else
setup_mock_logger
ShopifyAPI::Clients::Graphql::Admin.new(session: @session, api_version: @api_version)
end
end
Expand Down
1 change: 1 addition & 0 deletions test/clients/graphql/storefront_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def build_client
if !defined?("@api_version")
ShopifyAPI::Clients::Graphql::Storefront.new(@shop, @storefront_access_token)
else
setup_mock_logger
ShopifyAPI::Clients::Graphql::Storefront.new(@shop, @storefront_access_token, api_version: @api_version)
end
end
Expand Down
1 change: 1 addition & 0 deletions test/clients/rest/admin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_path_starting_at_admin_overrides_default
end

def test_api_version_can_be_overrriden
setup_mock_logger
@api_version = "2022-07"
run_test(:post)
end
Expand Down
1 change: 1 addition & 0 deletions test/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_send_a_warning_if_log_level_is_invalid
scope: [],
is_private: false,
is_embedded: true,
logger: Logger.new(T.let(StringIO.new, StringIO)),
session_storage: ShopifyAPI::Auth::FileSessionStorage.new,
user_agent_prefix: nil,
old_api_secret_key: nil,
Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def modify_context(
log_level: :off,
)
end

sig { void }
def setup_mock_logger
string_log_output = T.let(StringIO.new, StringIO)
modify_context(logger: Logger.new(string_log_output))

string_log_output
end
end
end
end
3 changes: 3 additions & 0 deletions test/test_helpers/graphql_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module TestHelpers
module GraphQLClient
def test_can_make_query
setup_mock_logger
query = <<~QUERY
{
shop {
Expand All @@ -26,6 +27,7 @@ def test_can_make_query
end

def test_can_make_query_with_variables
setup_mock_logger
query = <<~QUERY
query myTestQuery($first: Int) {
products (first: $first) {
Expand Down Expand Up @@ -55,6 +57,7 @@ def test_can_make_query_with_variables
end

def test_can_override_api_version
setup_mock_logger
@api_version = "2022-01"
query = <<~QUERY
query myTestQuery($first: Int) {
Expand Down

0 comments on commit 904c2a8

Please sign in to comment.