From e099449c373d6280f8bad3f62591add1e6ed5b64 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Tue, 3 Oct 2023 11:31:34 -0700 Subject: [PATCH] Adding optional QOL flags to gentest Summary: This diff adds the ability to add 2 flags to gentest.rb that can help with debugging that I found myself wanting to use: * The ability to suspend the script. Meaning the chrome browser will pause after running each fixture so the user can inspect elements to see if their html is as expected. Normally, the browser just redirects to the next fixture * The ability to run a specific fixture instead of all fixtures. I found myself wanting to do this as I was changing one in the previous diff. If the user input is incorrect it just ignores it. Hopefully this will help make debugging this script a bit easier for noobs like me :P Reviewed By: NickGerleman Differential Revision: D49775228 fbshipit-source-id: 29933029119ee5afc0195213df70d4d2cf881a9e --- gentest/gentest.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/gentest/gentest.rb b/gentest/gentest.rb index 597853fa..d0f32ebb 100644 --- a/gentest/gentest.rb +++ b/gentest/gentest.rb @@ -7,6 +7,7 @@ require 'watir' require 'webdrivers' require 'fileutils' +require 'optparse' browser = Watir::Browser.new(:chrome, options: { "goog:loggingPrefs" => { @@ -18,7 +19,23 @@ browser = Watir::Browser.new(:chrome, options: { Dir.chdir(File.dirname($0)) -Dir['fixtures/*.html'].each do |file| +options = OpenStruct.new +OptionParser.new do |opts| + opts.on("-s", "--suspend", "Pauses the script after each fixture to allow for debugging on Chrome. Press enter to go to the next fixure.") do + options.suspend = true + end + opts.on("-f", "--fixture [FIXTURE]", String, "Only runs the script on the specific fixture.") do |f| + fixture = "fixtures/" + f + ".html" + if !File.file?(fixture) + puts fixture + " does not exist." + else + options.fixture = fixture + end + end +end.parse! + +files = options.fixture ? options.fixture : "fixtures/*.html" +Dir[files].each do |file| fixture = File.read(file) name = File.basename(file, '.*') puts "Generate #{name}" @@ -55,6 +72,10 @@ Dir['fixtures/*.html'].each do |file| f = File.open("../javascript/tests/generated/#{name}.test.ts", 'w') f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('YogaTest', name) f.close + + if options.suspend + gets + end end File.delete('test.html') browser.close