2016-10-23 10:27:30 -07:00
|
|
|
#!/usr/bin/env ruby
|
2019-10-15 10:30:08 -07:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the MIT license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree.
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2017-11-30 06:49:11 -08:00
|
|
|
require 'watir'
|
2016-10-23 10:27:30 -07:00
|
|
|
require 'fileutils'
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
|
2016-11-23 11:12:51 -08:00
|
|
|
"loggingPrefs"=>{
|
|
|
|
"browser"=>"ALL",
|
|
|
|
"performance"=>"ALL"
|
|
|
|
}
|
|
|
|
)
|
2017-02-23 01:15:36 -08:00
|
|
|
browser = Watir::Browser.new(:chrome, :desired_capabilities => caps, :switches => ['--force-device-scale-factor=1', '--window-position=0,0'])
|
2017-11-30 06:49:11 -08:00
|
|
|
|
2016-10-23 10:27:34 -07:00
|
|
|
Dir.chdir(File.dirname($0))
|
2016-11-23 11:12:51 -08:00
|
|
|
|
2016-10-23 10:27:30 -07:00
|
|
|
Dir['fixtures/*.html'].each do |file|
|
|
|
|
fixture = File.read(file)
|
|
|
|
name = File.basename(file, '.*')
|
|
|
|
puts "Generate #{name}"
|
|
|
|
|
|
|
|
ltr_fixture = fixture.gsub('start', 'left')
|
|
|
|
.gsub('end', 'right')
|
|
|
|
.gsub('flex-left', 'flex-start')
|
|
|
|
.gsub('flex-right', 'flex-end')
|
|
|
|
|
|
|
|
rtl_fixture = fixture.gsub('start', 'right')
|
|
|
|
.gsub('end', 'left')
|
|
|
|
.gsub('flex-right', 'flex-start')
|
|
|
|
.gsub('flex-left', 'flex-end')
|
|
|
|
|
|
|
|
template = File.open('test-template.html').read
|
|
|
|
f = File.open('test.html', 'w')
|
2016-11-23 11:12:51 -08:00
|
|
|
f.write sprintf(template, name, ltr_fixture, rtl_fixture, fixture)
|
2016-10-23 10:27:30 -07:00
|
|
|
f.close
|
|
|
|
FileUtils.copy('test.html', "#{name}.html") if $DEBUG
|
|
|
|
|
|
|
|
browser.goto('file://' + Dir.pwd + '/test.html')
|
|
|
|
logs = browser.driver.manage.logs.get(:browser)
|
|
|
|
|
|
|
|
f = File.open("../tests/#{name}.cpp", 'w')
|
|
|
|
f.write eval(logs[0].message.sub(/^[^"]*/, ''))
|
|
|
|
f.close
|
|
|
|
|
2016-12-07 05:12:11 -08:00
|
|
|
f = File.open("../java/tests/com/facebook/yoga/#{name}.java", 'w')
|
2016-12-03 04:40:21 -08:00
|
|
|
f.write eval(logs[1].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
|
2016-10-23 10:27:30 -07:00
|
|
|
f.close
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
f = File.open("../csharp/tests/Facebook.Yoga/#{name}.cs", 'w')
|
|
|
|
f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
|
2016-10-23 10:27:30 -07:00
|
|
|
f.close
|
2017-01-02 02:22:45 -08:00
|
|
|
|
2017-03-28 10:28:53 -07:00
|
|
|
print logs[4]
|
|
|
|
|
2017-01-02 02:22:45 -08:00
|
|
|
f = File.open("../javascript/tests/Facebook.Yoga/#{name}.js", 'w')
|
|
|
|
f.write eval(logs[3].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
|
|
|
|
f.close
|
2016-10-23 10:27:30 -07:00
|
|
|
end
|
|
|
|
File.delete('test.html')
|
|
|
|
browser.close
|