Skip to content

Commit

Permalink
"(CAT-1618) - Add code coverage to ci"
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jan 15, 2024
1 parent 4f00eb8 commit 40ce781
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- "main"
workflow_dispatch:

env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:

spec:
Expand All @@ -25,7 +28,7 @@ jobs:
with:
ruby_version: ${{ matrix.ruby_version }}
runs_on: ${{ matrix.runs_on }}
rake_task: 'gem_revendor test_languageserver test_languageserver_sidecar test_debugserver'
rake_task: 'gem_revendor test:coverage'

acceptance:
strategy:
Expand Down
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ group :development do
gem 'puppetfile-resolver', '~> 0.6.2', :require => false
gem 'yard', '~> 0.9.28', :require => false
gem 'ffi', '= 1.15.5', :require => false
gem "rubocop", '~> 1.48.1', require: false
gem "rubocop-performance", '~> 1.16', require: false
gem "rubocop-rspec", '~> 2.19', require: false
gem "rubocop", '~> 1.48.1', :require => false
gem "rubocop-performance", '~> 1.16', :require => false
gem "rubocop-rspec", '~> 2.19', :require => false
gem 'simplecov', :require => false
gem 'simplecov-console', :require => false
gem 'codecov', :require => false

if ENV['PUPPET_GEM_VERSION']
gem 'puppet', ENV['PUPPET_GEM_VERSION'], :require => false
Expand Down
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ require 'rspec/core/rake_task'
rubocop_available = Gem::Specification::find_all_by_name('rubocop').any?
require 'rubocop/rake_task' if rubocop_available

require 'rake'

namespace :test do
desc 'Run tests with code coverage'
RakeTask.new(:coverage) do
ENV['COVERAGE'] = 'yes'
Rake::Task['test_languageserver'].execute
Rake::Task['test_languageserver_sidecar'].execute
Rake::Task['test_debugserver'].execute
Rake::Task['acceptance_languageserver'].execute
end
end

desc 'Run rspec tests for the Language Server with coloring.'
RSpec::Core::RakeTask.new(:test_languageserver) do |t|
t.rspec_opts = %w[--color --format documentation --default-path spec/languageserver]
Expand Down
2 changes: 1 addition & 1 deletion spec/debugserver/spec_debug_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../spec_helper.rb'
# Emulate the setup from the root 'puppet-debugserver' file

# Add the debug server into the load path
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))

Expand Down
1 change: 1 addition & 0 deletions spec/languageserver-sidecar/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative '../spec_helper.rb
# Emulate the setup from the root 'puppet-languageserver' file
root = File.join(File.dirname(__FILE__),'..','..')
Expand Down
2 changes: 1 addition & 1 deletion spec/languageserver/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require_relative '../spec_helper.rb'
# Emulate the setup from the root 'puppet-languageserver' file

root = File.join(File.dirname(__FILE__),'..','..')
# Add the language server into the load path
$LOAD_PATH.unshift(File.join(root,'lib'))
Expand Down
29 changes: 29 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
if ENV['SIMPLECOV'] == 'yes'
begin
require 'simplecov'
require 'simplecov-console'

SimpleCov.formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,,
]

if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatters << SimpleCov::Formatter::Codecov
end

SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter '/spec'
add_filter '/tools'
add_filter '/docs'

# do not track vendored files
add_filter '/vendor'
add_filter '/.vendor'
end
rescue LoadError
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
end
end

0 comments on commit 40ce781

Please sign in to comment.