blinka-reporter 0.6.1 → 0.7.0

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: 9c1fc7642c8c305df691452e7c08bf3d0f5cd3f93942fe05123727e7190ce43c
4
- data.tar.gz: 5695c3b9e7e5db14f9584515a06b1abbbe36f40900f90226e8f8cf8bfdc6922a
3
+ metadata.gz: 169cf0a2be6fe787a73ecb591ff4e271ead078adc25cfc762317d4de32871a00
4
+ data.tar.gz: e54f8c1b7c9521c42ff07c24ddef03489ebdfce0619b5006d0aa26d1eac7f3fc
5
5
  SHA512:
6
- metadata.gz: 6e3b2bfaf92e19ac3630f3bd89f84f5f53ad065b3c41e47fa8a1f0f80f2300b68ce6eec6368ebd50b9bfa5208ddf75c3c206e5875bbc440bca6ad403c24fe79e
7
- data.tar.gz: 2449352484f17be048e5b84c37a715e2130402832481a61534a344ccba7cedb42074d653570f513d33cfbe13907ab5846946b3fe52519804e4893e6de75009a9
6
+ metadata.gz: cd66de441531a066ed462e241670b0ea2904be084db2dd66819376e78f93d37bb5233709d634048727c8df9fd33e88a0820609c0e38df23f7052c052957cba2b
7
+ data.tar.gz: 28ee703aeb5a4bdf3ddfea38d443ad9db0692b370cbad8d744c9bb85e6669107723454f15cac24f6bc483b90315a55828776c103724a76aadc6f1458ab305557
@@ -8,6 +8,7 @@ jobs:
8
8
  name: Tests
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
+ fail-fast: false
11
12
  matrix:
12
13
  ruby: ["2.6", "2.7", "3.0", "3.1"]
13
14
 
@@ -29,7 +30,7 @@ jobs:
29
30
 
30
31
  - name: Run tests
31
32
  env:
32
- BLINKA_JSON: true
33
+ BLINKA_PATH: ./results.json
33
34
  run: bundle exec rake test
34
35
 
35
36
  - name: Build and install gem
@@ -38,9 +39,12 @@ jobs:
38
39
 
39
40
  - name: Report to Blinka
40
41
  if: always()
41
- env:
42
- BLINKA_REPOSITORY: davidwessman/blinka_reporter
43
- BLINKA_TEAM_ID: ${{ secrets.BLINKA_TEAM_ID }}
44
- BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
45
- BLINKA_TAG: ${{ matrix.ruby }}
46
- run: blinka_reporter --blinka --tap --path ./blinka_results.json
42
+ run: |
43
+ blinka_reporter \
44
+ --blinka \
45
+ --tap \
46
+ --path ./results.json \
47
+ --repository davidwessman/blinka_reporter \
48
+ --tag ${{ matrix.ruby }} \
49
+ --team-id ${{ secrets.BLINKA_TEAM_ID }} \
50
+ --team-secret ${{ secrets.BLINKA_TEAM_SECRET }}
data/.gitignore CHANGED
@@ -26,3 +26,4 @@ yarn-error.log*
26
26
  .yarn-integrity
27
27
 
28
28
  /blinka_results.json
29
+ /results.json
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0] - 2022-03-06
11
+
12
+ - Support multiple `--path` calls to combine results from multiple files.
13
+ - Replaces `BLINKA_JSON` and `BLINKA_APPEND` with `BLINKA_PATH`.
14
+ - Adds all reporter options as CLI-options instead of using environment variables. -`BLINKA_REPOSITORY` => `--repository`
15
+
10
16
  ## [0.6.1] - 2022-02-27
11
17
 
12
18
  - Rspec
@@ -137,7 +143,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
137
143
 
138
144
  - Handle inconsistency in source_location of test result in Minitest for different versions.
139
145
 
140
- [unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.1...HEAD
146
+ [unreleased]: https://github.com/davidwessman/blinka_reporter/compare/v0.7.0...HEAD
147
+ [0.7.0]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.1...v0.7.0
141
148
  [0.6.1]: https://github.com/davidwessman/blinka_reporter/compare/v0.6.0...v0.6.1
142
149
  [0.6.0]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.2...v0.6.0
143
150
  [0.5.2]: https://github.com/davidwessman/blinka_reporter/compare/v0.5.1...v0.5.2
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem install blinka-reporter
16
16
  or add to your Gemfile
17
17
 
18
18
  ```ruby
19
- gem 'blinka-repoter', '~> 0.5.0'
19
+ gem 'blinka-reporter', '~> 0.7.0'
20
20
  ```
21
21
 
22
22
  ## Which ruby testing frameworks are supported?
@@ -35,10 +35,10 @@ Blinka is a web service developed by [@davidwessman](https://github.com/davidwes
35
35
  ### Minitest
36
36
 
37
37
  ```sh
38
- BLINKA_JSON=true bundle exec rails test
38
+ BLINKA_PATH=./tests.json bundle exec rails test
39
39
  ```
40
40
 
41
- Output as `./blinka_results.json`
41
+ Output as `./tests.json`.
42
42
 
43
43
  ### Rspec
44
44
 
@@ -51,8 +51,7 @@ bundle exec rspec --formatter RspecJunitFormatter --out ./rspec.xml
51
51
  ## How to send report to Blinka?
52
52
 
53
53
  1. Output your test results as described [above](#how-to-generate-test-report-in-the-right-format).
54
- 1. Configure `BLINKA_TEAM_ID`, `BLINKA_TEAM_SECRET`, `BLINKA_REPOSITORY`.
55
- 1. `bundle exec blinka_reporter --path {./blinka_results.json,./rspec.xml} --blinka`
54
+ 1. `bundle exec blinka_reporter --path {./blinka_results.json,./rspec.xml} --blinka --team-id <BLINKA_TEAM_ID> --team-secret <BLINKA_TEAM_SECRET> --repository davidwessman/blinka_reporter`
56
55
 
57
56
  ## How can I send report in Github Action?
58
57
 
@@ -65,58 +64,59 @@ Add a step to your Github Action Workflow after running tests:
65
64
  run: bundle exec rake test
66
65
 
67
66
  - name: Report minitest to Blinka
68
- env:
69
- BLINKA_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
70
- BLINKA_REPOSITORY: davidwessman/blinka_reporter
71
- BLINKA_TAG: ""
72
- BLINKA_TEAM_ID: ${{ secrets.BLINKA_TEAM_ID }}
73
- BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
74
- run: bundle exec blinka_reporter --path ./blinka_results.json --blinka
67
+ run: |
68
+ bundle exec blinka_reporter \
69
+ --path ./blinka_results.json \
70
+ --blinka \
71
+ --commit ${{ github.event.pull_request.head.sha || github.sha }} \
72
+ --repository davidwessman/blinka_reporter \
73
+ --team-id ${{ secrets.BLINKA_TEAM_ID }} \
74
+ --team-secret ${{ secrets.BLINKA_TEAM_SECRET }}
75
75
  ```
76
76
 
77
77
  ```yaml
78
78
  - name: Rspec
79
79
  run: bundle exec rspec --formatter RspecJunitFormatter --out ./rspec.xml
80
80
  - name: Report minitest to Blinka
81
- env:
82
- BLINKA_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
83
- BLINKA_REPOSITORY: davidwessman/blinka_reporter
84
- BLINKA_TAG: ""
85
- BLINKA_TEAM_ID: ${{ secrets.BLINKA_TEAM_ID }}
86
- BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
87
- run: bundle exec blinka_reporter --path ./rspec.xml --blinka
81
+ run: |
82
+ bundle exec blinka_reporter \
83
+ --path ./rspec.xml \
84
+ --blinka \
85
+ --commit ${{ github.event.pull_request.head.sha || github.sha }} \
86
+ --repository davidwessman/blinka_reporter \
87
+ --team-id ${{ secrets.BLINKA_TEAM_ID }} \
88
+ --team-secret ${{ secrets.BLINKA_TEAM_SECRET }}
88
89
  ```
89
90
 
90
- `BLINKA_TAG` is optional and can be used to separate different reports, for example when using a build matrix.
91
+ `--tag` is optional and can be used to separate different reports, for example when using a build matrix.
91
92
 
92
93
  ## How to make multiple test runs into one report?
93
94
 
94
- **Only supported for Minitest, open an issue for Rspec-support**
95
-
96
95
  For example when running tests in parallel you might need to run system tests separately.
97
- By first using `BLINKA_JSON` it will create a clean file, `BLINKA_APPEND` will append the results.
96
+ Output the test results to different paths with `BLINKA_PATH`.
98
97
 
99
98
  ```yaml
100
99
  - name: System tests
101
100
  env:
102
- BLINKA_JSON: true
101
+ BLINKA_PATH: ./system_tests.json
103
102
  PARALLEL_WORKERS: 1
104
103
  run: bundle exec rails test:system
105
104
 
106
105
  - name: Tests
107
106
  env:
108
- BLINKA_JSON: true
109
- BLINKA_APPEND: true
107
+ BLINKA_JSON: ./tests.json
110
108
  run: bundle exec rails test
111
109
 
112
110
  - name: Report to Blinka
113
- env:
114
- BLINKA_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }}
115
- BLINKA_REPOSITORY: davidwessman/blinka_reporter
116
- BLINKA_TAG: ""
117
- BLINKA_TEAM_ID: ${{ secrets.BLINKA_TEAM_ID }}
118
- BLINKA_TEAM_SECRET: ${{ secrets.BLINKA_TEAM_SECRET }}
119
- run: bundle exec blinka_reporter --path ./blinka_results.json --blinka
111
+ run: |
112
+ bundle exec blinka_reporter \
113
+ --path ./system_tests.json \
114
+ --path ./tests.json \
115
+ --blinka \
116
+ --commit ${{ github.event.pull_request.head.sha || github.sha }} \
117
+ --repository davidwessman/blinka_reporter \
118
+ --team-id ${{ secrets.BLINKA_TEAM_ID }} \
119
+ --team-secret ${{ secrets.BLINKA_TEAM_SECRET }}
120
120
  ```
121
121
 
122
122
  ## How can I report tests in TAP-format?
@@ -99,7 +99,10 @@ module BlinkaReporter
99
99
  when 200
100
100
  @jwt_token = JSON.parse(response.body).dig('auth_token')
101
101
  else
102
- raise(BlinkaReporter::Error, 'Could not authenticate to API')
102
+ raise(
103
+ BlinkaReporter::Error,
104
+ "Could not authenticate to API #{response.code}"
105
+ )
103
106
  end
104
107
  end
105
108
 
@@ -9,28 +9,58 @@ module BlinkaReporter
9
9
  blinka_reporter version #{BlinkaReporter::VERSION}
10
10
 
11
11
  Options:
12
- --tap: Flag for outputting test results in TAP-protocol, helpful on Heroku CI.
13
- --blinka: Flag for reporting test results to blinka.app, requires setting environment:
14
- - BLINKA_TEAM_ID
15
- - BLINKA_TEAM_SECRET
16
- - BLINKA_REPOSITORY
17
- --path <path>: Path to test results file, works for
18
- - ./blinka_results.json blinka json format [default]
19
- - ./rspec.xml from https://github.com/sj26/rspec_junit_formatter
12
+ --path <path>: Path to test results file, can be supplied multiple times to combine results
13
+ - ./blinka_results.json blinka json format
14
+ - ./rspec.xml from https://github.com/sj26/rspec_junit_formatter
15
+
16
+ --tap: Flag for outputting test results in TAP-protocol, helpful on Heroku CI
17
+ --blinka: Flag for reporting test results to blinka.app, requires also supplying:
18
+ - --team-id
19
+ - --team-secret
20
+ - --repository
21
+ - --commit
22
+ --team-id <team-id>: Blinka team id, only used with --blinka
23
+ --team-secret <team-secret>: Blinka team secret, only used with --blinka
24
+ --commit <commit>: The commit hash to report
25
+ --tag <tag>: The tag for the run, for example to separate a test matrix
26
+ --repository <repository>: The Github repository
27
+ --host <host>: Override Blink host to send report
28
+
20
29
  EOS
21
30
  return 0
22
31
  end
23
32
 
24
33
  tap = (argv.index('--tap') || -1) >= 0
34
+
35
+ paths = argv_value_for(argv, '--path')
36
+
25
37
  blinka = (argv.index('--blinka') || -1) >= 0
26
- path = argv_value_for(argv, '--path') || './blinka_results.json'
27
- BlinkaReporter::Client.report(blinka: blinka, tap: tap, path: path)
28
- 0
38
+ commit = argv_value_for(argv, '--commit')&.first
39
+ repository = argv_value_for(argv, '--repository')&.first
40
+ tag = argv_value_for(argv, '--tag')&.first
41
+ team_id = argv_value_for(argv, '--team-id')&.first
42
+ team_secret = argv_value_for(argv, '--team-secret')&.first
43
+ host = argv_value_for(argv, '--host')&.first
44
+
45
+ client = BlinkaReporter::Client.new
46
+ data = client.parse(paths: paths)
47
+ config =
48
+ BlinkaReporter::Config.new(
49
+ tag: tag,
50
+ commit: commit,
51
+ team_id: team_id,
52
+ team_secret: team_secret,
53
+ repository: repository,
54
+ host: host
55
+ )
56
+ client.report(data: data, config: config, tap: tap, blinka: blinka)
29
57
  end
30
58
 
31
59
  def self.argv_value_for(argv, option_name)
32
- return unless (index = argv.index(option_name))
33
- argv[index + 1]
60
+ argv
61
+ .each_index
62
+ .select { |index| argv[index] == option_name }
63
+ .map { |index| argv[index + 1] }
34
64
  end
35
65
  end
36
66
  end
@@ -8,44 +8,58 @@ require 'blinka_reporter/tap'
8
8
 
9
9
  module BlinkaReporter
10
10
  class Client
11
- def initialize
12
- @config = BlinkaReporter::Config.new
13
- end
14
-
15
- def report(path: './blinka_results.json', blinka: false, tap: false)
16
- unless File.exist?(path)
17
- raise(
18
- BlinkaReporter::Error,
19
- "Could not find #{path}, was it generated when running the tests?"
20
- )
21
- end
22
-
23
- data =
24
- if path.end_with?('.xml')
25
- self.class.parse_xml(path: path)
26
- elsif path.end_with?('.json')
27
- self.class.parse_json(path: path)
28
- else
11
+ def parse(paths: nil)
12
+ paths ||= ['./blinka_results.json']
13
+ paths = Array(paths)
14
+ paths.each do |path|
15
+ unless File.exist?(path)
29
16
  raise(
30
17
  BlinkaReporter::Error,
31
- "Unknown format of #{path}, needs to be .json or .xml"
18
+ "Could not find #{path}, make sure the path is correct."
32
19
  )
33
20
  end
21
+ end
22
+
23
+ merge_results(
24
+ paths.map do |path|
25
+ if path.end_with?('.xml')
26
+ parse_xml(path: path)
27
+ elsif path.end_with?('.json')
28
+ parse_json(path: path)
29
+ else
30
+ raise(
31
+ BlinkaReporter::Error,
32
+ "Unknown format of #{path}, needs to be .json or .xml"
33
+ )
34
+ end
35
+ end
36
+ )
37
+ end
34
38
 
39
+ def report(data:, blinka: false, tap: false, config: nil)
35
40
  BlinkaReporter::Tap.report(data) if tap
36
- BlinkaReporter::Blinka.report(config: @config, data: data) if blinka
41
+ BlinkaReporter::Blinka.report(config: config, data: data) if blinka
37
42
  0
38
43
  end
39
44
 
40
- def self.report(path:, tap: false, blinka: false)
41
- Client.new.report(path: path, tap: tap, blinka: blinka)
45
+ private
46
+
47
+ def merge_results(data_array)
48
+ data = { total_time: 0, nbr_tests: 0, nbr_assertions: 0, results: [] }
49
+ data_array.each do |result|
50
+ data[:total_time] += result[:total_time] || 0
51
+ data[:nbr_tests] += result[:nbr_tests] || 0
52
+ data[:nbr_assertions] += result[:nbr_assertions] || 0
53
+ data[:results] += result[:results] || []
54
+ end
55
+ data
42
56
  end
43
57
 
44
- def self.parse_json(path:)
58
+ def parse_json(path:)
45
59
  JSON.parse(File.open(path).read, symbolize_names: true)
46
60
  end
47
61
 
48
- def self.parse_xml(path:)
62
+ def parse_xml(path:)
49
63
  data = Ox.load_file(path, { symbolize_keys: true, skip: :skip_none })
50
64
  test_suite = data.root
51
65
  unless test_suite.name == 'testsuite'
@@ -62,7 +76,7 @@ module BlinkaReporter
62
76
  }
63
77
  end
64
78
 
65
- def self.xml_seed(ox_properties)
79
+ def xml_seed(ox_properties)
66
80
  ox_properties.each do |property|
67
81
  property.nodes.each do |node|
68
82
  return node.attributes[:value] if node.attributes[:name] == 'seed'
@@ -72,7 +86,7 @@ module BlinkaReporter
72
86
  end
73
87
 
74
88
  # Kind is extracted from the second part of spec.models.customer_spec
75
- def self.xml_test_cases(test_cases)
89
+ def xml_test_cases(test_cases)
76
90
  test_cases.map do |test_case|
77
91
  result = {
78
92
  kind: Array(test_case.attributes[:classname]&.split('.'))[1],
@@ -100,7 +114,7 @@ module BlinkaReporter
100
114
  end
101
115
  end
102
116
 
103
- def self.get_image_path(backtrace)
117
+ def get_image_path(backtrace)
104
118
  backtrace.each do |text|
105
119
  path = /^(\[Screenshot\]|\[Screenshot Image\]):\s([\S]*)$/.match(text)
106
120
  next if path.nil?
@@ -3,32 +3,35 @@ require 'blinka_reporter/error'
3
3
  module BlinkaReporter
4
4
  class Config
5
5
  attr_reader(:commit, :host, :repository, :tag, :team_id, :team_secret)
6
+ DEFAULT_HOST = 'https://www.blinka.app'
6
7
 
7
- def initialize
8
- @commit = find_commit
9
- @host = ENV.fetch('BLINKA_HOST', 'https://www.blinka.app')
10
- @repository = ENV.fetch('BLINKA_REPOSITORY', nil)
11
- @tag = ENV.fetch('BLINKA_TAG', nil)
12
- @team_id = ENV.fetch('BLINKA_TEAM_ID', nil)
13
- @team_secret = ENV.fetch('BLINKA_TEAM_SECRET', nil)
8
+ def initialize(
9
+ tag:,
10
+ commit:,
11
+ repository:,
12
+ host: nil,
13
+ team_id:,
14
+ team_secret:
15
+ )
16
+ @commit = commit || find_commit
17
+ @host = host || DEFAULT_HOST
18
+ @repository = repository
19
+ @tag = tag
20
+ @team_id = team_id
21
+ @team_secret = team_secret
14
22
  end
15
23
 
16
24
  def validate_blinka
17
- if @team_id.nil? || @team_secret.nil? || @repository.nil?
25
+ required = [@team_id, @team_secret, @repository]
26
+ if required.include?(nil) || required.include?('')
18
27
  raise(BlinkaReporter::Error, <<~EOS)
19
- Missing configuration, make sure to set required environment variables:
20
- - BLINKA_TEAM_ID
21
- - BLINKA_TEAM_SECRET
22
- - BLINKA_REPOSITORY
23
- EOS
28
+ Missing configuration, make sure to set --team-id, --team-secret, --repository
29
+ EOS
24
30
  end
25
31
  end
26
32
 
27
33
  def find_commit
28
- ENV.fetch(
29
- 'BLINKA_COMMIT',
30
- ENV.fetch('HEROKU_TEST_RUN_COMMIT_VERSION', `git rev-parse HEAD`.chomp)
31
- )
34
+ ENV.fetch('HEROKU_TEST_RUN_COMMIT_VERSION', `git rev-parse HEAD`.chomp)
32
35
  end
33
36
  end
34
37
  end
@@ -1,3 +1,3 @@
1
1
  module BlinkaReporter
2
- VERSION = '0.6.1'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -11,31 +11,29 @@ module Minitest
11
11
  def plugin_blinka_options(opts, options); end
12
12
 
13
13
  module BlinkaPlugin
14
- REPORT_PATH = 'blinka_results.json'.freeze
15
14
  class Reporter < Minitest::StatisticsReporter
16
15
  attr_accessor :tests
17
16
 
18
- def initialize(io = $stdout, options = {})
19
- super
20
- self.tests = []
21
- end
22
-
23
17
  def record(test)
24
18
  super
19
+ self.tests ||= []
25
20
  tests << test
26
21
  end
27
22
 
28
23
  def report
29
24
  super
30
25
 
31
- json_report(append: !ENV['BLINKA_APPEND'].nil?) if ENV['BLINKA_JSON']
32
- rescue BlinkaReporter::Client::BlinkaReporter::Error => error
26
+ json_report
27
+ rescue BlinkaReporter::Error => error
33
28
  puts(error)
34
29
  end
35
30
 
36
31
  private
37
32
 
38
- def json_report(append:)
33
+ def json_report
34
+ report_path = ENV['BLINKA_PATH']
35
+ return if report_path.nil? || report_path.eql?('')
36
+
39
37
  result = {
40
38
  total_time: total_time,
41
39
  nbr_tests: count,
@@ -46,34 +44,13 @@ module Minitest
46
44
  BlinkaReporter::MinitestAdapter.new(test_result).report
47
45
  end
48
46
  }
49
- result = append_previous(result) if append
50
47
 
51
- File.open(REPORT_PATH, 'w+') do |file|
48
+ File.open(report_path, 'w+') do |file|
52
49
  file.write(JSON.pretty_generate(result))
53
50
  end
54
51
 
55
52
  puts
56
- puts("Test results written to `#{REPORT_PATH}`")
57
- end
58
-
59
- private
60
-
61
- def parse_report
62
- return unless File.exist?(REPORT_PATH)
63
- JSON.parse(File.read(REPORT_PATH), symbolize_names: true)
64
- end
65
-
66
- def append_previous(result)
67
- previous = parse_report
68
- return if previous.nil?
69
- return if result[:commit] != previous[:commit]
70
- return if result[:tag] != previous[:tag]
71
-
72
- result[:total_time] += previous[:total_time] || 0
73
- result[:nbr_tests] += previous[:nbr_tests] || 0
74
- result[:nbr_assertions] += previous[:nbr_assertions] || 0
75
- result[:results] += previous[:results] || []
76
- result
53
+ puts("Test results written to `#{report_path}`")
77
54
  end
78
55
  end
79
56
  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.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Wessman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-27 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty