blinka-reporter 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b1855b93d48ff636db20aac7c2bae03bf9c79f9f43db7fb0974de6bca511ed1
4
- data.tar.gz: 4e99728a7153c4d01297bbc2573204a7d7c054577b18f2f398fdd379f8344579
3
+ metadata.gz: 56e193271a3f7ffc8d089ac8e4484edb68e7a8783a1b138ceee55ba667b720e2
4
+ data.tar.gz: 70dfd466a32dba39ea0d0d28713ed979d56cdbc2cc5451cf35b54464c3ecf42e
5
5
  SHA512:
6
- metadata.gz: dabfc51219a7fb871c680791932df3fa7d1e9e7721f9be0a6f293e4acd445867cc7cb8ad60834c6cfd5d052aabdbb9ef6b66798829db86db02db25d6ae1a7af2
7
- data.tar.gz: 75f373ab3aad49c8873fec958091661962f9073ae67ecad8c975309c5e464c60106a6cc060abed1ebd246d80527510cbedadcadc7e10b6907208913e9a4a9188
6
+ metadata.gz: 2f1bd80ac40f5d2b68a6a72ff166d490835c4c58996d2019d4309cc0806ca19c7588f26f0930c8dbf25f099f7c195c06f191eb2852c4f025e266896356c9c049
7
+ data.tar.gz: 55abf722700a5a475d1e24fd93a7885c57a6b6272cc383c975b33e7707ae4df415f6560e3a00d9387da7d1dcd60830ec6589b4fee6439e713477e344b1aef501
data/lib/blinka_client.rb CHANGED
@@ -13,12 +13,21 @@ class BlinkaClient
13
13
  :jwt_token
14
14
  )
15
15
  def initialize
16
- @host = ENV.fetch('BLINKA_HOST', 'https://blinkblink.herokuapp.com')
17
- @team_id = ENV.fetch('BLINKA_TEAM_ID')
18
- @team_secret = ENV.fetch('BLINKA_TEAM_SECRET')
19
- @repository = ENV.fetch('BLINKA_REPOSITORY')
16
+ @host = ENV.fetch('BLINKA_HOST', 'https://www.blinka.app')
17
+ @team_id = ENV.fetch('BLINKA_TEAM_ID', nil)
18
+ @team_secret = ENV.fetch('BLINKA_TEAM_SECRET', nil)
19
+ @repository = ENV.fetch('BLINKA_REPOSITORY', nil)
20
20
  @tag = ENV.fetch('BLINKA_TAG', '')
21
21
  @commit = ENV.fetch('BLINKA_COMMIT', `git rev-parse HEAD`.chomp)
22
+
23
+ if @team_id.nil? || @team_secret.nil? || @repository.nil?
24
+ raise(BlinkaError, <<~EOS)
25
+ Missing configuration, make sure to set required environment variables:
26
+ - BLINKA_TEAM_ID
27
+ - BLINKA_TEAM_SECRET
28
+ - BLINKA_REPOSITORY
29
+ EOS
30
+ end
22
31
  end
23
32
  end
24
33
 
@@ -31,6 +40,12 @@ class BlinkaClient
31
40
  end
32
41
 
33
42
  def report(filepath: './blinka_results.json')
43
+ unless File.exist?(filepath)
44
+ raise(
45
+ BlinkaError,
46
+ 'Could not find blinka_results.json, did tests run with environment variable BLINKA_JSON=true set?'
47
+ )
48
+ end
34
49
  self.authenticate
35
50
  data = JSON.parse(File.open(filepath).read)
36
51
 
@@ -79,6 +94,12 @@ class BlinkaClient
79
94
  else
80
95
  raise(BlinkaError, "Could not report, got response code #{response.code}")
81
96
  end
97
+ rescue => error
98
+ raise(BlinkaError, <<-EOS)
99
+ BLINKA:
100
+ Failed to create report because of #{error.class} with message:
101
+ #{error.message}
102
+ EOS
82
103
  end
83
104
 
84
105
  def self.upload_image(filepath:)
@@ -1,6 +1,7 @@
1
1
  require 'minitest'
2
2
  require 'json'
3
3
  require 'blinka_minitest'
4
+ require 'blinka_client'
4
5
 
5
6
  module Minitest
6
7
  def self.plugin_blinka_init(options)
@@ -10,6 +11,7 @@ module Minitest
10
11
  def plugin_blinka_options(opts, options); end
11
12
 
12
13
  module BlinkaPlugin
14
+ TAP_COMMENT_PAD = 8
13
15
  class Reporter < Minitest::StatisticsReporter
14
16
  attr_accessor :tests
15
17
 
@@ -24,8 +26,18 @@ module Minitest
24
26
  end
25
27
 
26
28
  def report
29
+ tap_report if ENV['BLINKA_TAP']
30
+ json_report if ENV['BLINKA_JSON'] || ENV['BLINKA_REPORT']
31
+ BlinkaClient.new.report if ENV['BLINKA_REPORT']
32
+ rescue BlinkaClient::BlinkaError => error
33
+ puts(error)
34
+ ensure
27
35
  super
36
+ end
37
+
38
+ private
28
39
 
40
+ def json_report
29
41
  result = {
30
42
  total_time: total_time,
31
43
  nbr_tests: count,
@@ -41,6 +53,36 @@ module Minitest
41
53
  puts
42
54
  puts('Test results written to `./blinka_results.json`')
43
55
  end
56
+
57
+ # Based on https://github.com/kern/minitest-reporters/blob/master/lib/minitest/reporters/progress_reporter.rb
58
+ # Tries to adhere to https://testanything.org/tap-specification.html
59
+ def tap_report
60
+ puts
61
+ puts('TAP version 13')
62
+ puts("1..#{tests.length}")
63
+ tests.each_with_index do |test, index|
64
+ blinka = BlinkaMinitest.new(test)
65
+ test_str = "#{blinka.path} - #{test.name.tr('#', '_')}"
66
+ if test.passed?
67
+ puts "ok #{index + 1} - #{test_str}"
68
+ elsif test.skipped?
69
+ puts "ok #{index + 1} # skip: #{test_str}"
70
+ elsif test.failure
71
+ puts "not ok #{index + 1} - failed: #{test_str}"
72
+ blinka.message.each_line { |line| print_padded_comment(line) }
73
+
74
+ # test.failure.message.each_line { |line| print_padded_comment(line) }
75
+ unless test.failure.is_a?(MiniTest::UnexpectedError)
76
+ blinka.backtrace.each { |line| print_padded_comment(line) }
77
+ end
78
+ puts
79
+ end
80
+ end
81
+ end
82
+
83
+ def print_padded_comment(line)
84
+ puts "##{' ' * TAP_COMMENT_PAD + line}"
85
+ end
44
86
  end
45
87
  end
46
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blinka-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wessman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -103,7 +103,7 @@ files:
103
103
  - lib/blinka_client.rb
104
104
  - lib/blinka_minitest.rb
105
105
  - lib/minitest/blinka_plugin.rb
106
- homepage: https://rubygemspec.org/gems/blinka-reporter
106
+ homepage: https://github.com/davidwessman/blinka_reporter
107
107
  licenses:
108
108
  - MIT
109
109
  metadata: {}