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
This commit is contained in:
Joe Vilches
2023-12-14 11:48:22 -08:00
committed by Facebook GitHub Bot
parent 98552078b1
commit fba32ebf14
3 changed files with 36 additions and 5 deletions

View File

@@ -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();

View File

@@ -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"
}
}

View File

@@ -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"