From 98552078b1b93cafa04b2ee0060ad49df34510ac Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Thu, 14 Dec 2023 11:48:22 -0800 Subject: [PATCH] Create node version of gentest script (#1498) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1498 The only instance of ruby in this repository is `gentest.rb` used to generate test cases from html fixtures. This is quite annoying as ruby is not the most popular compared to something like Node and it does not integrate into the rest of our stack. I changed this to use Node.js instead. Instead of `watir` we now use `selenium-webdriver`. `watir` is backed by Selenium so I do not expect anything to change. Next commits will add command line options, clean up gentest.rb and its references, and change the README allow-large-files Reviewed By: yungsters, NickGerleman Differential Revision: D51874433 fbshipit-source-id: ef8588d48aa7f8b720b57df08738bbd01e9e74a3 --- .eslintrc.cjs | 1 + gentest/babel.config.cjs | 12 +++ gentest/gentest-driver.ts | 94 +++++++++++++++++++ gentest/package.json | 20 ++++ gentest/tsconfig.json | 6 ++ .../facebook/yoga/YGAbsolutePositionTest.java | 1 - .../generated/YGAbsolutePositionTest.test.ts | 2 +- package.json | 1 + tests/generated/YGAbsolutePositionTest.cpp | 2 - yarn.lock | 88 ++++++++++++++++- 10 files changed, 221 insertions(+), 6 deletions(-) create mode 100644 gentest/babel.config.cjs create mode 100644 gentest/gentest-driver.ts create mode 100644 gentest/package.json create mode 100644 gentest/tsconfig.json diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 442ae8f0..9f440e7b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -32,6 +32,7 @@ module.exports = { }, env: { es2020: true, + 'shared-node-browser': true, }, parserOptions: { ecmaVersion: 'latest', diff --git a/gentest/babel.config.cjs b/gentest/babel.config.cjs new file mode 100644 index 00000000..e1c2d8e4 --- /dev/null +++ b/gentest/babel.config.cjs @@ -0,0 +1,12 @@ +/** + * 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. + * + * @format + */ + +module.exports = { + presets: ['@babel/preset-typescript'], +}; diff --git a/gentest/gentest-driver.ts b/gentest/gentest-driver.ts new file mode 100644 index 00000000..f5aed80d --- /dev/null +++ b/gentest/gentest-driver.ts @@ -0,0 +1,94 @@ +/** + * 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. + * + * @format + */ + +import * as fs from 'node:fs/promises'; +import {format} from 'node:util'; +import {parse, dirname} from 'path'; +import * as process from 'node:process'; +import {Builder, logging} from 'selenium-webdriver'; +import {Options} from 'selenium-webdriver/chrome.js'; +import {fileURLToPath} from 'url'; + +const options = new Options(); +options.addArguments( + '--force-device-scale-factor=1', + '--window-position=0,0', + '--hide-scrollbars', +); +options.setLoggingPrefs({ + browser: 'ALL', + performance: 'ALL', +}); +const driver = await new Builder() + .forBrowser('chrome') + .setChromeOptions(options) + .build(); + +const gentestDir = dirname(fileURLToPath(import.meta.url)); +const yogaDir = dirname(gentestDir); + +const fixtures = await fs.readdir(`${gentestDir}/fixtures`); +for (const fileName of fixtures) { + const fixture = await fs.readFile( + `${gentestDir}/fixtures/${fileName}`, + 'utf8', + ); + const fileNameNoExtension = parse(fileName).name; + console.log('Generate', fileNameNoExtension); + + // TODO: replace this with something more robust than just blindly replacing + // start/end in the entire fixture + const ltrFixture = fixture + .replaceAll('start', 'left') + .replaceAll('end', 'right') + .replaceAll('flex-left', 'flex-start') + .replaceAll('flex-right', 'flex-end'); + + const rtlFixture = fixture + .replaceAll('start', 'right') + .replaceAll('end', 'left') + .replaceAll('flex-right', 'flex-start') + .replaceAll('flex-left', 'flex-end'); + + const template = await fs.readFile( + `${gentestDir}/test-template.html`, + 'utf8', + ); + const f = await fs.open(`${gentestDir}/test.html`, 'w'); + await f.write( + format(template, fileNameNoExtension, ltrFixture, rtlFixture, fixture), + ); + await f.close(); + + await driver.get('file://' + process.cwd() + '/test.html'); + const logs = await driver.manage().logs().get(logging.Type.BROWSER); + + await fs.writeFile( + `${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`, + JSON.parse(logs[0].message.replace(/^[^"]*/, '')), + ); + + await fs.writeFile( + `${yogaDir}/java/tests/com/facebook/yoga/${fileNameNoExtension}.java`, + JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace( + 'YogaTest', + fileNameNoExtension, + ), + ); + + await fs.writeFile( + `${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`, + JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace( + 'YogaTest', + fileNameNoExtension, + ), + ); +} +await fs.unlink(`${gentestDir}/test.html`); +await driver.quit(); diff --git a/gentest/package.json b/gentest/package.json new file mode 100644 index 00000000..9eab1a5a --- /dev/null +++ b/gentest/package.json @@ -0,0 +1,20 @@ +{ + "name": "gentest", + "version": "0.0.0", + "private": true, + "scripts": { + "gentest": "node --loader=babel-register-esm ./gentest-driver.ts" + }, + "type": "module", + "dependencies": { + "selenium-webdriver": "^4.16.0" + }, + "devDependencies": { + "@types/node": "^20.10.3", + "@types/selenium-webdriver": "^4.1.21", + "babel-register-esm": "^1.2.5", + "@babel/core": "^7.23.0", + "@babel/preset-typescript": "^7.23.0", + "@tsconfig/node18": "^18.2.2" + } +} diff --git a/gentest/tsconfig.json b/gentest/tsconfig.json new file mode 100644 index 00000000..6380e0c6 --- /dev/null +++ b/gentest/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "@tsconfig/node18/tsconfig.json", + "compilerOptions": { + "noEmit": true + } +} diff --git a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java index 5e9f2d4e..502dcb5e 100644 --- a/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java +++ b/java/tests/com/facebook/yoga/YGAbsolutePositionTest.java @@ -1124,7 +1124,6 @@ public class YGAbsolutePositionTest { } @Test - @Ignore public void test_absolute_layout_percentage_height_based_on_padded_parent() { YogaConfig config = YogaConfigFactory.create(); config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ABSOLUTE_PERCENTAGE_AGAINST_PADDING_EDGE, true); diff --git a/javascript/tests/generated/YGAbsolutePositionTest.test.ts b/javascript/tests/generated/YGAbsolutePositionTest.test.ts index e9810a8b..b0ffc6f1 100644 --- a/javascript/tests/generated/YGAbsolutePositionTest.test.ts +++ b/javascript/tests/generated/YGAbsolutePositionTest.test.ts @@ -1255,7 +1255,7 @@ test('percent_absolute_position_infinite_height', () => { config.free(); } }); -test.skip('absolute_layout_percentage_height_based_on_padded_parent', () => { +test('absolute_layout_percentage_height_based_on_padded_parent', () => { const config = Yoga.Config.create(); let root; diff --git a/package.json b/package.json index 0eb4a539..bab221a2 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ }, "workspaces": [ "javascript", + "gentest", "website-next" ], "devDependencies": { diff --git a/tests/generated/YGAbsolutePositionTest.cpp b/tests/generated/YGAbsolutePositionTest.cpp index 0e6e497c..57786dbd 100644 --- a/tests/generated/YGAbsolutePositionTest.cpp +++ b/tests/generated/YGAbsolutePositionTest.cpp @@ -1132,8 +1132,6 @@ TEST(YogaTest, percent_absolute_position_infinite_height) { } TEST(YogaTest, absolute_layout_percentage_height_based_on_padded_parent) { - GTEST_SKIP(); - const YGConfigRef config = YGConfigNew(); YGConfigSetExperimentalFeatureEnabled(config, YGExperimentalFeatureAbsolutePercentageAgainstPaddingEdge, true); diff --git a/yarn.lock b/yarn.lock index 09294c32..7cec75b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2284,6 +2284,11 @@ resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" integrity sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA== +"@tsconfig/node18@^18.2.2": + version "18.2.2" + resolved "https://registry.yarnpkg.com/@tsconfig/node18/-/node18-18.2.2.tgz#81fb16ecff0d400b1cbadbf76713b50f331029ce" + integrity sha512-d6McJeGsuoRlwWZmVIeE8CUA27lu6jLjvv1JzqmpsytOYYbVi1tHZEnwCNVOXnj4pyLvneZlFlpXUK+X9wBWyw== + "@types/acorn@^4.0.0": version "4.0.6" resolved "https://registry.yarnpkg.com/@types/acorn/-/acorn-4.0.6.tgz#d61ca5480300ac41a7d973dd5b84d0a591154a22" @@ -2542,6 +2547,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.45.tgz#2c0fafd78705e7a18b7906b5201a522719dc5190" integrity sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw== +"@types/node@^20.10.3": + version "20.10.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.4.tgz#b246fd84d55d5b1b71bf51f964bd514409347198" + integrity sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg== + dependencies: + undici-types "~5.26.4" + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -2624,6 +2636,13 @@ resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5" integrity sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ== +"@types/selenium-webdriver@^4.1.21": + version "4.1.21" + resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-4.1.21.tgz#79fe31faf9953a4143c3e32944d98d5146bbe185" + integrity sha512-QGURnImvxYlIQz5DVhvHdqpYNLBjhJ2Vm+cnQI2G9QZzkWlZm0LkLcvDcHp+qE6N2KBz4CeuvXgPO7W3XQ0Tyw== + dependencies: + "@types/ws" "*" + "@types/semver@^7.3.12": version "7.3.13" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" @@ -2679,6 +2698,13 @@ resolved "https://registry.yarnpkg.com/@types/which/-/which-3.0.0.tgz#849afdd9fdcb0b67339b9cfc80fa6ea4e0253fc5" integrity sha512-ASCxdbsrwNfSMXALlC3Decif9rwDMu+80KGp5zI2RLRotfMsTv7fHL8W8VDp24wymzDyIFudhUeSCugrgRFfHQ== +"@types/ws@*": + version "8.5.10" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.10.tgz#4acfb517970853fa6574a3a6886791d04a396787" + integrity sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A== + dependencies: + "@types/node" "*" + "@types/ws@^8.5.5": version "8.5.5" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb" @@ -5809,6 +5835,11 @@ image-size@^1.0.2: dependencies: queue "6.0.2" +immediate@~3.0.5: + version "3.0.6" + resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" + integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ== + immer@^9.0.7: version "9.0.21" resolved "https://registry.yarnpkg.com/immer/-/immer-9.0.21.tgz#1e025ea31a40f24fb064f1fef23e931496330176" @@ -6624,6 +6655,16 @@ jsonfile@^6.0.1: optionalDependencies: graceful-fs "^4.1.6" +jszip@^3.10.1: + version "3.10.1" + resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2" + integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g== + dependencies: + lie "~3.3.0" + pako "~1.0.2" + readable-stream "~2.3.6" + setimmediate "^1.0.5" + "just-scripts-utils@>=1.2.0 <2.0.0": version "1.2.0" resolved "https://registry.yarnpkg.com/just-scripts-utils/-/just-scripts-utils-1.2.0.tgz#232a768a1083626e47c29c749e33d964ee027d56" @@ -6733,6 +6774,13 @@ levn@^0.4.1: prelude-ls "^1.2.1" type-check "~0.4.0" +lie@~3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a" + integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ== + dependencies: + immediate "~3.0.5" + lilconfig@^2.0.3: version "2.1.0" resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.1.0.tgz#78e23ac89ebb7e1bfbf25b18043de756548e7f52" @@ -8078,6 +8126,11 @@ package-json@^8.1.0: registry-url "^6.0.0" semver "^7.3.7" +pako@~1.0.2: + version "1.0.11" + resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf" + integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw== + param-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/param-case/-/param-case-3.0.4.tgz#7d17fe4aa12bde34d4a77d91acfb6219caad01c5" @@ -8849,7 +8902,7 @@ react@^18.0.0: dependencies: loose-envify "^1.1.0" -readable-stream@^2.0.1: +readable-stream@^2.0.1, readable-stream@~2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b" integrity sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA== @@ -9155,7 +9208,7 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -rimraf@^3.0.2: +rimraf@^3.0.0, rimraf@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== @@ -9259,6 +9312,15 @@ select-hose@^2.0.0: resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" integrity sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg== +selenium-webdriver@^4.16.0: + version "4.16.0" + resolved "https://registry.yarnpkg.com/selenium-webdriver/-/selenium-webdriver-4.16.0.tgz#2f1a2426d876aa389d1c937b00f034c2c7808360" + integrity sha512-IbqpRpfGE7JDGgXHJeWuCqT/tUqnLvZ14csSwt+S8o4nJo3RtQoE9VR4jB47tP/A8ArkYsh/THuMY6kyRP6kuA== + dependencies: + jszip "^3.10.1" + tmp "^0.2.1" + ws ">=8.14.2" + selfsigned@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.1.1.tgz#18a7613d714c0cd3385c48af0075abf3f266af61" @@ -9360,6 +9422,11 @@ serve-static@1.15.0: parseurl "~1.3.3" send "0.18.0" +setimmediate@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" + integrity sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA== + setprototypeof@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656" @@ -9845,6 +9912,13 @@ tiny-warning@^1.0.0: resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754" integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA== +tmp@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.1.tgz#8457fc3037dcf4719c251367a1af6500ee1ccf14" + integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ== + dependencies: + rimraf "^3.0.0" + tmpl@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc" @@ -9992,6 +10066,11 @@ undertaker@^1.3.0: object.reduce "^1.0.0" undertaker-registry "^1.0.0" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc" @@ -10475,6 +10554,11 @@ write-file-atomic@^4.0.1: imurmurhash "^0.1.4" signal-exit "^3.0.7" +ws@>=8.14.2: + version "8.14.2" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f" + integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g== + ws@^7.3.1: version "7.5.9" resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.9.tgz#54fa7db29f4c7cec68b1ddd3a89de099942bb591"