Skip to content

Commit 3ba58db

Browse files
committed
Add React Native test configs
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
1 parent dddfe68 commit 3ba58db

File tree

8 files changed

+107
-22
lines changed

8 files changed

+107
-22
lines changed

.circleci/config.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,15 @@ workflows:
450450
- "-r=www-modern --env=production --variant=false"
451451
- "-r=www-modern --env=development --variant=true"
452452
- "-r=www-modern --env=production --variant=true"
453-
454-
# TODO: Test more persistent configurations?
453+
- "-r=native-oss --env=development"
454+
- "-r=native-oss --env=production"
455+
- "-r=native-fb --env=development --variant=false"
456+
- "-r=native-fb --env=production --variant=false"
457+
- "-r=native-fb --env=development --variant=true"
458+
- "-r=native-fb --env=production --variant=true"
459+
460+
# TODO: Maybe we can delete these because the RN
461+
# configurations above are sufficient?
455462
- '-r=stable --env=development --persistent'
456463
- '-r=experimental --env=development --persistent'
457464
- yarn_build:

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ const SEND_ACCESSIBILITY_EVENT_REQUIRES_HOST_COMPONENT =
2525
"sendAccessibilityEvent was called with a ref that isn't a " +
2626
'native component. Use React.forwardRef to get access to the underlying native component';
2727

28-
jest.mock('shared/ReactFeatureFlags', () =>
29-
require('shared/forks/ReactFeatureFlags.native-oss'),
30-
);
31-
3228
describe('ReactFabric', () => {
3329
beforeEach(() => {
3430
jest.resetModules();

packages/shared/forks/ReactFeatureFlags.native-fb-dynamic.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import typeof * as DynamicFlagsType from 'ReactNativeInternalFeatureFlags';
1515
//
1616
// Use __VARIANT__ to simulate a GK. The tests will be run twice: once
1717
// with the __VARIANT__ set to `true`, and once set to `false`.
18-
//
19-
// TODO: __VARIANT__ isn't supported for React Native flags yet. You can set the
20-
// flag here but it won't be set to `true` in any of our test runs. Need to
21-
// update the test configuration.
2218

2319
export const enableUseRefAccessWarning = __VARIANT__;
2420
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const baseConfig = require('./config.base');
4+
5+
module.exports = Object.assign({}, baseConfig, {
6+
modulePathIgnorePatterns: [
7+
...baseConfig.modulePathIgnorePatterns,
8+
'packages/react-devtools-extensions',
9+
'packages/react-devtools-shared',
10+
'ReactIncrementalPerf',
11+
'ReactIncrementalUpdatesMinimalism',
12+
'ReactIncrementalTriangle',
13+
'ReactIncrementalReflection',
14+
'forwardRef',
15+
],
16+
setupFiles: [
17+
...baseConfig.setupFiles,
18+
require.resolve('./setupTests.native-fb.js'),
19+
require.resolve('./setupHostConfigs.js'),
20+
],
21+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const baseConfig = require('./config.base');
4+
5+
module.exports = Object.assign({}, baseConfig, {
6+
modulePathIgnorePatterns: [
7+
...baseConfig.modulePathIgnorePatterns,
8+
'packages/react-devtools-extensions',
9+
'packages/react-devtools-shared',
10+
'ReactIncrementalPerf',
11+
'ReactIncrementalUpdatesMinimalism',
12+
'ReactIncrementalTriangle',
13+
'ReactIncrementalReflection',
14+
'forwardRef',
15+
],
16+
setupFiles: [
17+
...baseConfig.setupFiles,
18+
require.resolve('./setupTests.native-oss.js'),
19+
require.resolve('./setupHostConfigs.js'),
20+
],
21+
});

scripts/jest/jest-cli.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const semver = require('semver');
1010
const ossConfig = './scripts/jest/config.source.js';
1111
const wwwConfig = './scripts/jest/config.source-www.js';
1212
const devToolsConfig = './scripts/jest/config.build-devtools.js';
13+
const nativeOssConfig = './scripts/jest/config.source-native-oss.js';
14+
const nativeFbConfig = './scripts/jest/config.source-native-fb.js';
1315

1416
// TODO: These configs are separate but should be rolled into the configs above
1517
// so that the CLI can provide them as options for any of the configs.
@@ -46,7 +48,14 @@ const argv = yargs
4648
requiresArg: true,
4749
type: 'string',
4850
default: 'experimental',
49-
choices: ['experimental', 'stable', 'www-classic', 'www-modern'],
51+
choices: [
52+
'experimental',
53+
'stable',
54+
'www-classic',
55+
'www-modern',
56+
'native-oss',
57+
'native-fb',
58+
],
5059
},
5160
env: {
5261
alias: 'e',
@@ -129,12 +138,6 @@ function isWWWConfig() {
129138
);
130139
}
131140

132-
function isOSSConfig() {
133-
return (
134-
argv.releaseChannel === 'stable' || argv.releaseChannel === 'experimental'
135-
);
136-
}
137-
138141
function validateOptions() {
139142
let success = true;
140143

@@ -194,15 +197,15 @@ function validateOptions() {
194197
}
195198
}
196199

197-
if (isWWWConfig()) {
200+
if (isWWWConfig() || argv.releaseChannel === 'native-fb') {
198201
if (argv.variant === undefined) {
199202
// Turn internal experiments on by default
200203
argv.variant = true;
201204
}
202205
} else {
203206
if (argv.variant) {
204207
logError(
205-
'Variant is only supported for the www release channels. Update these options to continue.'
208+
`Variant not supported for release channel ${argv.releaseChannel}. Update these options to continue.`
206209
);
207210
success = false;
208211
}
@@ -215,9 +218,15 @@ function validateOptions() {
215218
success = false;
216219
}
217220

218-
if (!isOSSConfig() && argv.persistent) {
221+
if (
222+
argv.persistent === true &&
223+
argv.releaseChannel !== 'experimental' &&
224+
argv.releaseChannel !== 'stable' &&
225+
argv.releaseChannel !== 'native-oss' &&
226+
argv.releaseChannel !== 'native-fb'
227+
) {
219228
logError(
220-
'Persistence only supported for oss release channels. Update these options to continue.'
229+
`Persistence not supported for release channel ${argv.releaseChannel}. Update these options to continue.`
221230
);
222231
success = false;
223232
}
@@ -282,8 +291,15 @@ function getCommandArgs() {
282291
args.push(persistentConfig);
283292
} else if (isWWWConfig()) {
284293
args.push(wwwConfig);
285-
} else if (isOSSConfig()) {
294+
} else if (
295+
argv.releaseChannel === 'stable' ||
296+
argv.releaseChannel === 'experimental'
297+
) {
286298
args.push(ossConfig);
299+
} else if (argv.releaseChannel === 'native-oss') {
300+
args.push(nativeOssConfig);
301+
} else if (argv.releaseChannel === 'native-fb') {
302+
args.push(nativeFbConfig);
287303
} else {
288304
// We should not get here.
289305
logError('Unrecognized release channel');
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
jest.mock('shared/ReactFeatureFlags', () => {
4+
jest.mock(
5+
'ReactNativeInternalFeatureFlags',
6+
() =>
7+
jest.requireActual('shared/forks/ReactFeatureFlags.native-fb-dynamic'),
8+
{virtual: true}
9+
);
10+
return jest.requireActual('shared/forks/ReactFeatureFlags.native-fb');
11+
});
12+
13+
jest.mock('react-noop-renderer', () =>
14+
jest.requireActual('react-noop-renderer/persistent')
15+
);
16+
17+
global.__PERSISTENT__ = true;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
jest.mock('shared/ReactFeatureFlags', () =>
4+
require('shared/forks/ReactFeatureFlags.native-oss')
5+
);
6+
7+
jest.mock('react-noop-renderer', () =>
8+
jest.requireActual('react-noop-renderer/persistent')
9+
);
10+
11+
global.__PERSISTENT__ = true;

0 commit comments

Comments
 (0)