blinka-reporter 0.2.0 → 0.3.3

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: 9e4c4ccf6dd86400f02f520904fe168fcfe7530db71966b818844a0295369a50
4
- data.tar.gz: 34ef6d0a3c4ff1a1b8bd2c9f1fb62f139db83179c1665113ff2297c589f29547
3
+ metadata.gz: 76add87e3b4c07e52d38ace7ea5c8359b0eb2dc636165ffdf753fb3d475ed119
4
+ data.tar.gz: 5322abc35807213e72c59876ab0b33d5aaa8312bc8d56daf4203d34737666f5d
5
5
  SHA512:
6
- metadata.gz: 564f1f7b0088fcb2465e9a950e22cf1cfd2d7e6c8d4cbcc35cfb8392e4f7896587bf1a7432f42028474f39037b49d17adc29416b7e431f29bb22079c2e556b2f
7
- data.tar.gz: 3ad6f5d44f1851e4cbba08e601270939b1922f92cf47a5d722a9b299fa0d304ceb10afd70c669986075304b16cd11897b2faddc0540618e25ef5214faf2868fa
6
+ metadata.gz: bff827a035306476db6c83740fa95fb6a620c9475e012ef7d48b9d6feac766fc47f31e91c63bb9ecca57bddb2064c3951b97393d5206d4937b44e62078518a5d
7
+ data.tar.gz: 6e1432283c7f061f44448b67cd4af16be906b4baf38cda9947ea6b9d4af1d4e4a1ebaf96b7231685afbfffc9d10ee6042103921f8c01dcf04b0b8f1db3a256b2
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
- @commit = ENV.fetch('BLINKA_COMMIT', `git rev-parse HEAD`.chomp)
26
+ @commit = BlinkaClient.find_commit
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:)
@@ -160,4 +198,11 @@ class BlinkaClient
160
198
  }
161
199
  }
162
200
  end
201
+
202
+ def self.find_commit
203
+ ENV.fetch(
204
+ 'BLINKA_COMMIT',
205
+ ENV.fetch('HEROKU_TEST_RUN_COMMIT_VERSION', `git rev-parse HEAD`.chomp)
206
+ )
207
+ end
163
208
  end
@@ -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)
@@ -25,15 +26,18 @@ module Minitest
25
26
  end
26
27
 
27
28
  def report
28
- tap_report unless ENV['BLINKA_TAP'].nil?
29
- blinka_report
30
-
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
31
35
  super
32
36
  end
33
37
 
34
38
  private
35
39
 
36
- def blinka_report
40
+ def json_report
37
41
  result = {
38
42
  total_time: total_time,
39
43
  nbr_tests: count,
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.2.0
4
+ version: 0.3.3
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-07 00:00:00.000000000 Z
11
+ date: 2021-02-13 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: []