Skip to content

Commit

Permalink
[DevTools] Add jest-cli --reactVersion argument (#24556)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lunaruan authored May 16, 2022
1 parent 4c03bb6 commit c5e039d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/jest/jest-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -314,6 +329,10 @@ function getEnvars() {
envars.VARIANT = true;
}

if (argv.reactVersion) {
envars.REACT_VERSION = semver.coerce(argv.reactVersion);
}

return envars;
}

Expand Down

0 comments on commit c5e039d

Please sign in to comment.