From c5e039d9b0857b10fbcea861469ad0948c84b045 Mon Sep 17 00:00:00 2001 From: Luna Ruan Date: Mon, 16 May 2022 08:30:43 -0700 Subject: [PATCH] [DevTools] Add jest-cli --reactVersion argument (#24556) Add `--reactVersion` argument. This argument is only used in DevTools. When this is specified, run only the tests that have the `// @reactVersion` pragma that satisfies the semver version range. Otherwise, run tests as normal --- scripts/jest/jest-cli.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/jest/jest-cli.js b/scripts/jest/jest-cli.js index e1a2d9b4285ae..effecf3d22eff 100644 --- a/scripts/jest/jest-cli.js +++ b/scripts/jest/jest-cli.js @@ -5,6 +5,7 @@ const chalk = require('chalk'); const yargs = require('yargs'); const fs = require('fs'); const path = require('path'); +const semver = require('semver'); const ossConfig = './scripts/jest/config.source.js'; const wwwConfig = './scripts/jest/config.source-www.js'; @@ -104,6 +105,11 @@ const argv = yargs type: 'boolean', default: false, }, + reactVersion: { + describe: 'DevTools testing for specific version of React', + requiresArg: true, + type: 'string', + }, }).argv; function logError(message) { @@ -166,11 +172,20 @@ function validateOptions() { logError('DevTool tests require --build.'); success = false; } + + if (argv.reactVersion && !semver.validRange(argv.reactVersion)) { + success = false; + logError('please specify a valid version range for --reactVersion'); + } } else { if (argv.compactConsole) { logError('Only DevTool tests support compactConsole flag.'); success = false; } + if (argv.reactVersion) { + logError('Only DevTools tests supports the --reactVersion flag.'); + success = false; + } } if (isWWWConfig()) { @@ -314,6 +329,10 @@ function getEnvars() { envars.VARIANT = true; } + if (argv.reactVersion) { + envars.REACT_VERSION = semver.coerce(argv.reactVersion); + } + return envars; }