blinka-reporter 0.1.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a26795f0deaada3c12bef38c660e45cca49b277362306eb199da070d4f65d28
4
- data.tar.gz: 442cad020224f803c87deb42ded273fae7c0335858f3c3e8a641480bea21ed4c
3
+ metadata.gz: 9db36c14f19ef2d7697dc175f050648686bb3364a9af178253d19ecc7af25c2b
4
+ data.tar.gz: f4988109d5c1df6c708fd595970c59d3aec179a4fce8b170792a07492061ccb0
5
5
  SHA512:
6
- metadata.gz: 1ba2584c0cbd1540246a7d1720e97340b390509ecae76642ce90ff443fde11e32719f21d820d1e0454ff9d1c9f341b8f4c82b3424529287cb4d85b8b5e05fd7d
7
- data.tar.gz: 47ef061a1734215bdb0d17087fcb1412ed081a57c6b27b764e4a2a15372feda09f759dadfc3e435e8fe9cde513ed1cd034f91be74534cb7853bb1fa19e52556f
6
+ metadata.gz: 5e79caca1a875bf579bde5dc0c306e7ec56265d15a41b86b6a0b0df61c1161eee24774d8f3063893b32d8034b25c1b89e9fe0aae45f0a9fedcca9b423a6086b2
7
+ data.tar.gz: cde67e49366ddcfdf564478664fae6cb1e6445a7bcc2c9a3782a0f651d30b70c1274b29c22b51d98fde4907c3ea7f93e7bf7a3702e1670a06ba8185b3cbfae3c
data/lib/blinka_client.rb CHANGED
@@ -2,6 +2,10 @@ require 'mimemagic'
2
2
  require 'httparty'
3
3
 
4
4
  class BlinkaClient
5
+ DEFAULT_HOST = 'https://www.blinka.app'.freeze
6
+
7
+ include HTTParty
8
+
5
9
  class BlinkaConfig
6
10
  attr_reader(
7
11
  :tag,
@@ -12,18 +16,27 @@ class BlinkaClient
12
16
  :team_secret,
13
17
  :jwt_token
14
18
  )
19
+
15
20
  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')
21
+ @host = ENV.fetch('BLINKA_HOST', DEFAULT_HOST)
22
+ @team_id = ENV.fetch('BLINKA_TEAM_ID', nil)
23
+ @team_secret = ENV.fetch('BLINKA_TEAM_SECRET', nil)
24
+ @repository = ENV.fetch('BLINKA_REPOSITORY', nil)
20
25
  @tag = ENV.fetch('BLINKA_TAG', '')
21
26
  @commit = ENV.fetch('BLINKA_COMMIT', `git rev-parse HEAD`.chomp)
27
+
28
+ if @team_id.nil? || @team_secret.nil? || @repository.nil?
29
+ raise(BlinkaError, <<~EOS)
30
+ Missing configuration, make sure to set required environment variables:
31
+ - BLINKA_TEAM_ID
32
+ - BLINKA_TEAM_SECRET
33
+ - BLINKA_REPOSITORY
34
+ EOS
35
+ end
22
36
  end
23
37
  end
24
38
 
25
39
  class BlinkaError < StandardError; end
26
- include HTTParty
27
40
 
28
41
  def initialize
29
42
  @config = BlinkaConfig.new
@@ -31,6 +44,18 @@ class BlinkaClient
31
44
  end
32
45
 
33
46
  def report(filepath: './blinka_results.json')
47
+ unless File.exist?(filepath)
48
+ raise(
49
+ BlinkaError,
50
+ 'Could not find blinka_results.json, did tests run with environment variable BLINKA_JSON=true set?'
51
+ )
52
+ end
53
+
54
+ if ENV.fetch('BLINKA_ALLOW_WEBMOCK_DISABLE', 'true') == 'true' &&
55
+ defined?(WebMock) && WebMock.respond_to?(:disable!)
56
+ WebMock.disable!
57
+ end
58
+
34
59
  self.authenticate
35
60
  data = JSON.parse(File.open(filepath).read)
36
61
 
@@ -79,6 +104,19 @@ class BlinkaClient
79
104
  else
80
105
  raise(BlinkaError, "Could not report, got response code #{response.code}")
81
106
  end
107
+ rescue => error
108
+ raise(BlinkaError, <<-EOS)
109
+ BLINKA:
110
+ Failed to create report because of #{error.class} with message:
111
+ #{error.message}
112
+ EOS
113
+ ensure
114
+ WebMock.enable! if defined?(WebMock) && WebMock.respond_to?(:enable!)
115
+ end
116
+
117
+ def self.report(filepath: './blinka_results.json')
118
+ client = BlinkaClient.new
119
+ client.report(filepath: filepath)
82
120
  end
83
121
 
84
122
  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.1
4
+ version: 0.3.2
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
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.11'
97
111
  description: Use to format test results from Minitest to use with Blinka.
98
112
  email: david@wessman.co
99
113
  executables: []