From fba32ebf146382c3a853e60fcbdec713f7ec2307 Mon Sep 17 00:00:00 2001 From: Joe Vilches Date: Thu, 14 Dec 2023 11:48:22 -0800 Subject: [PATCH] Add command line options to new node-based gentest (#1499) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1499 This uses the minimist library to parse the command line easily for flags and options. I added over the same ones in the ruby script (-f and -s). Reviewed By: yungsters, NickGerleman Differential Revision: D51877810 fbshipit-source-id: 643606cad25609ed2567bb63470818b81ebef531 --- gentest/gentest-driver.ts | 33 +++++++++++++++++++++++++++++---- gentest/package.json | 3 ++- yarn.lock | 5 +++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/gentest/gentest-driver.ts b/gentest/gentest-driver.ts index f5aed80d..99a7b95b 100644 --- a/gentest/gentest-driver.ts +++ b/gentest/gentest-driver.ts @@ -14,6 +14,29 @@ import * as process from 'node:process'; import {Builder, logging} from 'selenium-webdriver'; import {Options} from 'selenium-webdriver/chrome.js'; import {fileURLToPath} from 'url'; +import {stdin, stdout} from 'node:process'; +import minimist from 'minimist'; +import readline from 'node:readline/promises'; + +const argv = minimist(process.argv.slice(2)); +const specificFixture = argv.f || argv.fixture; +const suspend = argv.s || argv.suspend; + +const gentestDir = dirname(fileURLToPath(import.meta.url)); +const yogaDir = dirname(gentestDir); + +let fixtures = await fs.readdir(`${gentestDir}/fixtures`); +try { + if (specificFixture != null) { + await fs.access(`fixtures/${specificFixture}.html`, fs.constants.F_OK); + fixtures = [specificFixture + '.html']; + } +} catch (e) { + const errorMessage = e instanceof Error ? e.message : ''; + console.log( + `Trying to access ${specificFixture}.html threw an exception. Executing against all fixtures. ${errorMessage}`, + ); +} const options = new Options(); options.addArguments( @@ -30,10 +53,6 @@ const driver = await new Builder() .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}`, @@ -89,6 +108,12 @@ for (const fileName of fixtures) { fileNameNoExtension, ), ); + + if (suspend) { + const rl = readline.createInterface({input: stdin, output: stdout}); + await rl.question(''); + rl.close(); + } } await fs.unlink(`${gentestDir}/test.html`); await driver.quit(); diff --git a/gentest/package.json b/gentest/package.json index 9eab1a5a..557e5f39 100644 --- a/gentest/package.json +++ b/gentest/package.json @@ -15,6 +15,7 @@ "babel-register-esm": "^1.2.5", "@babel/core": "^7.23.0", "@babel/preset-typescript": "^7.23.0", - "@tsconfig/node18": "^18.2.2" + "@tsconfig/node18": "^18.2.2", + "@types/minimist": "^1.2.5" } } diff --git a/yarn.lock b/yarn.lock index 7cec75b6..a743b110 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2522,6 +2522,11 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== +"@types/minimist@^1.2.5": + version "1.2.5" + resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.5.tgz#ec10755e871497bcd83efe927e43ec46e8c0747e" + integrity sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag== + "@types/ms@*": version "0.7.33" resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.33.tgz#80bf1da64b15f21fd8c1dc387c31929317d99ee9"