blinka-reporter 0.3.1 → 0.3.6

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: 56e193271a3f7ffc8d089ac8e4484edb68e7a8783a1b138ceee55ba667b720e2
4
- data.tar.gz: 70dfd466a32dba39ea0d0d28713ed979d56cdbc2cc5451cf35b54464c3ecf42e
3
+ metadata.gz: 06c9c5c7a1de551d63e7b5c847e8f63141b3947b2e2438bb99682df7533dbf65
4
+ data.tar.gz: 04efe62851c48eb4b956f9ab749a3c9910edaa13fdb910e3e21ab1b8687815ce
5
5
  SHA512:
6
- metadata.gz: 2f1bd80ac40f5d2b68a6a72ff166d490835c4c58996d2019d4309cc0806ca19c7588f26f0930c8dbf25f099f7c195c06f191eb2852c4f025e266896356c9c049
7
- data.tar.gz: 55abf722700a5a475d1e24fd93a7885c57a6b6272cc383c975b33e7707ae4df415f6560e3a00d9387da7d1dcd60830ec6589b4fee6439e713477e344b1aef501
6
+ metadata.gz: f2f18d7a70bec74bfa5df5777f3a31b0b87ec7d957d74a1571e1f6ee25c2e71b897f4ce89314c808579ae3448e28c98263dfe3cdbe03d262a6223d6a821a0c90
7
+ data.tar.gz: 9212e1935d61b03e366407c0a964fa5726c2d523031a61066f8b19233c9f1da23f38de3b21d5ade2e123f60498402dae054a16c8416856c6f338d81e07c5a725
data/lib/blinka_client.rb CHANGED
@@ -1,24 +1,23 @@
1
- require 'mimemagic'
2
1
  require 'httparty'
3
2
 
4
3
  class BlinkaClient
4
+ DEFAULT_HOST = 'https://www.blinka.app'.freeze
5
+ SUPPORTED_MIME_TYPES = {
6
+ jpg: 'image/jpeg',
7
+ jpeg: 'image/jpeg',
8
+ png: 'image/png'
9
+ }
10
+
11
+ include HTTParty
12
+
5
13
  class BlinkaConfig
6
- attr_reader(
7
- :tag,
8
- :commit,
9
- :host,
10
- :repository,
11
- :team_id,
12
- :team_secret,
13
- :jwt_token
14
- )
14
+ attr_reader(:host, :repository, :team_id, :team_secret, :jwt_token)
15
+
15
16
  def initialize
16
- @host = ENV.fetch('BLINKA_HOST', 'https://www.blinka.app')
17
+ @host = ENV.fetch('BLINKA_HOST', DEFAULT_HOST)
17
18
  @team_id = ENV.fetch('BLINKA_TEAM_ID', nil)
18
19
  @team_secret = ENV.fetch('BLINKA_TEAM_SECRET', nil)
19
20
  @repository = ENV.fetch('BLINKA_REPOSITORY', nil)
20
- @tag = ENV.fetch('BLINKA_TAG', '')
21
- @commit = ENV.fetch('BLINKA_COMMIT', `git rev-parse HEAD`.chomp)
22
21
 
23
22
  if @team_id.nil? || @team_secret.nil? || @repository.nil?
24
23
  raise(BlinkaError, <<~EOS)
@@ -32,7 +31,6 @@ class BlinkaClient
32
31
  end
33
32
 
34
33
  class BlinkaError < StandardError; end
35
- include HTTParty
36
34
 
37
35
  def initialize
38
36
  @config = BlinkaConfig.new
@@ -46,6 +44,12 @@ class BlinkaClient
46
44
  'Could not find blinka_results.json, did tests run with environment variable BLINKA_JSON=true set?'
47
45
  )
48
46
  end
47
+
48
+ if ENV.fetch('BLINKA_ALLOW_WEBMOCK_DISABLE', 'true') == 'true' &&
49
+ defined?(WebMock) && WebMock.respond_to?(:disable!)
50
+ WebMock.disable!
51
+ end
52
+
49
53
  self.authenticate
50
54
  data = JSON.parse(File.open(filepath).read)
51
55
 
@@ -65,13 +69,13 @@ class BlinkaClient
65
69
  body = {
66
70
  report: {
67
71
  repository: @config.repository,
68
- tag: @config.tag,
69
- commit: @config.commit,
72
+ tag: data['tag'],
73
+ commit: data['commit'],
70
74
  metadata: {
71
- total_time: data.dig('total_time'),
72
- nbr_tests: data.dig('nbr_tests'),
73
- nbr_assertions: data.dig('nbr_assertions'),
74
- seed: data.dig('seed')
75
+ total_time: data['total_time'],
76
+ nbr_tests: data['nbr_tests'],
77
+ nbr_assertions: data['nbr_assertions'],
78
+ seed: data['seed']
75
79
  }.compact,
76
80
  results: results
77
81
  }
@@ -88,9 +92,7 @@ class BlinkaClient
88
92
  )
89
93
  case response.code
90
94
  when 200
91
- puts "Reported #{data.dig('nbr_tests')} tests of commit #{
92
- @config.commit
93
- }!"
95
+ puts "Reported #{data['nbr_tests']} tests of commit #{data['commit']}!"
94
96
  else
95
97
  raise(BlinkaError, "Could not report, got response code #{response.code}")
96
98
  end
@@ -100,6 +102,13 @@ class BlinkaClient
100
102
  Failed to create report because of #{error.class} with message:
101
103
  #{error.message}
102
104
  EOS
105
+ ensure
106
+ WebMock.enable! if defined?(WebMock) && WebMock.respond_to?(:enable!)
107
+ end
108
+
109
+ def self.report(filepath: './blinka_results.json')
110
+ client = BlinkaClient.new
111
+ client.report(filepath: filepath)
103
112
  end
104
113
 
105
114
  def self.upload_image(filepath:)
@@ -107,7 +116,9 @@ class BlinkaClient
107
116
 
108
117
  file = File.open(filepath)
109
118
  filename = File.basename(filepath)
110
- content_type = MimeMagic.by_magic(file).type
119
+ extension = File.extname(filepath).delete('.').to_sym
120
+ content_type = SUPPORTED_MIME_TYPES[extension]
121
+ return if content_type.nil?
111
122
 
112
123
  presigned_post =
113
124
  BlinkaClient.presign_image(filename: filename, content_type: content_type)
@@ -1,5 +1,4 @@
1
1
  class BlinkaMinitest
2
- attr_reader(:test_result)
3
2
  def initialize(test_result)
4
3
  @test_result = test_result
5
4
  end
@@ -8,14 +7,19 @@ class BlinkaMinitest
8
7
  @path ||= source_location.first.gsub(Dir.getwd, '').delete_prefix('/')
9
8
  end
10
9
 
10
+ def line
11
+ @line ||= source_location.last
12
+ end
13
+
11
14
  # Handle broken API in Minitest between 5.10 and 5.11
12
15
  # https://github.com/minitest-reporters/minitest-reporters/blob/e9092460b5a5cf5ca9eb375428217cbb2a7f6dbb/lib/minitest/reporters/default_reporter.rb#L159
13
16
  def source_location
14
- if test_result.respond_to?(:klass)
15
- test_result.source_location
16
- else
17
- test_result.method(test_result.name).source_location
18
- end
17
+ @source_location ||=
18
+ if @test_result.respond_to?(:klass)
19
+ @test_result.source_location
20
+ else
21
+ @test_result.method(@test_result.name).source_location
22
+ end
19
23
  end
20
24
 
21
25
  def kind
@@ -24,47 +28,34 @@ class BlinkaMinitest
24
28
  end
25
29
 
26
30
  def message
27
- failure = test_result.failure
31
+ failure = @test_result.failure
28
32
  return unless failure
29
33
  "#{failure.error.class}: #{failure.error.message}"
30
34
  end
31
35
 
32
36
  def backtrace
33
- return unless test_result.failure
34
- Minitest.filter_backtrace(test_result.failure.backtrace)
37
+ return unless @test_result.failure
38
+ Minitest.filter_backtrace(@test_result.failure.backtrace)
35
39
  end
36
40
 
37
41
  def result
38
- if test_result.error?
42
+ if @test_result.error?
39
43
  :error
40
- elsif test_result.skipped?
44
+ elsif @test_result.skipped?
41
45
  :skip
42
- elsif test_result.failure
46
+ elsif @test_result.failure
43
47
  :failed
44
48
  else
45
49
  :pass
46
50
  end
47
51
  end
48
52
 
49
- def line
50
- current_backtrace = backtrace
51
- return if current_backtrace.nil?
52
-
53
- row =
54
- current_backtrace
55
- .map { |row| row.split(':')[0..1] }
56
- .detect { |row| row[0] == path }
57
-
58
- return if row.nil?
59
- row[1].to_i
60
- end
61
-
62
53
  def time
63
- test_result.time
54
+ @test_result.time
64
55
  end
65
56
 
66
57
  def name
67
- test_result.name
58
+ @test_result.name
68
59
  end
69
60
 
70
61
  def image
@@ -0,0 +1,3 @@
1
+ module BlinkaReporter
2
+ VERSION = '0.3.6'.freeze
3
+ end
@@ -26,13 +26,13 @@ module Minitest
26
26
  end
27
27
 
28
28
  def report
29
+ super
30
+
29
31
  tap_report if ENV['BLINKA_TAP']
30
32
  json_report if ENV['BLINKA_JSON'] || ENV['BLINKA_REPORT']
31
33
  BlinkaClient.new.report if ENV['BLINKA_REPORT']
32
34
  rescue BlinkaClient::BlinkaError => error
33
35
  puts(error)
34
- ensure
35
- super
36
36
  end
37
37
 
38
38
  private
@@ -42,6 +42,8 @@ module Minitest
42
42
  total_time: total_time,
43
43
  nbr_tests: count,
44
44
  nbr_assertions: assertions,
45
+ commit: find_commit,
46
+ tag: ENV.fetch('BLINKA_TAG', ''),
45
47
  seed: options[:seed],
46
48
  results:
47
49
  tests.map { |test_result| BlinkaMinitest.new(test_result).report }
@@ -83,6 +85,16 @@ module Minitest
83
85
  def print_padded_comment(line)
84
86
  puts "##{' ' * TAP_COMMENT_PAD + line}"
85
87
  end
88
+
89
+ def find_commit
90
+ ENV.fetch(
91
+ 'BLINKA_COMMIT',
92
+ ENV.fetch(
93
+ 'HEROKU_TEST_RUN_COMMIT_VERSION',
94
+ `git rev-parse HEAD`.chomp
95
+ )
96
+ )
97
+ end
86
98
  end
87
99
  end
88
100
  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.3.1
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wessman
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-12 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.18.1
27
- - !ruby/object:Gem::Dependency
28
- name: mimemagic
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: 0.3.5
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: 0.3.5
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: dotenv
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,20 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.11'
97
97
  description: Use to format test results from Minitest to use with Blinka.
98
98
  email: david@wessman.co
99
99
  executables: []
@@ -102,12 +102,18 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - lib/blinka_client.rb
104
104
  - lib/blinka_minitest.rb
105
+ - lib/blinka_reporter/version.rb
105
106
  - lib/minitest/blinka_plugin.rb
106
107
  homepage: https://github.com/davidwessman/blinka_reporter
107
108
  licenses:
108
109
  - MIT
109
- metadata: {}
110
- post_install_message:
110
+ metadata:
111
+ homepage_uri: https://github.com/davidwessman/blinka_reporter
112
+ bug_tracker_uri: https://github.com/davidwessman/blinka_reporter/issues
113
+ documentation_uri: https://github.com/davidwessman/blinka_reporter
114
+ changelog_uri: https://github.com/davidwessman/blinka_reporter/main/CHANGELOG.md
115
+ source_code_uri: https://github.com/davidwessman/blinka_reporter
116
+ post_install_message:
111
117
  rdoc_options: []
112
118
  require_paths:
113
119
  - lib
@@ -123,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
129
  version: '0'
124
130
  requirements: []
125
131
  rubygems_version: 3.2.7
126
- signing_key:
132
+ signing_key:
127
133
  specification_version: 4
128
134
  summary: Format tests for Blinka
129
135
  test_files: []