This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
theme push --development --json
to output the proper exit code (#…
- Loading branch information
Showing
8 changed files
with
189 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module ShopifyCLI | ||
module Theme | ||
class Syncer | ||
## | ||
# ShopifyCLI::Theme::Syncer::ErrorReporter allows delaying log of errors, | ||
# mainly to not break the progress bar. | ||
# | ||
class ErrorReporter | ||
attr_reader :ctx, :delayed_errors | ||
|
||
def initialize(ctx) | ||
@ctx = ctx | ||
@has_any_error = false | ||
@delay_errors = false | ||
@delayed_errors = [] | ||
end | ||
|
||
def delay_errors! | ||
@delay_errors = true | ||
end | ||
|
||
def report_errors! | ||
@delay_errors = false | ||
@delayed_errors.each { |error| report_error(error) } | ||
@delayed_errors.clear | ||
end | ||
|
||
def report_error(error_message) | ||
if @delay_errors | ||
@delayed_errors << error_message | ||
else | ||
@has_any_error = true | ||
@ctx.puts(error_message) | ||
end | ||
end | ||
|
||
def has_any_error? | ||
@has_any_error | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module ShopifyCLI | ||
module Theme | ||
class Syncer | ||
class Operation < Struct.new(:method, :file) | ||
def to_s | ||
"#{method} #{file&.relative_path}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "shopify_cli/theme/syncer" | ||
|
||
module ShopifyCLI | ||
module Theme | ||
class Syncer | ||
class ErrorReporterTest < Minitest::Test | ||
def setup | ||
super | ||
@error_reporter = ErrorReporter.new(@context) # stub(puts: nil)) | ||
end | ||
|
||
def test_report_errors_with_standard_errors | ||
io = capture_io do | ||
@error_reporter.report_error("error 1") | ||
@error_reporter.report_error("error 2") | ||
end | ||
|
||
io_messages = io.join | ||
|
||
assert_match("error 1", io_messages) | ||
assert_match("error 2", io_messages) | ||
end | ||
|
||
def test_report_errors_with_delayed_errors | ||
@error_reporter.delay_errors! | ||
|
||
before_report_errors = capture_io do | ||
@error_reporter.report_error("error 1") | ||
@error_reporter.report_error("error 2") | ||
end | ||
|
||
after_report_errors = capture_io do | ||
@error_reporter.report_errors! | ||
end | ||
|
||
before_report_io = before_report_errors.join | ||
after_report_io = after_report_errors.join | ||
|
||
assert_empty(before_report_io) | ||
refute_empty(after_report_io) | ||
assert_match("error 1", after_report_io) | ||
assert_match("error 2", after_report_io) | ||
end | ||
|
||
def test_has_any_error_when_no_error_was_reported | ||
refute(@error_reporter.has_any_error?) | ||
end | ||
|
||
def test_has_any_error_when_an_error_was_reported | ||
@error_reporter.report_error("error 1") | ||
assert(@error_reporter.has_any_error?) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "shopify_cli/theme/syncer" | ||
|
||
module ShopifyCLI | ||
module Theme | ||
class Syncer | ||
class OperationTest < Minitest::Test | ||
def test_to_s | ||
file = stub(relative_path: "sections/apps.liquid") | ||
operation = Operation.new("update", file) | ||
|
||
assert_equal("update sections/apps.liquid", operation.to_s) | ||
end | ||
|
||
def test_to_s_when_file_is_nil | ||
operation = Operation.new("update", nil) | ||
|
||
assert_equal("update ", operation.to_s) | ||
end | ||
end | ||
end | ||
end | ||
end |