diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41145d88..eb3d389a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: - "main" workflow_dispatch: +env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + jobs: spec: @@ -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: diff --git a/Gemfile b/Gemfile index e1010811..07bad7d8 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index d1492d11..f24e5e11 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,16 @@ require 'rspec/core/rake_task' rubocop_available = Gem::Specification::find_all_by_name('rubocop').any? require 'rubocop/rake_task' if rubocop_available +namespace :test do + desc 'Run tests with code coverage' + task :coverage do + ENV['COVERAGE'] = 'yes' + Rake::Task['test_languageserver'].execute + Rake::Task['test_languageserver_sidecar'].execute + Rake::Task['test_debugserver'].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] diff --git a/spec/debugserver/spec_debug_helper.rb b/spec/debugserver/spec_debug_helper.rb index 5232c703..acd2a4ef 100644 --- a/spec/debugserver/spec_debug_helper.rb +++ b/spec/debugserver/spec_debug_helper.rb @@ -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')) diff --git a/spec/languageserver-sidecar/spec_helper.rb b/spec/languageserver-sidecar/spec_helper.rb index 7728c372..6616596f 100644 --- a/spec/languageserver-sidecar/spec_helper.rb +++ b/spec/languageserver-sidecar/spec_helper.rb @@ -1,3 +1,5 @@ +require_relative '../spec_helper.rb' + # Emulate the setup from the root 'puppet-languageserver' file root = File.join(File.dirname(__FILE__),'..','..') diff --git a/spec/languageserver/spec_helper.rb b/spec/languageserver/spec_helper.rb index a52fdf9e..4ceb66b0 100644 --- a/spec/languageserver/spec_helper.rb +++ b/spec/languageserver/spec_helper.rb @@ -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')) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..913772aa --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,29 @@ +if ENV['COVERAGE'] == '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