Skip to content

Commit c5e039d

Browse files
authored
[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
1 parent 4c03bb6 commit c5e039d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/jest/jest-cli.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const chalk = require('chalk');
55
const yargs = require('yargs');
66
const fs = require('fs');
77
const path = require('path');
8+
const semver = require('semver');
89

910
const ossConfig = './scripts/jest/config.source.js';
1011
const wwwConfig = './scripts/jest/config.source-www.js';
@@ -104,6 +105,11 @@ const argv = yargs
104105
type: 'boolean',
105106
default: false,
106107
},
108+
reactVersion: {
109+
describe: 'DevTools testing for specific version of React',
110+
requiresArg: true,
111+
type: 'string',
112+
},
107113
}).argv;
108114

109115
function logError(message) {
@@ -166,11 +172,20 @@ function validateOptions() {
166172
logError('DevTool tests require --build.');
167173
success = false;
168174
}
175+
176+
if (argv.reactVersion && !semver.validRange(argv.reactVersion)) {
177+
success = false;
178+
logError('please specify a valid version range for --reactVersion');
179+
}
169180
} else {
170181
if (argv.compactConsole) {
171182
logError('Only DevTool tests support compactConsole flag.');
172183
success = false;
173184
}
185+
if (argv.reactVersion) {
186+
logError('Only DevTools tests supports the --reactVersion flag.');
187+
success = false;
188+
}
174189
}
175190

176191
if (isWWWConfig()) {
@@ -314,6 +329,10 @@ function getEnvars() {
314329
envars.VARIANT = true;
315330
}
316331

332+
if (argv.reactVersion) {
333+
envars.REACT_VERSION = semver.coerce(argv.reactVersion);
334+
}
335+
317336
return envars;
318337
}
319338

0 commit comments

Comments
 (0)