@samitouri / QOS-React-2 / commits / c5e039d9b0

[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

Luna Ruan committed May 16, 2022 at 08:30 UTC c5e039d9b0857b10fbcea861469ad0948c84b045
1 file changed +19
scripts/jest/jest-cli.js
+19
@@ -5,6 +5,7 @@ const chalk = require('chalk');
5 const yargs = require('yargs');
6 const fs = require('fs');
7 const path = require('path');
8 +const semver = require('semver');
9
10 const ossConfig = './scripts/jest/config.source.js';
11 const wwwConfig = './scripts/jest/config.source-www.js';
@@ -104,6 +105,11 @@ const argv = yargs
105 type: 'boolean',
106 default: false,
107 },
108 + reactVersion: {
109 + describe: 'DevTools testing for specific version of React',
110 + requiresArg: true,
111 + type: 'string',
112 + },
113 }).argv;
114
115 function logError(message) {
@@ -166,11 +172,20 @@ function validateOptions() {
172 logError('DevTool tests require --build.');
173 success = false;
174 }
175 +
176 + if (argv.reactVersion && !semver.validRange(argv.reactVersion)) {
177 + success = false;
178 + logError('please specify a valid version range for --reactVersion');
179 + }
180 } else {
181 if (argv.compactConsole) {
182 logError('Only DevTool tests support compactConsole flag.');
183 success = false;
184 }
185 + if (argv.reactVersion) {
186 + logError('Only DevTools tests supports the --reactVersion flag.');
187 + success = false;
188 + }
189 }
190
191 if (isWWWConfig()) {
@@ -314,6 +329,10 @@ function getEnvars() {
329 envars.VARIANT = true;
330 }
331
332 + if (argv.reactVersion) {
333 + envars.REACT_VERSION = semver.coerce(argv.reactVersion);
334 + }
335 +
336 return envars;
337 }
338