Skip to content

Commit

Permalink
feature: rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
askonev committed Nov 16, 2023
1 parent 534a9e8 commit 6ddaa3a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'csv'
require_relative 'lib/doc_builder_testing'
require_relative 'lib/coverage/test_coverage'

task default: %w[run_tests_on_desktop]

Expand Down Expand Up @@ -45,3 +46,9 @@ desc 'run rspec via windows'
task :run_test_on_win do
system('rspec --tag win')
end

desc 'run coverage'
task :coverage do
File.binwrite(File.join(Dir.pwd, 'reports', 'coverage_result.json').to_s,
TestCoverage.run(TestCoverage.get_api))
end
26 changes: 16 additions & 10 deletions lib/coverage/test_coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ module TestCoverage
REDACTORS = {
'CDE' => 'Text document API',
'CSE' => 'Spreadsheet API',
'CPE' => 'Presentation API'
'CPE' => 'Presentation API',
'Form' => 'Form API'
}.freeze

SOURCES = {
'CDE' => File.join(Dir.pwd, 'js', 'docx', 'smoke').to_s,
'CSE' => File.join(Dir.pwd, 'js', 'xlsx', 'smoke').to_s,
'CPE' => File.join(Dir.pwd, 'js', 'pptx', 'smoke').to_s
'CPE' => File.join(Dir.pwd, 'js', 'pptx', 'smoke').to_s,
'Form' => File.join(Dir.pwd, 'js', 'form', 'smoke').to_s
}.freeze

def self.address
ADDRESS
end

def self.redactors
REDACTORS
end

# MethodCoverage class
class Matcher
def initialize(pattern, path)
Expand Down Expand Up @@ -49,7 +59,8 @@ def recursive_search(pattern = @pattern, node = @path)
def contains_matches?(path, pattern)
File.open(path, 'r') do |file|
file.each_line do |line|
next unless line.include?("#{pattern}(")
# regex pattern for js method
next unless line.match?(/#{pattern}\(.*\)/)

@flag = true # Switch global flag
break
Expand All @@ -58,7 +69,7 @@ def contains_matches?(path, pattern)
end
end

def self.get_api(url)
def self.get_api(url = ADDRESS)
file_url = URI.parse(url)
http = Net::HTTP.new(file_url.host.to_s, file_url.port)
http.use_ssl = (file_url.scheme = 'https')
Expand All @@ -70,7 +81,7 @@ def self.get_api(url)
end
end

def self.run(method_list = get_api(ADDRESS))
def self.run(method_list)
method_list = JSON.parse(method_list)
REDACTORS.each do |key, type|
method_list[type].each do |_api_class, method|
Expand All @@ -80,8 +91,3 @@ def self.run(method_list = get_api(ADDRESS))
JSON.pretty_generate(method_list)
end
end

# p TestCoverage::Matcher.new('SetData', 'js').pattern_found?

File.binwrite(File.join(Dir.pwd, 'reports', 'coverage_result.json').to_s,
TestCoverage.run)

0 comments on commit 6ddaa3a

Please sign in to comment.