Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.xcworkspace/
.DS_Store
.android-test-*
.bundle/*
.ccache/*
!.ccache/ccache.conf
.cxx/
Expand Down
4 changes: 2 additions & 2 deletions packages/app/.rubocop.yml → .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Style/HashTransformValues:

Style/OneClassPerFile:
Exclude:
- ios/test_app.rb
- test/test_test_app.rb
- packages/app/ios/test_app.rb
- packages/app/test/test_test_app.rb

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"test": "node scripts/internal/test.mts",
"test:js": "node --no-warnings --test $(git ls-files '*.test.mts')",
"test:matrix": "node scripts/testing/test-matrix.mts",
"test:rb": "bundle exec ruby -Ilib:test -e \"Dir.glob('./test/test_*.rb').each { |file| require(file) }\""
"test:rb": "bundle exec ruby -Ilib:test -rgithub_annotations -e \"Dir.glob('./test/test_*.rb').each { |file| require(file) }\""
},
"dependencies": {
"@rnx-kit/react-native-host": "^0.5.21",
Expand Down
55 changes: 55 additions & 0 deletions packages/app/test/github_annotations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require('minitest')

# Reports test failures as GitHub Actions annotations. Unlike problem matchers,
# workflow commands support multiline messages (newlines are encoded as `%0A`).
#
# See https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands
module GitHubAnnotations
class Reporter < Minitest::AbstractReporter
def initialize(io)
super()
@io = io
@annotations = []
end

def record(result)
return if result.passed? || result.skipped?

failure = result.failure
file, line = parse_location(failure.location)
title = "#{result.class_name}##{result.name}"
@annotations << "::error file=#{escape_property(file)},line=#{line}," \
"title=#{escape_property(title)}::#{escape_data(failure.message.rstrip)}"
end

# Workflow commands must start on a new line, so we cannot print them
# while progress is being reported.
def report
@io.puts(@annotations) unless @annotations.empty?
end

private

def escape_data(value)
value.to_s.gsub('%', '%25').gsub("\r", '%0D').gsub("\n", '%0A')
end

def escape_property(value)
escape_data(value).gsub(':', '%3A').gsub(',', '%2C')
end

# The runner makes absolute paths under `GITHUB_WORKSPACE` relative to it.
def parse_location(location)
file, line = location.match(/\A(.*):(\d+)\z/)&.captures || [location, 1]
[File.expand_path(file), line]
end
end

def self.minitest_plugin_init(options)
return unless ENV['GITHUB_ACTIONS'] == 'true'

Minitest.reporter << Reporter.new(options[:io])
end
end

Minitest.register_plugin(GitHubAnnotations)
Loading