Skip to content

Commit

Permalink
Add React Native test configs
Browse files Browse the repository at this point in the history
Adds new Jest configs for running our test suite using React Native
feature flags. This includes a special config for the version of RN
that Meta uses for internal dogfooding, similar to the equivalent ones
used for Meta's web codebase.

Practically speaking, the main benefit is we can run our tests in CI
with the experimental flags used at Meta without having to enable them
in the open source builds.

Usage:
  yarn test -r=native-oss
  yarn test -r=native-fb
  yarn test -r=native-fb --no-variant
  • Loading branch information
acdlite committed Oct 9, 2023
1 parent dddfe68 commit 7322b2d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 22 deletions.
11 changes: 9 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,15 @@ workflows:
- "-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=native-oss --env=development"
- "-r=native-oss --env=production"
- "-r=native-fb --env=development --variant=false"
- "-r=native-fb --env=production --variant=false"
- "-r=native-fb --env=development --variant=true"
- "-r=native-fb --env=production --variant=true"

# TODO: Maybe we can delete these because the RN
# configurations above are sufficient?
- '-r=stable --env=development --persistent'
- '-r=experimental --env=development --persistent'
- yarn_build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const SEND_ACCESSIBILITY_EVENT_REQUIRES_HOST_COMPONENT =
"sendAccessibilityEvent was called with a ref that isn't a " +
'native component. Use React.forwardRef to get access to the underlying native component';

jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss'),
);

describe('ReactFabric', () => {
beforeEach(() => {
jest.resetModules();
Expand Down
4 changes: 0 additions & 4 deletions packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
//
// Use __VARIANT__ to simulate a GK. The tests will be run twice: once
// with the __VARIANT__ set to `true`, and once set to `false`.
//
// TODO: __VARIANT__ isn't supported for React Native flags yet. You can set the
// flag here but it won't be set to `true` in any of our test runs. Need to
// update the test configuration.

export const enableUseRefAccessWarning = __VARIANT__;
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
Expand Down
21 changes: 21 additions & 0 deletions scripts/jest/config.source-native-fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const baseConfig = require('./config.base');

module.exports = Object.assign({}, baseConfig, {
modulePathIgnorePatterns: [
...baseConfig.modulePathIgnorePatterns,
'packages/react-devtools-extensions',
'packages/react-devtools-shared',
'ReactIncrementalPerf',
'ReactIncrementalUpdatesMinimalism',
'ReactIncrementalTriangle',
'ReactIncrementalReflection',
'forwardRef',
],
setupFiles: [
...baseConfig.setupFiles,
require.resolve('./setupTests.native-fb.js'),
require.resolve('./setupHostConfigs.js'),
],
});
21 changes: 21 additions & 0 deletions scripts/jest/config.source-native-oss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const baseConfig = require('./config.base');

module.exports = Object.assign({}, baseConfig, {
modulePathIgnorePatterns: [
...baseConfig.modulePathIgnorePatterns,
'packages/react-devtools-extensions',
'packages/react-devtools-shared',
'ReactIncrementalPerf',
'ReactIncrementalUpdatesMinimalism',
'ReactIncrementalTriangle',
'ReactIncrementalReflection',
'forwardRef',
],
setupFiles: [
...baseConfig.setupFiles,
require.resolve('./setupTests.native-oss.js'),
require.resolve('./setupHostConfigs.js'),
],
});
40 changes: 28 additions & 12 deletions scripts/jest/jest-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const semver = require('semver');
const ossConfig = './scripts/jest/config.source.js';
const wwwConfig = './scripts/jest/config.source-www.js';
const devToolsConfig = './scripts/jest/config.build-devtools.js';
const nativeOssConfig = './scripts/jest/config.source-native-oss.js';
const nativeFbConfig = './scripts/jest/config.source-native-fb.js';

// TODO: These configs are separate but should be rolled into the configs above
// so that the CLI can provide them as options for any of the configs.
Expand Down Expand Up @@ -46,7 +48,14 @@ const argv = yargs
requiresArg: true,
type: 'string',
default: 'experimental',
choices: ['experimental', 'stable', 'www-classic', 'www-modern'],
choices: [
'experimental',
'stable',
'www-classic',
'www-modern',
'native-oss',
'native-fb',
],
},
env: {
alias: 'e',
Expand Down Expand Up @@ -129,12 +138,6 @@ function isWWWConfig() {
);
}

function isOSSConfig() {
return (
argv.releaseChannel === 'stable' || argv.releaseChannel === 'experimental'
);
}

function validateOptions() {
let success = true;

Expand Down Expand Up @@ -194,15 +197,15 @@ function validateOptions() {
}
}

if (isWWWConfig()) {
if (isWWWConfig() || argv.releaseChannel === 'native-fb') {
if (argv.variant === undefined) {
// Turn internal experiments on by default
argv.variant = true;
}
} else {
if (argv.variant) {
logError(
'Variant is only supported for the www release channels. Update these options to continue.'
`Variant not supported for release channel ${argv.releaseChannel}. Update these options to continue.`
);
success = false;
}
Expand All @@ -215,9 +218,15 @@ function validateOptions() {
success = false;
}

if (!isOSSConfig() && argv.persistent) {
if (
argv.persistent === true &&
argv.releaseChannel !== 'oss-experimental' &&
argv.releaseChannel !== 'oss-stable' &&
argv.releaseChannel !== 'native-oss' &&
argv.releaseChannel !== 'native-fb'
) {
logError(
'Persistence only supported for oss release channels. Update these options to continue.'
`Persistence not supported for release channel ${argv.releaseChannel}. Update these options to continue.`
);
success = false;
}
Expand Down Expand Up @@ -282,8 +291,15 @@ function getCommandArgs() {
args.push(persistentConfig);
} else if (isWWWConfig()) {
args.push(wwwConfig);
} else if (isOSSConfig()) {
} else if (
argv.releaseChannel === 'stable' ||
argv.releaseChannel === 'experimental'
) {
args.push(ossConfig);
} else if (argv.releaseChannel === 'native-oss') {
args.push(nativeOssConfig);
} else if (argv.releaseChannel === 'native-fb') {
args.push(nativeFbConfig);
} else {
// We should not get here.
logError('Unrecognized release channel');
Expand Down
17 changes: 17 additions & 0 deletions scripts/jest/setupTests.native-fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

jest.mock('shared/ReactFeatureFlags', () => {
jest.mock(
'ReactNativeInternalFeatureFlags',
() =>
jest.requireActual('shared/forks/ReactFeatureFlags.native-fb-dynamic'),
{virtual: true}
);
return jest.requireActual('shared/forks/ReactFeatureFlags.native-fb');
});

jest.mock('react-noop-renderer', () =>
jest.requireActual('react-noop-renderer/persistent')
);

global.__PERSISTENT__ = true;
11 changes: 11 additions & 0 deletions scripts/jest/setupTests.native-oss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

jest.mock('shared/ReactFeatureFlags', () =>
require('shared/forks/ReactFeatureFlags.native-oss')
);

jest.mock('react-noop-renderer', () =>
jest.requireActual('react-noop-renderer/persistent')
);

global.__PERSISTENT__ = true;

0 comments on commit 7322b2d

Please sign in to comment.