-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
61 lines (47 loc) · 1.41 KB
/
main.rb
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
require 'open3'
require 'colored'
def get_env_variable(key)
return (ENV[key] == nil || ENV[key] == "") ? nil : ENV[key]
end
def env_has_key(key)
value = get_env_variable(key)
return value unless value.nil? || value.empty?
abort("Input #{key} is missing.")
end
$output_path = env_has_key("AC_OUTPUT_DIR")
$repo_path = env_has_key("AC_REPOSITORY_DIR")
$jest_params = get_env_variable("AC_RN_TEST_COMMAND_ARGS")
$exit_status_code = 0
def run_command(command, skip_abort)
puts "@@[command] #{command}"
status = nil
stdout_str = nil
stderr_str = nil
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
stdout.each_line do |line|
puts line
end
stdout_str = stdout.read
stderr_str = stderr.read
status = wait_thr.value
end
unless status.success?
puts stderr_str
unless skip_abort
exit 1
end
$exit_status_code = 1
end
end
def runTests
yarn_or_npm = File.file?("#{$repo_path}/yarn.lock") ? "yarn" : "npm"
report_command = "jest #{$jest_params}"
run_command("cd #{$repo_path} && #{yarn_or_npm} #{report_command}", true)
run_command("cp #{$repo_path}/test-reports/*-report.xml #{$output_path}", false)
File.open(ENV['AC_ENV_FILE_PATH'], 'a') do |f|
f.puts "AC_TEST_RESULT_PATH=#{$output_path}"
end
puts 'Tests completed successfully.'.green
end
runTests()
exit $exit_status_code