diff --git a/Rakefile b/Rakefile index 5d63b7c97..e3014bbaf 100644 --- a/Rakefile +++ b/Rakefile @@ -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] @@ -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 diff --git a/lib/coverage/test_coverage.rb b/lib/coverage/test_coverage.rb index 0f4b5da22..3e2c27bcf 100644 --- a/lib/coverage/test_coverage.rb +++ b/lib/coverage/test_coverage.rb @@ -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) @@ -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 @@ -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') @@ -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| @@ -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)