forked from facebook/yoga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgentest.rb
81 lines (67 loc) · 2.38 KB
/
gentest.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env ruby
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
require 'watir'
require 'webdrivers'
require 'fileutils'
require 'optparse'
browser = Watir::Browser.new(:chrome, options: {
"goog:loggingPrefs" => {
"browser" => "ALL",
"performance" => "ALL"
},
args: ['--force-device-scale-factor=1', '--window-position=0,0']
})
Dir.chdir(File.dirname($0))
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}"
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')
f.write sprintf(template, name, ltr_fixture, rtl_fixture, fixture)
f.close
FileUtils.copy('test.html', "#{name}.html") if $DEBUG
browser.goto('file://' + Dir.pwd + '/test.html')
logs = browser.driver.logs.get(:browser)
f = File.open("../tests/generated/#{name}.cpp", 'w')
f.write eval(logs[0].message.sub(/^[^"]*/, ''))
f.close
f = File.open("../java/tests/com/facebook/yoga/#{name}.java", 'w')
f.write eval(logs[1].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
f.close
print logs[3]
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