Skip to content

Commit

Permalink
Use jest projects instead of custom jest wrapper
Browse files Browse the repository at this point in the history
This uses Jest's first party support for "projects" instead of passing different config flags to jest. This should make it easier to locally run all variations of a single test and removes all the custom argument parsing.

## TODO
- is the outcome actually easier?
- look into devtools tests
- figure out how to handle the "build" variants, I'm thinking those might be a different package.json script that sets an env variable as it's probably rarely used locally (super slow to build before)
  • Loading branch information
kassens committed Apr 5, 2024
1 parent 2acfb7b commit 5f92568
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 854 deletions.
27 changes: 1 addition & 26 deletions .circleci/config.yml
Expand Up @@ -386,13 +386,10 @@ jobs:
docker: *docker
environment: *environment
parallelism: *TEST_PARALLELISM
parameters:
args:
type: string
steps:
- checkout
- setup_node_modules
- run: yarn test <<parameters.args>> --ci
- run: yarn jest --selectProjects=stable-production --maxWorkers=2 --ci --shard=$(expr $CIRCLE_NODE_INDEX + 1)/$CIRCLE_NODE_TOTAL

yarn_test_build:
docker: *docker
Expand Down Expand Up @@ -481,28 +478,6 @@ workflows:
branches:
ignore:
- builds/facebook-www
matrix:
parameters:
args:
# Intentionally passing these as strings instead of creating a
# separate parameter per CLI argument, since it's easier to
# control/see which combinations we want to run.
- "-r=stable --env=development"
- "-r=stable --env=production"
- "-r=experimental --env=development"
- "-r=experimental --env=production"
- "-r=www-classic --env=development --variant=false"
- "-r=www-classic --env=production --variant=false"
- "-r=www-classic --env=development --variant=true"
- "-r=www-classic --env=production --variant=true"
- "-r=www-modern --env=development --variant=false"
- "-r=www-modern --env=production --variant=false"
- "-r=www-modern --env=development --variant=true"
- "-r=www-modern --env=production --variant=true"

# TODO: Test more persistent configurations?
- '-r=stable --env=development --persistent'
- '-r=experimental --env=development --persistent'
- yarn_build:
filters:
branches:
Expand Down
171 changes: 171 additions & 0 deletions jest.config.js
@@ -0,0 +1,171 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

function createConfig({releaseChannel, env, variant, persistent}) {
let displayName = `${releaseChannel}-${env}`;
if (variant === true) {
displayName += '-variant';
}
if (persistent) {
displayName += '-persistent';
}

const setupFiles = [];
if (variant) {
setupFiles.push(require.resolve('./scripts/jest/setupEnvVariant.js'));
}
switch (env) {
case 'development':
setupFiles.push(require.resolve('./scripts/jest/setupEnvDevelopment.js'));
break;
case 'production':
setupFiles.push(require.resolve('./scripts/jest/setupEnvProduction.js'));
break;
default:
throw new Error(`Unexpected env: ${env}`);
}
setupFiles.push(require.resolve('./scripts/jest/setupEnvironment.js'));
if (persistent) {
setupFiles.push(require.resolve('./scripts/jest/setupTests.persistent.js'));
} else {
switch (releaseChannel) {
case 'www-classic':
case 'www-modern':
setupFiles.push(require.resolve('./scripts/jest/setupTests.www.js'));
break;
case 'experimental':
case 'stable':
// no special setup files
break;
default:
throw new Error(`Unexpected release channel: ${releaseChannel}`);
}
}
setupFiles.push(require.resolve('./scripts/jest/setupHostConfigs.js'));

const modulePathIgnorePatterns = [
'<rootDir>/scripts/rollup/shims/',
'<rootDir>/scripts/bench/',
'packages/react-devtools-extensions',
'packages/react-devtools-shared',
];

if (persistent) {
modulePathIgnorePatterns.push(
'ReactIncrementalPerf',
'ReactIncrementalUpdatesMinimalism',
'ReactIncrementalTriangle',
'ReactIncrementalReflection',
'forwardRef'
);
}

return {
displayName,
setupFiles,
modulePathIgnorePatterns,
transform: {
'.*':
env === 'development'
? require.resolve('./scripts/jest/preprocessor.dev.js')
: require.resolve('./scripts/jest/preprocessor.prod.js'),
},
prettierPath: require.resolve('prettier-2'),
setupFilesAfterEnv: [require.resolve('./scripts/jest/setupTests.js')],
// Only include files directly in __tests__, not in nested folders.
testRegex: '/__tests__/[^/]*(\\.js|\\.coffee|[^d]\\.ts)$',
moduleFileExtensions: ['js', 'json', 'node', 'coffee', 'ts'],
rootDir: process.cwd(),
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
fakeTimers: {
enableGlobally: true,
legacyFakeTimers: true,
},
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],
testEnvironment: 'jsdom',
testRunner: 'jest-circus/runner',
};
}

module.exports = {
globalSetup: require.resolve('./scripts/jest/setupGlobal.js'),
collectCoverageFrom: ['packages/**/*.js'],

projects: [
createConfig({
releaseChannel: 'stable',
env: 'development',
}),
createConfig({
releaseChannel: 'stable',
env: 'production',
}),
createConfig({
releaseChannel: 'stable',
env: 'development',
persistent: true,
}),

createConfig({
releaseChannel: 'experimental',
env: 'development',
}),
createConfig({
releaseChannel: 'experimental',
env: 'production',
}),
createConfig({
releaseChannel: 'experimental',
env: 'development',
persistent: true,
}),

createConfig({
releaseChannel: 'www-classic',
env: 'development',
variant: false,
}),
createConfig({
releaseChannel: 'www-classic',
env: 'production',
variant: false,
}),
createConfig({
releaseChannel: 'www-classic',
env: 'development',
variant: true,
}),
createConfig({
releaseChannel: 'www-classic',
env: 'production',
variant: true,
}),

createConfig({
releaseChannel: 'www-modern',
env: 'development',
variant: false,
}),
createConfig({
releaseChannel: 'www-modern',
env: 'production',
variant: false,
}),
createConfig({
releaseChannel: 'www-modern',
env: 'development',
variant: true,
}),
createConfig({
releaseChannel: 'www-modern',
env: 'production',
variant: true,
}),
],
};
8 changes: 1 addition & 7 deletions package.json
Expand Up @@ -103,9 +103,6 @@
"devEngines": {
"node": "16.x || 18.x || 20.x || 21.x"
},
"jest": {
"testRegex": "/scripts/jest/dont-run-jest-directly\\.js$"
},
"scripts": {
"build": "node ./scripts/rollup/build-all-release-channels.js",
"build-for-devtools": "cross-env RELEASE_CHANNEL=experimental yarn build react/index,react/jsx,react-dom/index,react-dom/unstable_testing,react-dom/test-utils,react-is,react-debug-tools,scheduler,react-test-renderer,react-refresh,react-art --type=NODE",
Expand All @@ -116,10 +113,7 @@
"lint-build": "node ./scripts/rollup/validate/index.js",
"extract-errors": "node scripts/error-codes/extract-errors.js",
"postinstall": "node node_modules/fbjs-scripts/node/check-dev-engines.js package.json && node ./scripts/flow/createFlowConfigs.js",
"test": "node ./scripts/jest/jest-cli.js",
"test-stable": "node ./scripts/jest/jest-cli.js --release-channel=stable",
"test-www": "node ./scripts/jest/jest-cli.js --release-channel=www-modern",
"test-classic": "node ./scripts/jest/jest-cli.js --release-channel=www-classic",
"test": "jest",
"test-build-devtools": "node ./scripts/jest/jest-cli.js --build --project devtools --release-channel=experimental",
"test-dom-fixture": "cd fixtures/dom && yarn && yarn predev && yarn test",
"flow": "node ./scripts/tasks/flow.js",
Expand Down
32 changes: 0 additions & 32 deletions scripts/jest/config.base.js

This file was deleted.

110 changes: 0 additions & 110 deletions scripts/jest/config.build-devtools.js

This file was deleted.

0 comments on commit 5f92568

Please sign in to comment.