Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add React Native test configs #27489

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the import here not just a circular dependency? The ReactNativeInternalFeatureFlags import should suffice, since that's defined in flow/xplat.js

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 !== 'experimental' &&
argv.releaseChannel !== '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;