@samitouri / QOS-React-2 / commits / 72bbcad160

Add new test cli (#19184)

* Add new test cli * Remove --variant accidentally added to test-persist * s/test/tests * Updates from review * Update package.json tests * Missed a release channel in circle.yaml * Update config.yml to use just run: with test commands * Update release-channel options and add build dir checks * Update test args to use the new release-channel options * Fix error in circle config.yml * Fix a wrong condition for the --variant check * Fix a wrong condition for the --persistent check * Prettier * Require build check for devtool tests as well

Ricky committed Jun 25, 2020 at 20:39 UTC 72bbcad160e9c2d27143f8bd617138a2790de3e9
5 files changed +374 -98
.circleci/config.yml
+20 -74
@@ -97,10 +97,7 @@ jobs:
97 - checkout
98 - *restore_yarn_cache
99 - *run_yarn
100 - - run:
101 - environment:
102 - RELEASE_CHANNEL: stable
103 - command: yarn test --maxWorkers=2
100 + - run: yarn test --release-channel=stable --ci
101
102 yarn_test:
103 docker: *docker
@@ -109,10 +106,7 @@ jobs:
106 - checkout
107 - *restore_yarn_cache
108 - *run_yarn
112 - - run:
113 - environment:
114 - RELEASE_CHANNEL: experimental
115 - command: yarn test --maxWorkers=2
109 + - run: yarn test --ci
110
111 RELEASE_CHANNEL_stable_yarn_test_www:
112 docker: *docker
@@ -121,10 +115,7 @@ jobs:
115 - checkout
116 - *restore_yarn_cache
117 - *run_yarn
124 - - run:
125 - environment:
126 - RELEASE_CHANNEL: stable
127 - command: yarn test-www --maxWorkers=2
118 + - run: yarn test --release-channel=www-classic --ci
119
120 RELEASE_CHANNEL_stable_yarn_test_www_variant:
121 docker: *docker
@@ -133,10 +124,7 @@ jobs:
124 - checkout
125 - *restore_yarn_cache
126 - *run_yarn
136 - - run:
137 - environment:
138 - RELEASE_CHANNEL: stable
139 - command: yarn test-www-variant --maxWorkers=2
127 + - run: yarn test --release-channel=www-classic --variant --ci
128
129 RELEASE_CHANNEL_stable_yarn_test_prod_www:
130 docker: *docker
@@ -145,10 +133,7 @@ jobs:
133 - checkout
134 - *restore_yarn_cache
135 - *run_yarn
148 - - run:
149 - environment:
150 - RELEASE_CHANNEL: stable
151 - command: yarn test-prod-www --maxWorkers=2
136 + - run: yarn test --release-channel=www-classic --prod --ci
137
138 RELEASE_CHANNEL_stable_yarn_test_prod_www_variant:
139 docker: *docker
@@ -157,10 +142,7 @@ jobs:
142 - checkout
143 - *restore_yarn_cache
144 - *run_yarn
160 - - run:
161 - environment:
162 - RELEASE_CHANNEL: stable
163 - command: yarn test-prod-www-variant --maxWorkers=2
145 + - run: yarn test --release-channel=www-classic --prod --variant --ci
146
147 yarn_test_www:
148 docker: *docker
@@ -169,10 +151,7 @@ jobs:
151 - checkout
152 - *restore_yarn_cache
153 - *run_yarn
172 - - run:
173 - environment:
174 - RELEASE_CHANNEL: experimental
175 - command: yarn test-www --maxWorkers=2
154 + - run: yarn test --release-channel=www-modern --ci
155
156 yarn_test_www_variant:
157 docker: *docker
@@ -181,10 +160,7 @@ jobs:
160 - checkout
161 - *restore_yarn_cache
162 - *run_yarn
184 - - run:
185 - environment:
186 - RELEASE_CHANNEL: experimental
187 - command: yarn test-www-variant --maxWorkers=2
163 + - run: yarn test --release-channel=www-modern --variant --ci
164
165 yarn_test_prod_www:
166 docker: *docker
@@ -193,10 +169,7 @@ jobs:
169 - checkout
170 - *restore_yarn_cache
171 - *run_yarn
196 - - run:
197 - environment:
198 - RELEASE_CHANNEL: experimental
199 - command: yarn test-prod-www --maxWorkers=2
172 + - run: yarn test --release-channel=www-modern --prod --ci
173
174 yarn_test_prod_www_variant:
175 docker: *docker
@@ -205,10 +178,7 @@ jobs:
178 - checkout
179 - *restore_yarn_cache
180 - *run_yarn
208 - - run:
209 - environment:
210 - RELEASE_CHANNEL: experimental
211 - command: yarn test-prod-www-variant --maxWorkers=2
181 + - run: yarn test --release-channel=www-modern --prod --variant --ci
182
183 RELEASE_CHANNEL_stable_yarn_test_persistent:
184 docker: *docker
@@ -218,10 +188,7 @@ jobs:
188 - checkout
189 - *restore_yarn_cache
190 - *run_yarn
221 - - run:
222 - environment:
223 - RELEASE_CHANNEL: stable
224 - command: yarn test-persistent --maxWorkers=2
191 + - run: yarn test --release-channel=stable --persistent --ci
192
193 RELEASE_CHANNEL_stable_yarn_test_prod:
194 docker: *docker
@@ -231,10 +198,7 @@ jobs:
198 - checkout
199 - *restore_yarn_cache
200 - *run_yarn
234 - - run:
235 - environment:
236 - RELEASE_CHANNEL: stable
237 - command: yarn test-prod --maxWorkers=2
201 + - run: yarn test --release-channel=stable --prod --ci
202
203 yarn_test_prod:
204 docker: *docker
@@ -243,10 +207,7 @@ jobs:
207 - checkout
208 - *restore_yarn_cache
209 - *run_yarn
246 - - run:
247 - environment:
248 - RELEASE_CHANNEL: experimental
249 - command: yarn test-prod --maxWorkers=2
210 + - run: yarn test --release-channel=experimental --prod --ci
211
212 RELEASE_CHANNEL_stable_yarn_build:
213 docker: *docker
@@ -388,10 +349,7 @@ jobs:
349 - attach_workspace: *attach_workspace
350 - *restore_yarn_cache
351 - *run_yarn
391 - - run:
392 - environment:
393 - RELEASE_CHANNEL: stable
394 - command: yarn test-build --maxWorkers=2
352 + - run: yarn test --release-channel=stable --build --ci
353
354 yarn_test_build:
355 docker: *docker
@@ -401,10 +359,7 @@ jobs:
359 - attach_workspace: *attach_workspace
360 - *restore_yarn_cache
361 - *run_yarn
404 - - run:
405 - environment:
406 - RELEASE_CHANNEL: experimental
407 - command: yarn test-build --maxWorkers=2
362 + - run: yarn test --release-channel=experimental --build --ci
363
364 yarn_test_build_devtools:
365 docker: *docker
@@ -414,10 +369,7 @@ jobs:
369 - attach_workspace: *attach_workspace
370 - *restore_yarn_cache
371 - *run_yarn
417 - - run:
418 - environment:
419 - RELEASE_CHANNEL: experimental
420 - command: yarn test-build-devtools --maxWorkers=2
372 + - run: yarn test --project=devtools --build --ci
373
374 RELEASE_CHANNEL_stable_yarn_test_dom_fixtures:
375 docker: *docker
@@ -446,8 +398,8 @@ jobs:
398 - run:
399 name: Run fuzz tests
400 command: |
449 - FUZZ_TEST_SEED=$RANDOM yarn test fuzz --maxWorkers=2
450 - FUZZ_TEST_SEED=$RANDOM yarn test-prod fuzz --maxWorkers=2
401 + FUZZ_TEST_SEED=$RANDOM yarn test fuzz --ci
402 + FUZZ_TEST_SEED=$RANDOM yarn test --prod fuzz --ci
403
404 RELEASE_CHANNEL_stable_yarn_test_build_prod:
405 docker: *docker
@@ -457,10 +409,7 @@ jobs:
409 - attach_workspace: *attach_workspace
410 - *restore_yarn_cache
411 - *run_yarn
460 - - run:
461 - environment:
462 - RELEASE_CHANNEL: stable
463 - command: yarn test-build-prod --maxWorkers=2
412 + - run: yarn test --release-channel=stable --build --prod --ci
413
414 yarn_test_build_prod:
415 docker: *docker
@@ -470,10 +419,7 @@ jobs:
419 - attach_workspace: *attach_workspace
420 - *restore_yarn_cache
421 - *run_yarn
473 - - run:
474 - environment:
475 - RELEASE_CHANNEL: experimental
476 - command: yarn test-build-prod --maxWorkers=2
422 + - run: yarn test --release-channel=experimental --build --prod --ci
423
424 workflows:
425 version: 2
package.json
+18 -17
@@ -44,7 +44,6 @@
44 "core-js": "^3.6.4",
45 "coveralls": "^3.0.9",
46 "create-react-class": "^15.6.3",
47 - "cross-env": "^6.0.3",
47 "danger": "^9.2.10",
48 "error-stack-parser": "^2.0.6",
49 "eslint": "^7.0.0",
@@ -65,6 +64,7 @@
64 "gzip-size": "^5.1.1",
65 "jasmine-check": "^1.0.0-rc.0",
66 "jest": "^25.2.7",
67 + "jest-cli": "^25.2.7",
68 "jest-diff": "^25.2.6",
69 "jest-snapshot-serializer-raw": "^1.1.0",
70 "minimatch": "^3.0.4",
@@ -90,7 +90,8 @@
90 "through2": "^3.0.1",
91 "tmp": "^0.1.0",
92 "typescript": "^3.7.5",
93 - "webpack": "^4.41.2"
93 + "webpack": "^4.41.2",
94 + "yargs": "^15.3.1"
95 },
96 "devEngines": {
97 "node": "8.x || 9.x || 10.x || 11.x || 12.x || 13.x || 14.x"
@@ -106,21 +107,21 @@
107 "lint-build": "node ./scripts/rollup/validate/index.js",
108 "extract-errors": "yarn build --type=dev --extract-errors",
109 "postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json && node ./scripts/flow/createFlowConfigs.js && node ./scripts/yarn/downloadReactIsForPrettyFormat.js",
109 - "debug-test": "cross-env NODE_ENV=development node --inspect-brk node_modules/jest/bin/jest.js --config ./scripts/jest/config.source.js --runInBand",
110 - "test": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source.js",
111 - "test-www": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source-www.js",
112 - "test-www-variant": "cross-env NODE_ENV=development VARIANT=true jest --config ./scripts/jest/config.source-www.js",
113 - "test-prod-www": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.source-www.js",
114 - "test-prod-www-variant": "cross-env NODE_ENV=production VARIANT=true jest --config ./scripts/jest/config.source-www.js",
115 - "test-persistent": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.source-persistent.js",
116 - "debug-test-persistent": "cross-env NODE_ENV=development node --inspect-brk node_modules/jest/bin/jest.js --config ./scripts/jest/config.source-persistent.js --runInBand",
117 - "test-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.source.js",
118 - "debug-test-prod": "cross-env NODE_ENV=production node --inspect-brk node_modules/jest/bin/jest.js --config ./scripts/jest/config.source.js --runInBand",
119 - "test-prod-build": "yarn test-build-prod",
120 - "test-build": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.build.js",
121 - "test-build-prod": "cross-env NODE_ENV=production jest --config ./scripts/jest/config.build.js",
122 - "test-build-devtools": "cross-env NODE_ENV=development jest --config ./scripts/jest/config.build-devtools.js",
123 - "debug-test-build-devtools": "cross-env NODE_ENV=development node --inspect-brk node_modules/jest/bin/jest.js --config ./scripts/jest/config.build-devtools.js",
110 + "debug-test": "yarn test --debug",
111 + "test": "node ./scripts/jest/jest-cli.js",
112 + "test-www": "yarn test --release-channel=www-modern",
113 + "test-www-variant": "yarn test --release-channel=www-modern --variant",
114 + "test-prod-www": "yarn test --prod --release-channel=www-modern",
115 + "test-prod-www-variant": "yarn test --prod --release-channel=www-modern --variant",
116 + "test-persistent": "yarn test --persistent",
117 + "debug-test-persistent": "yarn test --debug --persistent",
118 + "test-prod": "yarn test --prod",
119 + "debug-test-prod": "yarn test --debug --prod",
120 + "test-prod-build": "yarn test --prod --build",
121 + "test-build": "yarn test --build",
122 + "test-build-prod": "yarn test --build --prod",
123 + "test-build-devtools": "yarn test --build --project devtools",
124 + "debug-test-build-devtools": "yarn test --debug --build --project devtools",
125 "test-dom-fixture": "cd fixtures/dom && yarn && yarn prestart && yarn test",
126 "flow": "node ./scripts/tasks/flow.js",
127 "flow-ci": "node ./scripts/tasks/flow-ci.js",
scripts/jest/jest-cli.js new
+323
@@ -0,0 +1,323 @@
1 +'use strict';
2 +
3 +const {spawn} = require('child_process');
4 +const chalk = require('chalk');
5 +const yargs = require('yargs');
6 +const fs = require('fs');
7 +const path = require('path');
8 +
9 +const ossConfig = './scripts/jest/config.source.js';
10 +const wwwConfig = './scripts/jest/config.source-www.js';
11 +const devToolsConfig = './scripts/jest/config.build-devtools.js';
12 +
13 +// TODO: These configs are separate but should be rolled into the configs above
14 +// so that the CLI can provide them as options for any of the configs.
15 +const persistentConfig = './scripts/jest/config.source-persistent.js';
16 +const buildConfig = './scripts/jest/config.build.js';
17 +
18 +const argv = yargs
19 + .parserConfiguration({
20 + // Important: This option tells yargs to move all other options not
21 + // specified here into the `_` key. We use this to send all of the
22 + // Jest options that we don't use through to Jest (like --watch).
23 + 'unknown-options-as-args': true,
24 + })
25 + .wrap(yargs.terminalWidth())
26 + .options({
27 + debug: {
28 + alias: 'd',
29 + describe: 'Run with node debugger attached.',
30 + requiresArg: false,
31 + type: 'boolean',
32 + default: false,
33 + },
34 + project: {
35 + alias: 'p',
36 + describe: 'Run the given project.',
37 + requiresArg: true,
38 + type: 'string',
39 + default: 'default',
40 + choices: ['default', 'devtools'],
41 + },
42 + releaseChannel: {
43 + alias: 'r',
44 + describe: 'Run with the given release channel.',
45 + requiresArg: true,
46 + type: 'string',
47 + default: 'experimental',
48 + choices: ['experimental', 'stable', 'www-classic', 'www-modern'],
49 + },
50 + env: {
51 + alias: 'e',
52 + describe: 'Run with the given node environment.',
53 + requiresArg: true,
54 + type: 'string',
55 + choices: ['development', 'production'],
56 + },
57 + prod: {
58 + describe: 'Run with NODE_ENV=production.',
59 + requiresArg: false,
60 + type: 'boolean',
61 + default: false,
62 + },
63 + dev: {
64 + describe: 'Run with NODE_ENV=development.',
65 + requiresArg: false,
66 + type: 'boolean',
67 + default: false,
68 + },
69 + variant: {
70 + alias: 'v',
71 + describe: 'Run with www variant set to true.',
72 + requiresArg: false,
73 + type: 'boolean',
74 + default: false,
75 + },
76 + build: {
77 + alias: 'b',
78 + describe: 'Run tests on builds.',
79 + requiresArg: false,
80 + type: 'boolean',
81 + default: false,
82 + },
83 + persistent: {
84 + alias: 'n',
85 + describe: 'Run with persistence.',
86 + requiresArg: false,
87 + type: 'boolean',
88 + default: false,
89 + },
90 + ci: {
91 + describe: 'Run tests in CI',
92 + requiresArg: false,
93 + type: 'boolean',
94 + default: false,
95 + },
96 + }).argv;
97 +
98 +function logError(message) {
99 + console.error(chalk.red(`\n${message}`));
100 +}
101 +function isWWWConfig() {
102 + return (
103 + argv.releaseChannel === 'www-classic' ||
104 + argv.releaseChannel === 'www-modern'
105 + );
106 +}
107 +
108 +function isOSSConfig() {
109 + return (
110 + argv.releaseChannel === 'stable' || argv.releaseChannel === 'experimental'
111 + );
112 +}
113 +
114 +function validateOptions() {
115 + let success = true;
116 +
117 + if (argv.project === 'devtools') {
118 + if (argv.prod) {
119 + logError(
120 + 'DevTool tests do not support --prod. Remove this option to continue.'
121 + );
122 + success = false;
123 + }
124 +
125 + if (argv.dev) {
126 + logError(
127 + 'DevTool tests do not support --dev. Remove this option to continue.'
128 + );
129 + success = false;
130 + }
131 +
132 + if (argv.env) {
133 + logError(
134 + 'DevTool tests do not support --env. Remove this option to continue.'
135 + );
136 + success = false;
137 + }
138 +
139 + if (argv.persistent) {
140 + logError(
141 + 'DevTool tests do not support --persistent. Remove this option to continue.'
142 + );
143 + success = false;
144 + }
145 +
146 + if (argv.variant) {
147 + logError(
148 + 'DevTool tests do not support --variant. Remove this option to continue.'
149 + );
150 + success = false;
151 + }
152 +
153 + if (!argv.build) {
154 + logError('DevTool tests require --build.');
155 + success = false;
156 + }
157 + }
158 +
159 + if (argv.variant && !isWWWConfig()) {
160 + logError(
161 + 'Variant is only supported for the www release channels. Update these options to continue.'
162 + );
163 + success = false;
164 + }
165 +
166 + if (argv.build && argv.persistent) {
167 + logError(
168 + 'Persistence is not supported for build targets. Update these options to continue.'
169 + );
170 + success = false;
171 + }
172 +
173 + if (!isOSSConfig() && argv.persistent) {
174 + logError(
175 + 'Persistence only supported for oss release channels. Update these options to continue.'
176 + );
177 + success = false;
178 + }
179 +
180 + if (argv.build && isWWWConfig()) {
181 + logError(
182 + 'Build targets are only not supported for www release channels. Update these options to continue.'
183 + );
184 + success = false;
185 + }
186 +
187 + if (argv.env && argv.env !== 'production' && argv.prod) {
188 + logError(
189 + 'Build type does not match --prod. Update these options to continue.'
190 + );
191 + success = false;
192 + }
193 +
194 + if (argv.env && argv.env !== 'development' && argv.dev) {
195 + logError(
196 + 'Build type does not match --dev. Update these options to continue.'
197 + );
198 + success = false;
199 + }
200 +
201 + if (argv.prod && argv.dev) {
202 + logError(
203 + 'Cannot supply both --prod and --dev. Remove one of these options to continue.'
204 + );
205 + success = false;
206 + }
207 +
208 + if (argv.build) {
209 + // TODO: We could build this if it hasn't been built yet.
210 + const buildDir = path.resolve('./build');
211 + if (!fs.existsSync(buildDir)) {
212 + logError(
213 + 'Build directory does not exist, please run `yarn build` or remove the --build option.'
214 + );
215 + success = false;
216 + } else if (Date.now() - fs.statSync(buildDir).mtimeMs > 1000 * 60 * 15) {
217 + logError(
218 + 'Warning: Running a build test with a build directory older than 15 minutes.\nPlease remember to run `yarn build` when using --build.'
219 + );
220 + }
221 + }
222 +
223 + if (!success) {
224 + console.log(''); // Extra newline.
225 + process.exit(1);
226 + }
227 +}
228 +
229 +function getCommandArgs() {
230 + // Add the correct Jest config.
231 + const args = ['./scripts/jest/jest.js', '--config'];
232 + if (argv.build) {
233 + args.push(buildConfig);
234 + } else if (argv.persistent) {
235 + args.push(persistentConfig);
236 + } else if (argv.project === 'devtools') {
237 + args.push(devToolsConfig);
238 + } else if (isWWWConfig()) {
239 + args.push(wwwConfig);
240 + } else if (isOSSConfig()) {
241 + args.push(ossConfig);
242 + } else {
243 + // We should not get here.
244 + logError('Unrecognized release channel');
245 + process.exit(1);
246 + }
247 +
248 + // Set the debug options, if necessary.
249 + if (argv.debug) {
250 + args.unshift('--inspect-brk');
251 + args.push('--runInBand');
252 + }
253 +
254 + // CI Environments have limited workers.
255 + if (argv.ci) {
256 + args.push('--maxWorkers=2');
257 + }
258 +
259 + // Push the remaining args onto the command.
260 + // This will send args like `--watch` to Jest.
261 + args.push(argv._);
262 +
263 + return args;
264 +}
265 +
266 +function getEnvars() {
267 + const envars = {
268 + NODE_ENV: argv.env || 'development',
269 + RELEASE_CHANNEL: argv.releaseChannel.match(/modern|experimental/)
270 + ? 'experimental'
271 + : 'stable',
272 + };
273 +
274 + if (argv.prod) {
275 + envars.NODE_ENV = 'production';
276 + }
277 +
278 + if (argv.dev) {
279 + envars.NODE_ENV = 'development';
280 + }
281 +
282 + if (argv.variant) {
283 + envars.VARIANT = true;
284 + }
285 +
286 + return envars;
287 +}
288 +
289 +function main() {
290 + validateOptions();
291 + const args = getCommandArgs();
292 + const envars = getEnvars();
293 +
294 + // Print the full command we're actually running.
295 + console.log(
296 + chalk.dim(
297 + `$ ${Object.keys(envars)
298 + .map(envar => `${envar}=${envars[envar]}`)
299 + .join(' ')}`,
300 + 'node',
301 + args.join(' ')
302 + )
303 + );
304 +
305 + // Print the release channel and project we're running for quick confirmation.
306 + console.log(
307 + chalk.blue(
308 + `\nRunning tests for ${argv.project} (${argv.releaseChannel})...`
309 + )
310 + );
311 +
312 + // Print a message that the debugger is starting just
313 + // for some extra feedback when running the debugger.
314 + if (argv.debug) {
315 + console.log(chalk.green('\nStarting debugger...'));
316 + console.log(chalk.green('Open chrome://inspect and press "inspect"\n'));
317 + }
318 +
319 + // Run Jest.
320 + spawn('node', args, {stdio: 'inherit', env: {...envars, ...process.env}});
321 +}
322 +
323 +main();
scripts/jest/jest.js new
+13
@@ -0,0 +1,13 @@
1 +#!/usr/bin/env node
2 +/**
3 + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
4 + *
5 + * This source code is licensed under the MIT license found in the
6 + * LICENSE file in the root directory of this source tree.
7 + */
8 +'use strict';
9 +
10 +// --- Welcome to debugging React tests ---
11 +// The debugger pauses on this statement so that you can open the dev tools.
12 +// You can now set breakpoints and begin debugging.
13 +require('jest-cli/bin/jest');
yarn.lock
-7
@@ -3973,13 +3973,6 @@ cross-env@^3.1.4:
3973 cross-spawn "^5.1.0"
3974 is-windows "^1.0.0"
3975
3976 -cross-env@^6.0.3:
3977 - version "6.0.3"
3978 - resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-6.0.3.tgz#4256b71e49b3a40637a0ce70768a6ef5c72ae941"
3979 - integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag==
3980 - dependencies:
3981 - cross-spawn "^7.0.0"
3982 -
3976 cross-spawn@6.0.5, cross-spawn@^6.0.0, cross-spawn@^6.0.5:
3977 version "6.0.5"
3978 resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"