Welcome to mirror list, hosted at ThFree Co, Russian Federation.

simplecov_env.rb « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47a2f43e30c20d9d6c43ba8b683ed3bf023b1d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true

require 'simplecov'
require 'simplecov-cobertura'
require 'simplecov-lcov'
require 'gitlab/utils/all'

module SimpleCovEnv
  extend self

  def start!
    return if !ENV.key?('SIMPLECOV') || ENV['SIMPLECOV'] == '0'
    return if SimpleCov.running

    configure_profile
    configure_job
    configure_formatter

    SimpleCov.start
  end

  def configure_formatter
    SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true

    SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
      [
        SimpleCov::Formatter::SimpleFormatter,
        SimpleCov::Formatter::HTMLFormatter,
        SimpleCov::Formatter::CoberturaFormatter,
        SimpleCov::Formatter::LcovFormatter
      ]
    )
  end

  def configure_job
    SimpleCov.configure do
      if ENV['CI_JOB_NAME']
        job_name = Gitlab::Utils.slugify(ENV['CI_JOB_NAME'])
        coverage_dir "coverage/#{job_name}"
        command_name job_name
      end

      if ENV['CI']
        SimpleCov.at_exit do
          # In CI environment don't generate formatted reports
          # Only generate .resultset.json
          SimpleCov.result
        end
      end
    end
  end

  def configure_profile
    SimpleCov.configure do
      load_profile 'test_frameworks'

      add_filter %r{^/(ee/)?(bin|gems|vendor)}
      add_filter %r{^/(ee/)?db/fixtures/development}
      add_filter %r{^/(ee/)?db/migrate/\d{14}_init_schema\.rb\z}

      add_group 'Channels',           %r{^/(ee/)?app/channels}
      add_group 'Components',         %r{^/(ee/)?app/components}
      add_group 'Config',             %r{^/(ee/)?config}
      add_group 'Controllers',        %r{^/(ee/)?app/controllers}
      add_group 'Elastic migrations', %r{^/(ee/)?elastic}
      add_group 'Enums',              %r{^/(ee/)?app/enums}
      add_group 'Events',             %r{^/(ee/)?app/events}
      add_group 'Experiments',        %r{^/(ee/)?app/experiments}
      add_group 'Finders',            %r{^/(ee/)?app/finders}
      add_group 'Fixtures',           %r{^/(ee/)?db/fixtures}
      add_group 'GraphQL',            %r{^/(ee/)?app/graphql}
      add_group 'Helpers',            %r{^/(ee/)?app/helpers}
      add_group 'Libraries',          %r{^/(ee/)?lib}
      add_group 'Mailers',            %r{^/(ee/)?app/mailers}
      add_group 'Metrics server',     %r{^/(ee/)?metrics_server}
      add_group 'Migrations',         %r{^/(ee/)?db/(geo/)?(migrate|optional_migrations|post_migrate)}
      add_group 'Models',             %r{^/(ee/)?app/models}
      add_group 'Policies',           %r{^/(ee/)?app/policies}
      add_group 'Presenters',         %r{^/(ee/)?app/presenters}
      add_group 'Replicators',        %r{^/(ee/)?app/replicators}
      add_group 'Seeds',              %r{^/(ee/)?db/seeds}
      add_group 'Serializers',        %r{^/(ee/)?app/serializers}
      add_group 'Services',           %r{^/(ee/)?app/services}
      add_group 'Sidekiq cluster',    %r{^/(ee/)?sidekiq_cluster}
      add_group 'Tooling',            %r{^/(ee/)?(danger|haml_lint|rubocop|scripts|tooling)}
      add_group 'Uploaders',          %r{^/(ee/)?app/uploaders}
      add_group 'Validators',         %r{^/(ee/)?app/validators}
      add_group 'Views',              %r{^/(ee/)?app/views}
      add_group 'Workers',            %r{^/(ee/)?app/workers}

      merge_timeout 365 * 24 * 3600
    end
  end
end