-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract Knapsack integration from RSpec
- Loading branch information
1 parent
acc48cb
commit a0b41cc
Showing
15 changed files
with
253 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "knapsack_pro/extensions/rspec_extension" | ||
|
||
require_relative "runner" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
module Extension | ||
def self.included(base) | ||
base.singleton_class.prepend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
def setup! | ||
super | ||
|
||
::RSpec::Core::Runner.include(Datadog::CI::Contrib::Knapsack::Runner) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../integration" | ||
require_relative "patcher" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
# Knapsack Pro test runner instrumentation | ||
# https://github.com/KnapsackPro/knapsack_pro-ruby | ||
class Integration | ||
include Datadog::CI::Contrib::Integration | ||
|
||
Configuration = Struct.new(:enabled) | ||
|
||
MINIMUM_VERSION = Gem::Version.new("7.0.0") | ||
|
||
register_as :knapsack | ||
|
||
def self.version | ||
Gem.loaded_specs["knapsack_pro"]&.version | ||
end | ||
|
||
def self.loaded? | ||
!defined?(::KnapsackPro).nil? && !defined?(::KnapsackPro::Extensions::RSpecExtension).nil? && | ||
!defined?(::KnapsackPro::Extensions::RSpecExtension::Runner).nil? | ||
end | ||
|
||
def self.compatible? | ||
super && version >= MINIMUM_VERSION | ||
end | ||
|
||
# test environments should not auto instrument test libraries | ||
def auto_instrument? | ||
false | ||
end | ||
|
||
# TODO: not every integration needs a configuration | ||
def new_configuration | ||
Integration::Configuration.new(true) | ||
end | ||
|
||
def patcher | ||
Patcher | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../patcher" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
module Patcher | ||
include Datadog::CI::Contrib::Patcher | ||
|
||
module_function | ||
|
||
def target_version | ||
Integration.version | ||
end | ||
|
||
def patch | ||
if ::RSpec::Core::Runner.ancestors.include?(::KnapsackPro::Extensions::RSpecExtension::Runner) | ||
# knapsack already patched rspec runner | ||
require_relative "runner" | ||
::RSpec::Core::Runner.include(Datadog::CI::Contrib::Knapsack::Runner) | ||
else | ||
# knapsack didn't patch rspec runner yet | ||
require_relative "extension" | ||
::KnapsackPro::Extensions::RSpecExtension.include(Datadog::CI::Contrib::Knapsack::Extension) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../../ext/test" | ||
require_relative "../ext" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
module Runner | ||
def self.included(base) | ||
base.prepend(InstanceMethods) | ||
end | ||
|
||
module InstanceMethods | ||
# TODO: this is coupled to RSpec integration being present | ||
def knapsack__run_specs(*args) | ||
return super if ::RSpec.configuration.dry_run? && !datadog_configuration[:dry_run_enabled] | ||
return super unless datadog_configuration[:enabled] | ||
|
||
test_session = test_visibility_component.start_test_session( | ||
tags: { | ||
CI::Ext::Test::TAG_FRAMEWORK => CI::Contrib::RSpec::Ext::FRAMEWORK, | ||
CI::Ext::Test::TAG_FRAMEWORK_VERSION => CI::Contrib::RSpec::Integration.version.to_s | ||
}, | ||
service: datadog_configuration[:service_name] | ||
) | ||
|
||
test_module = test_visibility_component.start_test_module(CI::Contrib::RSpec::Ext::FRAMEWORK) | ||
|
||
result = super | ||
return result unless test_module && test_session | ||
|
||
if result != 0 | ||
test_module.failed! | ||
test_session.failed! | ||
else | ||
test_module.passed! | ||
test_session.passed! | ||
end | ||
test_module.finish | ||
test_session.finish | ||
|
||
result | ||
end | ||
|
||
private | ||
|
||
def datadog_configuration | ||
Datadog.configuration.ci[:rspec] | ||
end | ||
|
||
def test_visibility_component | ||
Datadog.send(:components).test_visibility | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
module Extension | ||
def self.included: (untyped base) -> untyped | ||
|
||
module ClassMethods | ||
include ::KnapsackPro::Extensions::RSpecExtension | ||
|
||
def setup!: () -> void | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
class Integration | ||
extend Datadog::CI::Contrib::Integration::ClassMethods | ||
include Datadog::CI::Contrib::Integration::InstanceMethods | ||
|
||
class Configuration | ||
def initialize: (bool enabled) -> void | ||
end | ||
|
||
MINIMUM_VERSION: Gem::Version | ||
|
||
def self.version: () -> untyped | ||
|
||
def self.loaded?: () -> bool | ||
|
||
def self.compatible?: () -> bool | ||
|
||
def auto_instrument?: () -> bool | ||
|
||
def new_configuration: () -> Configuration | ||
|
||
def patcher: () -> singleton(Patcher) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Knapsack | ||
module Patcher | ||
def self.patch: () -> void | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.