testmetrics_minitest 1.0.0
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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/LICENSE +24 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/circle.yml +24 -0
- data/lib/minitest/testmetrics.rb +2 -0
- data/lib/minitest/testmetrics_plugin.rb +148 -0
- data/lib/testmetrics_minitest.rb +2 -0
- data/testmetrics_minitest.gemspec +27 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed676fac58e14542581140eb0f7b6dbfc11df4a3652de9292296e907798a1731
|
4
|
+
data.tar.gz: b4b22d08333b7d8227957d3e1b09c621c0ed9cf101fe79617538ba07e864397c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fdb0d03f98045223a119b1c71ce9c3e65991f65d7765f7dff70338e0635d9225bb36dd0b118757c419ad8f3edfe38d7fb36ab0d5ae58e783d9d7ea798c37d42
|
7
|
+
data.tar.gz: c291a41b052ef3fa11376f7e6ae3e33d56ab28fd0221f7679233d0f951473b1802392cf8dd83107b482e87a3fb29162ea5cd4cf2b9cc312959c74d6f9d1b8140
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
== LICENSE:
|
2
|
+
|
3
|
+
(The MIT License)
|
4
|
+
|
5
|
+
Copyright (c) 2019 devonestes
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
a copy of this software and associated documentation files (the
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
the following conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Testmetrics MiniTest [](https://circleci.com/gh/Testmetrics/testmetrics_minitest)
|
2
|
+
|
3
|
+
The official MiniTest client for [Testmetrics](https://www.testmetrics.app). This client collects data
|
4
|
+
about your MiniTest test suites after being run in CI and sends that data to
|
5
|
+
Testmetrics so you can gain valuable insights about your test suite.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Add it to your Gemfile in the same groups as MiniTest.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
group :test do
|
13
|
+
gem "minitest"
|
14
|
+
gem "testmetrics_minitest"
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
Then, when you're running your tests in CI, you can pass the `--testmetrics`
|
19
|
+
option to turn on the reporter:
|
20
|
+
|
21
|
+
```
|
22
|
+
bundle exec rake test --testmetrics
|
23
|
+
```
|
24
|
+
|
25
|
+
You can also turn on the reporter by requiring `'minitest/testmetrics'` in
|
26
|
+
your test files.
|
27
|
+
|
28
|
+
In order for the metrics to be sent to Testmetrics, you must have your
|
29
|
+
Testmetrics Project Key set in the `TESTMETRICS_PROJECT_KEY` environment
|
30
|
+
variable in your CI environment. If this environment variable isn't set, the
|
31
|
+
collected metrics for your CI run will be discarded.
|
32
|
+
|
33
|
+
This key should be kept private and not exposed to the public.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
`testmetrics_minitest` is offered under the MIT license. For the full license
|
38
|
+
text see [LICENSE](https://github.com/testmetrics/testmetrics_minitest/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
parallelism: 1
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.4.2-jessie-node
|
7
|
+
environment:
|
8
|
+
BUNDLE_JOBS: 3
|
9
|
+
BUNDLE_RETRY: 3
|
10
|
+
BUNDLE_PATH: vendor/bundle
|
11
|
+
PGHOST: 127.0.0.1
|
12
|
+
PGUSER: circleci-demo-ruby
|
13
|
+
RAILS_ENV: test
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
- run:
|
17
|
+
name: Which bundler?
|
18
|
+
command: bundle -v
|
19
|
+
- run:
|
20
|
+
name: Bundle Install
|
21
|
+
command: bundle check || bundle install
|
22
|
+
- run:
|
23
|
+
name: MiniTest run
|
24
|
+
command: bundle exec rake
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Minitest
|
6
|
+
def self.plugin_testmetrics_options(opts, _options)
|
7
|
+
opts.on "--testmetrics", "Enable Minitest::Testmetrics Reporting." do
|
8
|
+
Testmetrics.report!
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.plugin_testmetrics_init(options)
|
13
|
+
if Testmetrics.report?
|
14
|
+
self.reporter << Testmetrics.new(options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Testmetrics < Reporter
|
19
|
+
class << self
|
20
|
+
def report!
|
21
|
+
@enabled = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def report?
|
25
|
+
@enabled ||= false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_accessor :options, :testmetrics_results, :results
|
30
|
+
|
31
|
+
def initialize(options = {})
|
32
|
+
self.options = options
|
33
|
+
self.results = Hash.new { |h, k| h[k] = [] }
|
34
|
+
self.testmetrics_results = {
|
35
|
+
key: ENV['TESTMETRICS_PROJECT_KEY'] || 'Unknown',
|
36
|
+
branch: git_branch,
|
37
|
+
sha: git_sha,
|
38
|
+
metadata: {
|
39
|
+
ruby_version: RUBY_VERSION,
|
40
|
+
ci_platform: ci_platform
|
41
|
+
},
|
42
|
+
tests: []
|
43
|
+
}
|
44
|
+
post_results(testmetrics_results) unless testmetrics_results[:key] == 'Unknown'
|
45
|
+
end
|
46
|
+
|
47
|
+
def start
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def record(result)
|
52
|
+
key = result.respond_to?(:klass) ? result.klass : result.class
|
53
|
+
results[key] << result
|
54
|
+
end
|
55
|
+
|
56
|
+
def report
|
57
|
+
total_time = 0
|
58
|
+
results.each do |name, class_results|
|
59
|
+
class_results.each do |result|
|
60
|
+
total_time += time_in_microseconds(result.time)
|
61
|
+
result.name
|
62
|
+
testmetrics_results[:tests]<< {
|
63
|
+
name: "#{name}.#{result.name.delete("\0").delete("\x01").delete("\e")}",
|
64
|
+
total_run_time: time_in_microseconds(result.time),
|
65
|
+
state: state(result.failure)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
testmetrics_results[:total_run_time] = total_time
|
70
|
+
|
71
|
+
puts "\nSending results to Testmetrics server..."
|
72
|
+
post_results(testmetrics_results) unless testmetrics_results[:key] == 'Unknown'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
BRANCH_VARS = %w[
|
79
|
+
TRAVIS_EVENT_TYPE
|
80
|
+
CIRCLE_BRANCH
|
81
|
+
CI_COMMIT_REF_NAME
|
82
|
+
BRANCH_NAME
|
83
|
+
].freeze
|
84
|
+
def git_branch
|
85
|
+
correct_var = correct_var(BRANCH_VARS)
|
86
|
+
|
87
|
+
if correct_var == 'TRAVIS_EVENT_TYPE'
|
88
|
+
travis_branch(correct_var)
|
89
|
+
else
|
90
|
+
correct_var.nil? ? 'Unknown' : ENV[correct_var]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def travis_branch(var)
|
95
|
+
case ENV[var]
|
96
|
+
when 'push'
|
97
|
+
ENV['TRAVIS_BRANCH']
|
98
|
+
when 'pull_request'
|
99
|
+
ENV['TRAVIS_PULL_REQUEST_BRANCH']
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
SHA_VARS = %w[TRAVIS_COMMIT CIRCLE_SHA1 CI_COMMIT_SHA REVISION].freeze
|
104
|
+
def git_sha
|
105
|
+
correct_var = correct_var(SHA_VARS)
|
106
|
+
correct_var.nil? ? 'Unknown' : ENV[correct_var]
|
107
|
+
end
|
108
|
+
|
109
|
+
def ci_platform
|
110
|
+
case correct_var(SHA_VARS)
|
111
|
+
when 'TRAVIS_COMMIT' then 'Travis CI'
|
112
|
+
when 'CIRCLE_SHA1' then 'Circle CI'
|
113
|
+
when 'CI_COMMIT_SHA' then 'Gitlab CI'
|
114
|
+
when 'REVISION' then 'Semaphore CI'
|
115
|
+
else 'Unknown'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def correct_var(vars)
|
120
|
+
vars.find { |var| !ENV[var].nil? && ENV[var] != '' }
|
121
|
+
end
|
122
|
+
|
123
|
+
def post_results(results)
|
124
|
+
Faraday.post do |req|
|
125
|
+
req.url 'https://www.testmetrics.app/results'
|
126
|
+
req.headers['Content-Type'] = 'application/json'
|
127
|
+
req.body = results.to_json
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def time_in_microseconds(time)
|
132
|
+
(time * 1_000_000).round(0)
|
133
|
+
end
|
134
|
+
|
135
|
+
def state(failure)
|
136
|
+
case failure
|
137
|
+
when Skip
|
138
|
+
:pending
|
139
|
+
when UnexpectedError
|
140
|
+
:failed
|
141
|
+
when Assertion
|
142
|
+
:failed
|
143
|
+
else
|
144
|
+
:passed
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'testmetrics_minitest'
|
6
|
+
spec.version = '1.0.0'
|
7
|
+
spec.authors = ['Devon Estes']
|
8
|
+
spec.email = ['devon.c.estes@gmail.com']
|
9
|
+
|
10
|
+
spec.summary = 'The official Minitest client for Testmetrics'
|
11
|
+
spec.homepage = 'https://testmetrics.app'
|
12
|
+
|
13
|
+
# Specify which files should be added to the gem when it is released.
|
14
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
15
|
+
# into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
25
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
26
|
+
spec.add_runtime_dependency 'faraday', '>= 0.9.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: testmetrics_minitest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Devon Estes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- devon.c.estes@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- circle.yml
|
82
|
+
- lib/minitest/testmetrics.rb
|
83
|
+
- lib/minitest/testmetrics_plugin.rb
|
84
|
+
- lib/testmetrics_minitest.rb
|
85
|
+
- testmetrics_minitest.gemspec
|
86
|
+
homepage: https://testmetrics.app
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.6
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: The official Minitest client for Testmetrics
|
109
|
+
test_files: []
|