Skip to content

Commit

Permalink
Support screenshots from rspec
Browse files Browse the repository at this point in the history
- Bump to version 0.6.0
  • Loading branch information
davidwessman committed Feb 20, 2022
1 parent 60f0929 commit 9c76707
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 86 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.0] - 2022-02-20

- Adds support for Rspec.
- Remove support for `BLINKA_REPORT`, instead use `bundle exec blinka-reporter --blinka` for reporting.
- Remove `BLINKA_TAP` and replace with `bundle exec blinka-reporter --tap`.
- Restructure gem internals.
- Support Rspec screenshots.

## [0.5.2] - 2022-02-01

Expand Down Expand Up @@ -127,7 +130,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Handle inconsistency in source_location of test result in Minitest for different versions.

[unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.2...HEAD
[unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.0...HEAD
[0.5.2]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.2...v0.6.0
[0.5.2]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.1...v0.5.2
[0.5.1]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/davidwessman/blinka_reporter/compare/v0.4.0...v0.5.0
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bundle exec rspec --formatter RspecJunitFormatter --out ./rspec.xml

Add a step to your Github Action Workflow after running tests:

```yaml
````yaml
- name: Minitest
env:
BLINKA_JSON: true
Expand All @@ -72,6 +72,10 @@ Add a step to your Github Action Workflow after running tests:
BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
run: bundle exec blinka-reporter --path ./blinka_results.json --blinka


```yaml
- name: Rspec
run: bundle exec rspec --formatter RspecJunitFormatter --out ./rspec.xml
- name: Report minitest to Blinka
env:
BLINKA_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
Expand All @@ -80,13 +84,13 @@ Add a step to your Github Action Workflow after running tests:
BLINKA_TEAM_ID: ${{ secrets.BLINKA_TEAM_ID }}
BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
run: bundle exec blinka-reporter --path ./rspec.xml --blinka
```
````
`BLINKA_TAG` is optional and can be used to separate different reports, for example when using a build matrix.

## How to make multiple test runs into one report?

**Only reported for Minitest, open an issue for Rspec-support**
**Only supported for Minitest, open an issue for Rspec-support**

For example when running tests in parallel you might need to run system tests separately.
By first using `BLINKA_JSON` it will create a clean file, `BLINKA_APPEND` will append the results.
Expand Down Expand Up @@ -142,8 +146,6 @@ ok 13 - test/test_blinka_minitest.rb - test_message_no_failure
ok 14 - test/test_blinka_minitest.rb - test_source_location
```

It should format tests as TAP-format.

# Development

## Release new version
Expand Down
2 changes: 1 addition & 1 deletion lib/blinka_reporter/blinka.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def report
@data
.fetch(:results, [])
.map do |result|
if result.key?(:image)
if !result[:image].nil?
result[:image] = Blinka.upload_image(filepath: result[:image])
result
else
Expand Down
9 changes: 9 additions & 0 deletions lib/blinka_reporter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def self.xml_test_cases(test_cases)
failure =
test_case.nodes.select { |node| node.name == 'failure' }.first
if failure
result[:image] = get_image_path(failure.text)
result[:result] = 'fail'
result[:backtrace] = failure.text.split('\n')
result[:message] = failure.attributes[:message]
Expand All @@ -96,5 +97,13 @@ def self.xml_test_cases(test_cases)
result
end
end

def self.get_image_path(text)
path = /^\[Screenshot\]:\s([\S]*)$/.match(text)
return if path.nil?
path = path[1]
return unless File.exists?(path)
path
end
end
end
42 changes: 26 additions & 16 deletions lib/blinka_reporter/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,49 @@ class Tap
# Based on https://github.com/kern/minitest-reporters/blob/master/lib/minitest/reporters/progress_reporter.rb
# Tries to adhere to https://testanything.org/tap-specification.html
TAP_COMMENT_PAD = 8
attr_reader(:data)

def self.report(data)
Tap.new(data).report
end

def initialize(data)
@data = data
results = Array(data[:results])
return if results.size == 0

@data = <<~REPORT
TAP version 13
1..#{results.size}
#{test_results(results)}
REPORT
end

def report
tests = @data[:results]
puts
puts('TAP version 13')
puts("1..#{tests.size}")
tests.each_with_index do |test, index|
def test_results(results)
report = []
results.each_with_index do |test, index|
test_str = "#{test[:path]} - #{test[:name].tr('#', '_')}"
result = test[:result]
if result == 'pass'
puts "ok #{index + 1} - #{test_str}"
report << "ok #{index + 1} - #{test_str}"
elsif result == 'skip'
puts "ok #{index + 1} # skip: #{test_str}"
report << "ok #{index + 1} # skip: #{test_str}"
elsif result == 'fail'
puts "not ok #{index + 1} - failed: #{test_str}"
test[:message].each_line { |line| print_padded_comment(line) }

Array(test[:backtrace]).each { |line| print_padded_comment(line) }
puts
report << "not ok #{index + 1} - failed: #{test_str}"
test[:message].split('\n') do |line|
report << "##{' ' * TAP_COMMENT_PAD + line}"
end
report << '#'
Array(test[:backtrace]).each do |line|
report << "##{' ' * TAP_COMMENT_PAD + line}"
end
report << ''
end
end
report.join("\n")
end

def print_padded_comment(line)
puts "##{' ' * TAP_COMMENT_PAD + line}"
def report
puts(@data)
end
end
end
2 changes: 1 addition & 1 deletion lib/blinka_reporter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BlinkaReporter
VERSION = '0.5.2'.freeze
VERSION = '0.6.0'.freeze
end
Loading

0 comments on commit 9c76707

Please sign in to comment.