97 lines
2.6 KiB
JavaScript
97 lines
2.6 KiB
JavaScript
'use strict';
|
||
|
||
// These flags can be in a @gate pragma to declare that a test depends on
|
||
// certain conditions. They're like GKs.
|
||
//
|
||
// Examples:
|
||
// // @gate enableBlocksAPI
|
||
// test('uses an unstable API', () => {/*...*/})
|
||
//
|
||
// // @gate isDev
|
||
// test('only passes in development', () => {/*...*/})
|
||
//
|
||
// Most flags are defined in ReactFeatureFlags. If it's defined there, you don't
|
||
// have to do anything extra here.
|
||
//
|
||
// There are also flags based on the environment, like isDev. Feel free to
|
||
// add new flags and aliases below.
|
||
//
|
||
// You can also combine flags using multiple gates:
|
||
//
|
||
// // @gate enableBlocksAPI
|
||
// // @gate isDev
|
||
// test('both conditions must pass', () => {/*...*/})
|
||
//
|
||
// Or using logical operators
|
||
// // @gate enableBlocksAPI && isDev
|
||
// test('both conditions must pass', () => {/*...*/})
|
||
//
|
||
// Negation also works:
|
||
// // @gate !deprecateLegacyContext
|
||
// test('uses a deprecated feature', () => {/*...*/})
|
||
|
||
// These flags are based on the environment and don't change for the entire
|
||
// test run.
|
||
const environmentFlags = {
|
||
isDev,
|
||
build: isDev ? 'development' : 'production',
|
||
|
||
// TODO: Should "experimental" also imply "modern"? Maybe we should
|
||
// always compare to the channel?
|
||
experimental: __EXPERIMENTAL__,
|
||
// Similarly, should stable imply "classic"?
|
||
stable: !__EXPERIMENTAL__,
|
||
|
||
// Use this for tests that are known to be broken.
|
||
FIXME: false,
|
||
|
||
enableLegacyContext: false,
|
||
// 是否启用受控组件
|
||
enableControlledValue: true,
|
||
// 是否启动懒加载
|
||
enableLazyDelegate:false,
|
||
// radio受控
|
||
enableRadioControlled: false
|
||
};
|
||
|
||
function getTestFlags() {
|
||
// These are required on demand because some of our tests mutate them. We try
|
||
// not to but there are exceptions.
|
||
|
||
const releaseChannel = __EXPERIMENTAL__
|
||
? 'experimental'
|
||
: 'stable';
|
||
|
||
// Return a proxy so we can throw if you attempt to access a flag that
|
||
// doesn't exist.
|
||
return new Proxy(
|
||
{
|
||
// Feature flag aliases
|
||
// TODO: 调整测试框架移除flag,如: @gate new / @gate old会访问这些flag
|
||
old: true,
|
||
new: false,
|
||
|
||
channel: releaseChannel,
|
||
modern: releaseChannel === 'modern',
|
||
classic: releaseChannel === 'classic',
|
||
www: false,
|
||
|
||
...environmentFlags,
|
||
},
|
||
{
|
||
get(flags, flagName) {
|
||
const flagValue = flags[flagName];
|
||
if (flagValue === undefined && typeof flagName === 'string') {
|
||
throw Error(
|
||
`Feature flag "${flagName}" does not exist. See TestFlags.js ` +
|
||
'for more details.'
|
||
);
|
||
}
|
||
return flagValue;
|
||
},
|
||
}
|
||
);
|
||
}
|
||
|
||
exports.getTestFlags = getTestFlags;
|