Created
August 18, 2024 13:47
-
-
Save wittawasw/34de0325d6269b62de867b1d32f7ce74 to your computer and use it in GitHub Desktop.
scripts to generate test tasks in https://github.com/eventpop/parallelizer format
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
// Generate with these commands | |
// | |
// rails new <app_name> && cd <app_name> | |
// rails g scaffold courses name:string description:text summary:string{500} | |
// rails g scaffold student name:string email:text | |
// ruby <relative_path>/generate_tests.rb | |
{ | |
"id": "test-rails-example-app-1723988622", | |
"tasks": [ | |
{ | |
"id": "task-should-get-index-1723988622", | |
"displayName": "Task should get index", | |
"spec": "rails test test/controllers/courses_controller_test.rb:8" | |
}, | |
{ | |
"id": "task-should-get-new-1723988622", | |
"displayName": "Task should get new", | |
"spec": "rails test test/controllers/courses_controller_test.rb:13" | |
}, | |
{ | |
"id": "task-should-create-course-1723988622", | |
"displayName": "Task should create course", | |
"spec": "rails test test/controllers/courses_controller_test.rb:18" | |
}, | |
{ | |
"id": "task-should-show-course-1723988622", | |
"displayName": "Task should show course", | |
"spec": "rails test test/controllers/courses_controller_test.rb:26" | |
}, | |
{ | |
"id": "task-should-get-edit-1723988622", | |
"displayName": "Task should get edit", | |
"spec": "rails test test/controllers/courses_controller_test.rb:31" | |
}, | |
{ | |
"id": "task-should-update-course-1723988622", | |
"displayName": "Task should update course", | |
"spec": "rails test test/controllers/courses_controller_test.rb:36" | |
}, | |
{ | |
"id": "task-should-destroy-course-1723988622", | |
"displayName": "Task should destroy course", | |
"spec": "rails test test/controllers/courses_controller_test.rb:41" | |
}, | |
{ | |
"id": "task-should-get-index-1723988622", | |
"displayName": "Task should get index", | |
"spec": "rails test test/controllers/students_controller_test.rb:8" | |
}, | |
{ | |
"id": "task-should-get-new-1723988622", | |
"displayName": "Task should get new", | |
"spec": "rails test test/controllers/students_controller_test.rb:13" | |
}, | |
{ | |
"id": "task-should-create-student-1723988622", | |
"displayName": "Task should create student", | |
"spec": "rails test test/controllers/students_controller_test.rb:18" | |
}, | |
{ | |
"id": "task-should-show-student-1723988622", | |
"displayName": "Task should show student", | |
"spec": "rails test test/controllers/students_controller_test.rb:26" | |
}, | |
{ | |
"id": "task-should-get-edit-1723988622", | |
"displayName": "Task should get edit", | |
"spec": "rails test test/controllers/students_controller_test.rb:31" | |
}, | |
{ | |
"id": "task-should-update-student-1723988622", | |
"displayName": "Task should update student", | |
"spec": "rails test test/controllers/students_controller_test.rb:36" | |
}, | |
{ | |
"id": "task-should-destroy-student-1723988622", | |
"displayName": "Task should destroy student", | |
"spec": "rails test test/controllers/students_controller_test.rb:41" | |
}, | |
{ | |
"id": "task-visiting-the-index-1723988622", | |
"displayName": "Task visiting the index", | |
"spec": "rails test test/system/courses_test.rb:8" | |
}, | |
{ | |
"id": "task-should-create-course-1723988622", | |
"displayName": "Task should create course", | |
"spec": "rails test test/system/courses_test.rb:13" | |
}, | |
{ | |
"id": "task-should-update-course-1723988622", | |
"displayName": "Task should update Course", | |
"spec": "rails test test/system/courses_test.rb:26" | |
}, | |
{ | |
"id": "task-should-destroy-course-1723988622", | |
"displayName": "Task should destroy Course", | |
"spec": "rails test test/system/courses_test.rb:39" | |
}, | |
{ | |
"id": "task-visiting-the-index-1723988622", | |
"displayName": "Task visiting the index", | |
"spec": "rails test test/system/students_test.rb:8" | |
}, | |
{ | |
"id": "task-should-create-student-1723988622", | |
"displayName": "Task should create student", | |
"spec": "rails test test/system/students_test.rb:13" | |
}, | |
{ | |
"id": "task-should-update-student-1723988622", | |
"displayName": "Task should update Student", | |
"spec": "rails test test/system/students_test.rb:25" | |
}, | |
{ | |
"id": "task-should-destroy-student-1723988622", | |
"displayName": "Task should destroy Student", | |
"spec": "rails test test/system/students_test.rb:37" | |
} | |
] | |
} |
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
require 'json' | |
test_commands = [] | |
Dir.glob('test/**/*_test.rb').each do |file| | |
File.readlines(file).each_with_index do |line, index| | |
if match = line.match(/^\s*(test|it)\s+"([^"]+)"\s+do/) | |
task_name = match[2] | |
test_commands << { file: file, line: index + 1, name: task_name } | |
end | |
end | |
end | |
Dir.glob('spec/**/*_spec.rb').each do |file| | |
File.readlines(file).each_with_index do |line, index| | |
if match = line.match(/^\s*(test|it)\s+"([^"]+)"\s+do/) | |
task_name = match[2] | |
test_commands << { file: file, line: index + 1, name: task_name } | |
end | |
end | |
end | |
time_now = Time.now.to_i | |
job_id = "test-rails-example-app-#{time_now}" | |
tasks = test_commands.map do |cmd| | |
{ | |
id: "task-#{cmd[:name].gsub(/\s+/, '-').downcase}-#{time_now}", | |
displayName: "Task #{cmd[:name]}", | |
spec: "rails test #{cmd[:file]}:#{cmd[:line]}" | |
} | |
end | |
job_file = { | |
id: job_id, | |
tasks: tasks | |
} | |
File.open('parallelizer_job.json', 'w') do |f| | |
f.write(JSON.pretty_generate(job_file)) | |
end | |
puts "Parallelizer Job file created: parallelizer_job.json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment