Authored by 张丽霞

add files

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
// These annotations are copy/pasted from the built-in Flow definitions for
// Native Map.
declare module "Map" {
// Use the name "MapPolyfill" so that we don't get confusing error
// messages about "Using Map instead of Map".
declare class MapPolyfill<K, V> {
@@iterator(): Iterator<[K, V]>;
constructor<Key, Value>(_: void): MapPolyfill<Key, Value>;
constructor<Key, Value>(_: null): MapPolyfill<Key, Value>;
constructor<Key, Value>(iterable: Iterable<[Key, Value]>): MapPolyfill<Key, Value>;
clear(): void;
delete(key: K): boolean;
entries(): Iterator<[K, V]>;
forEach(callbackfn: (value: V, index: K, map: MapPolyfill<K, V>) => mixed, thisArg?: any): void;
get(key: K): V | void;
has(key: K): boolean;
keys(): Iterator<K>;
set(key: K, value: V): MapPolyfill<K, V>;
size: number;
values(): Iterator<V>;
}
declare module.exports: typeof MapPolyfill;
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @nolint
*/
declare class Position {
coords: Coordinates,
timestamp: number,
mocked: boolean,
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
// These annotations are copy/pasted from the built-in Flow definitions for
// Native Promises with some non-standard APIs added in
declare class Promise<+R> {
constructor(callback: (
resolve: (result?: Promise<R> | R) => void,
reject: (error?: any) => void
) => mixed): void;
then<U>(
onFulfill?: ?(value: R) => Promise<U> | ?U,
onReject?: ?(error: any) => Promise<U> | ?U
): Promise<U>;
catch<U>(
onReject?: (error: any) => ?Promise<U> | U
): Promise<U>;
static resolve<T>(object?: Promise<T> | T): Promise<T>;
static reject<T>(error?: any): Promise<T>;
static all<T: Iterable<mixed>>(promises: T): Promise<$TupleMap<T, typeof $await>>;
static race<T>(promises: Array<Promise<T>>): Promise<T>;
// Non-standard APIs
// See https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/__forks__/Promise.native.js#L21
finally<U>(
onFinally?: ?(value: any) => Promise<U> | U
): Promise<U>;
done<U>(
onFulfill?: ?(value: R) => mixed,
onReject?: ?(error: any) => mixed
): void;
static cast<T>(object?: T): Promise<T>;
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @nolint
*/
// These annotations are copy/pasted from the built-in Flow definitions for
// Native Set.
declare module "Set" {
// Use the name "SetPolyfill" so that we don't get confusing error
// messages about "Using Set instead of Set".
declare class SetPolyfill<T> {
@@iterator(): Iterator<T>;
constructor(iterable: ?Iterable<T>): void;
add(value: T): SetPolyfill<T>;
clear(): void;
delete(value: T): boolean;
entries(): Iterator<[T, T]>;
forEach(callbackfn: (value: T, index: T, set: SetPolyfill<T>) => mixed, thisArg?: any): void;
has(value: T): boolean;
keys(): Iterator<T>;
size: number;
values(): Iterator<T>;
}
declare module.exports: typeof SetPolyfill;
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
declare module 'console' {
declare function assert(value: any, ...message: any): void;
declare function dir(
obj: Object,
options: {showHidden: boolean, depth: number, colors: boolean},
): void;
declare function error(...data: any): void;
declare function info(...data: any): void;
declare function log(...data: any): void;
declare function time(label: any): void;
declare function timeEnd(label: any): void;
declare function trace(first: any, ...rest: any): void;
declare function warn(...data: any): void;
declare class Console {
constructor(stdout: stream$Writable, stdin?: stream$Writable): void;
assert(value: any, ...message: any): void,
dir(
obj: Object,
options: {showHidden: boolean, depth: number, colors: boolean},
): void,
error(...data: any): void,
info(...data: any): void,
log(...data: any): void,
time(label: any): void,
timeEnd(label: any): void,
trace(first: any, ...rest: any): void,
warn(...data: any): void,
}
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @nolint
*/
// TODO (acdlite) Remove this file once flowtype/flow-typed/pull/773 is merged
declare module 'create-react-class' {
declare module.exports: React$CreateClass;
}
... ...
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
declare module 'fbjs/lib/invariant' {
declare module.exports: <T>(condition: any, message: string, ...args: Array<any>) => void;
}
declare module 'fbjs/lib/nullthrows' {
declare module.exports: <T>(value: ?T) => T;
}
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @nolint
*/
// TODO (bvaughn) Remove this file once flowtype/flow-typed/pull/773 is merged
type $npm$propTypes$ReactPropsCheckType = (
props: any,
propName: string,
componentName: string,
href?: string
) => ?Error;
declare module 'prop-types' {
declare var array: React$PropType$Primitive<Array<any>>;
declare var bool: React$PropType$Primitive<boolean>;
declare var func: React$PropType$Primitive<Function>;
declare var number: React$PropType$Primitive<number>;
declare var object: React$PropType$Primitive<Object>;
declare var string: React$PropType$Primitive<string>;
declare var any: React$PropType$Primitive<any>;
declare var arrayOf: React$PropType$ArrayOf;
declare var element: React$PropType$Primitive<any>; /* TODO */
declare var instanceOf: React$PropType$InstanceOf;
declare var node: React$PropType$Primitive<any>; /* TODO */
declare var objectOf: React$PropType$ObjectOf;
declare var oneOf: React$PropType$OneOf;
declare var oneOfType: React$PropType$OneOfType;
declare var shape: React$PropType$Shape;
declare function checkPropTypes<V>(
propTypes: $Subtype<{[_: $Keys<V>]: $npm$propTypes$ReactPropsCheckType}>,
values: V,
location: string,
componentName: string,
getStack: ?(() => ?string)
) : void;
}
... ...
{
"rules": {
// This folder currently runs through babel and doesn't need to be
// compatible with node 4
"comma-dangle": 0
}
}
... ...
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
/* eslint-env node */
const path = require('path');
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
module.exports = {
// Mocks asset requires to return the filename. Makes it possible to test that
// the correct images are loaded for components. Essentially
// require('img1.png') becomes `Object { "testUri": 'path/to/img1.png' }` in
// the Jest snapshot.
process: (_, filename) =>
`module.exports = {
testUri: ${JSON.stringify(path.relative(__dirname, filename))}
};`,
getCacheKey: createCacheKeyFunction([__filename]),
};
... ...
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
module.exports = moduleName => {
const RealComponent = require.requireActual(moduleName);
const React = require('react');
const Component = class extends RealComponent {
render() {
const name = RealComponent.displayName || RealComponent.name;
return React.createElement(
name.replace(/^(RCT|RK)/,''),
this.props,
this.props.children,
);
}
};
return Component;
};
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
/* eslint-env node */
'use strict';
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const babel = require('babel-core');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const babelRegisterOnly = require('metro/src/babelRegisterOnly');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const generate = require('babel-generator').default;
const nodeFiles = RegExp([
'/local-cli/',
'/metro(-bundler)?/',
].join('|'));
const nodeOptions = babelRegisterOnly.config([nodeFiles]);
babelRegisterOnly([]);
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
const transformer = require('metro/src/transformer.js');
module.exports = {
process(src/*: string*/, file/*: string*/) {
if (nodeFiles.test(file)) { // node specific transforms only
return babel.transform(
src,
Object.assign({filename: file}, nodeOptions)
).code;
}
const {ast} = transformer.transform({
filename: file,
localPath: file,
options: {
assetDataPlugins: [],
dev: true,
inlineRequires: true,
minify: false,
platform: '',
projectRoot: '',
retainLines: true,
},
src,
});
return generate(ast, {
code: true,
comments: false,
compact: false,
filename: file,
retainLines: true,
sourceFileName: file,
sourceMaps: true,
}, src).code;
},
getCacheKey: createCacheKeyFunction([
__filename,
require.resolve('metro/src/transformer.js'),
require.resolve('babel-core/package.json'),
]),
};
... ...
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const mockComponent = require.requireActual('./mockComponent');
require.requireActual('../Libraries/polyfills/babelHelpers.js');
require.requireActual('../Libraries/polyfills/Object.es7.js');
require.requireActual('../Libraries/polyfills/error-guard');
global.__DEV__ = true;
global.Promise = require.requireActual('promise');
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');
global.requestAnimationFrame = function(callback) {
return setTimeout(callback, 0);
};
global.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
jest
.mock('setupDevtools')
.mock('npmlog');
// there's a __mock__ for it.
jest.setMock('ErrorUtils', require('ErrorUtils'));
jest
.mock('InitializeCore', () => {})
.mock('Image', () => mockComponent('Image'))
.mock('Text', () => mockComponent('Text'))
.mock('TextInput', () => mockComponent('TextInput'))
.mock('Modal', () => mockComponent('Modal'))
.mock('View', () => mockComponent('View'))
.mock('RefreshControl', () => require.requireMock('RefreshControlMock'))
.mock('ScrollView', () => require.requireMock('ScrollViewMock'))
.mock(
'ActivityIndicator',
() => mockComponent('ActivityIndicator'),
)
.mock('ListView', () => require.requireMock('ListViewMock'))
.mock('ListViewDataSource', () => {
const DataSource = require.requireActual('ListViewDataSource');
DataSource.prototype.toJSON = function() {
function ListViewDataSource(dataBlob) {
this.items = 0;
// Ensure this doesn't throw.
try {
Object.keys(dataBlob).forEach(key => {
this.items += dataBlob[key] && (
dataBlob[key].length || dataBlob[key].size || 0
);
});
} catch (e) {
this.items = 'unknown';
}
}
return new ListViewDataSource(this._dataBlob);
};
return DataSource;
})
.mock('AnimatedImplementation', () => {
const AnimatedImplementation = require.requireActual('AnimatedImplementation');
const oldCreate = AnimatedImplementation.createAnimatedComponent;
AnimatedImplementation.createAnimatedComponent = function(Component) {
const Wrapped = oldCreate(Component);
Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;
return Wrapped;
};
return AnimatedImplementation;
})
.mock('ReactNative', () => {
const ReactNative = require.requireActual('ReactNative');
const NativeMethodsMixin =
ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.NativeMethodsMixin;
[
'measure',
'measureInWindow',
'measureLayout',
'setNativeProps',
'focus',
'blur',
].forEach((key) => {
let warned = false;
NativeMethodsMixin[key] = function() {
if (warned) {
return;
}
warned = true;
console.warn(
'Calling .' + key + '() in the test renderer environment is not ' +
'supported. Instead, mock out your components that use ' +
'findNodeHandle with replacements that don\'t rely on the ' +
'native environment.',
);
};
});
return ReactNative;
})
.mock('ensureComponentIsNative', () => () => true);
const mockEmptyObject = {};
const mockNativeModules = {
AlertManager: {
alertWithArgs: jest.fn(),
},
AppState: {
addEventListener: jest.fn(),
},
AsyncLocalStorage: {
multiGet: jest.fn((keys, callback) => process.nextTick(() => callback(null, []))),
multiSet: jest.fn((entries, callback) => process.nextTick(() => callback(null))),
multiRemove: jest.fn((keys, callback) => process.nextTick(() => callback(null))),
multiMerge: jest.fn((entries, callback) => process.nextTick(() => callback(null))),
clear: jest.fn(callback => process.nextTick(() => callback(null))),
getAllKeys: jest.fn(callback => process.nextTick(() => callback(null, []))),
},
BuildInfo: {
appVersion: '0',
buildVersion: '0',
},
Clipboard: {
setString: jest.fn(),
},
DataManager: {
queryData: jest.fn(),
},
DeviceInfo: {
Dimensions: {
window: {
fontScale: 2,
height: 1334,
scale: 2,
width: 750,
},
screen: {
fontScale: 2,
height: 1334,
scale: 2,
width: 750,
},
},
},
FacebookSDK: {
login: jest.fn(),
logout: jest.fn(),
queryGraphPath: jest.fn((path, method, params, callback) => callback()),
},
FbRelayNativeAdapter: {
updateCLC: jest.fn(),
},
GraphPhotoUpload: {
upload: jest.fn(),
},
I18n: {
translationsDictionary: JSON.stringify({
'Good bye, {name}!|Bye message': '\u{00A1}Adi\u{00F3}s {name}!',
}),
},
ImageLoader: {
getSize: jest.fn(
(url) => Promise.resolve({width: 320, height: 240})
),
prefetchImage: jest.fn(),
},
ImageViewManager: {
getSize: jest.fn(
(uri, success) => process.nextTick(() => success(320, 240))
),
prefetchImage: jest.fn(),
},
KeyboardObserver: {
addListener: jest.fn(),
removeListeners: jest.fn(),
},
Linking: {
openURL: jest.fn(),
canOpenURL: jest.fn(
() => Promise.resolve(true)
),
addEventListener: jest.fn(),
getInitialURL: jest.fn(
() => Promise.resolve()
),
removeEventListener: jest.fn(),
},
LocationObserver: {
getCurrentPosition: jest.fn(),
startObserving: jest.fn(),
stopObserving: jest.fn(),
},
ModalFullscreenViewManager: {},
NetInfo: {
fetch: jest.fn(
() => Promise.resolve()
),
getConnectionInfo: jest.fn(
() => Promise.resolve()
),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
isConnected: {
fetch: jest.fn(
() => Promise.resolve()
),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
},
isConnectionExpensive: jest.fn(
() => Promise.resolve()
),
},
Networking: {
sendRequest: jest.fn(),
abortRequest: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn(),
},
PushNotificationManager: {
presentLocalNotification: jest.fn(),
scheduleLocalNotification: jest.fn(),
cancelAllLocalNotifications: jest.fn(),
removeAllDeliveredNotifications: jest.fn(),
getDeliveredNotifications: jest.fn(callback => process.nextTick(() => [])),
removeDeliveredNotifications: jest.fn(),
setApplicationIconBadgeNumber: jest.fn(),
getApplicationIconBadgeNumber: jest.fn(callback => process.nextTick(() => callback(0))),
cancelLocalNotifications: jest.fn(),
getScheduledLocalNotifications: jest.fn(callback => process.nextTick(() => callback())),
requestPermissions: jest.fn(() => Promise.resolve({alert: true, badge: true, sound: true})),
abandonPermissions: jest.fn(),
checkPermissions: jest.fn(callback => process.nextTick(() => callback({alert: true, badge: true, sound: true}))),
getInitialNotification: jest.fn(() => Promise.resolve(null)),
addListener: jest.fn(),
removeListeners: jest.fn(),
},
SourceCode: {
scriptURL: null,
},
StatusBarManager: {
setColor: jest.fn(),
setStyle: jest.fn(),
setHidden: jest.fn(),
setNetworkActivityIndicatorVisible: jest.fn(),
setBackgroundColor: jest.fn(),
setTranslucent: jest.fn(),
},
Timing: {
createTimer: jest.fn(),
deleteTimer: jest.fn(),
},
UIManager: {
AndroidViewPager: {
Commands: {
setPage: jest.fn(),
setPageWithoutAnimation: jest.fn(),
},
},
blur: jest.fn(),
createView: jest.fn(),
dispatchViewManagerCommand: jest.fn(),
focus: jest.fn(),
setChildren: jest.fn(),
manageChildren: jest.fn(),
updateView: jest.fn(),
removeSubviewsFromContainerWithID: jest.fn(),
replaceExistingNonRootView: jest.fn(),
customBubblingEventTypes: {},
customDirectEventTypes: {},
AndroidTextInput: {
Commands: {},
},
ModalFullscreenView: {
Constants: {},
},
ScrollView: {
Constants: {},
},
View: {
Constants: {},
},
},
BlobModule: {
BLOB_URI_SCHEME: 'content',
BLOB_URI_HOST: null,
enableBlobSupport: jest.fn(),
disableBlobSupport: jest.fn(),
createFromParts: jest.fn(),
sendBlob: jest.fn(),
release: jest.fn(),
},
WebSocketModule: {
connect: jest.fn(),
send: jest.fn(),
sendBinary: jest.fn(),
ping: jest.fn(),
close: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn(),
},
};
Object.keys(mockNativeModules).forEach(module => {
try {
jest.doMock(module, () => mockNativeModules[module]); // needed by FacebookSDK-test
} catch (e) {
jest.doMock(module, () => mockNativeModules[module], {virtual: true});
}
});
jest
.doMock('NativeModules', () => mockNativeModules)
.doMock('ReactNativePropRegistry', () => ({
register: id => id,
getByID: () => mockEmptyObject,
}));
jest.doMock('requireNativeComponent', () => {
const React = require('react');
return viewName => class extends React.Component {
render() {
return React.createElement(
viewName,
this.props,
this.props.children,
);
}
};
});
... ...