mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Copy Flow parser tests to prepare TypeScript Parser
Summary: These files are directly copied from the flow parser to aid in reviewing the next two Diffs: D33080789 and D33081127. The only things that were changed during the copy are the import/require paths to ensure this diff could ship independently. (For this diff, these tests will still test the flow parser instead of importing the typescript parser). Changelog: [Internal][Add] - Copy Flow parser tests to aid in Diff review Reviewed By: RSNara Differential Revision: D33136296 fbshipit-source-id: 007e18618c9eba13728d19e4e342fbe9642adacc
This commit is contained in:
committed by
Facebook GitHub Bot
parent
078f6310ba
commit
f4e32ac5bf
Vendored
+599
@@ -0,0 +1,599 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
* @lint-ignore-every LICENSELINT
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const COMMANDS_DEFINED_INLINE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<{
|
||||
+hotspotUpdate: (ref: React.Ref<'RCTView'>, x: Int32, y: Int32) => void,
|
||||
}>({
|
||||
supportedCommands: ['hotspotUpdate'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const COMMANDS_DEFINED_MULTIPLE_TIMES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
|
||||
}
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props or events
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate'],
|
||||
});
|
||||
export const Commands2 = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const COMMANDS_DEFINED_WITHOUT_REF = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (x: Int32, y: Int32) => void;
|
||||
}
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props or events
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const COMMANDS_DEFINED_WITH_NULLABLE_REF = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (viewRef: ?React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
|
||||
}
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props or events
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const COMMANDS_DEFINED_WITH_MISMATCHED_METHOD_NAMES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
|
||||
+scrollTo: (
|
||||
viewRef: React.Ref<'RCTView'>,
|
||||
y: Int32,
|
||||
animated: boolean,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props or events
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['scrollTo'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const COMMANDS_DEFINED_WITHOUT_METHOD_NAMES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
interface NativeCommands {
|
||||
+hotspotUpdate: (viewRef: React.Ref<'RCTView'>, x: Int32, y: Int32) => void;
|
||||
+scrollTo: (
|
||||
viewRef: React.Ref<'RCTView'>,
|
||||
y: Int32,
|
||||
animated: boolean,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
// No props or events
|
||||
|}>;
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>();
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const NULLABLE_WITH_DEFAULT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {WithDefault, Float} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
nullable_with_default: ?WithDefault<Float, 1.0>,
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {WithDefault, Float} from 'CodegenTypes';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
required_key_with_default: WithDefault<Float, 1.0>,
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROPS_CONFLICT_NAMES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
isEnabled: string,
|
||||
|
||||
isEnabled: boolean,
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROPS_CONFLICT_WITH_SPREAD_PROPS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
type PropsInFile = $ReadOnly<{|
|
||||
isEnabled: boolean,
|
||||
|}>;
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
...PropsInFile,
|
||||
isEnabled: boolean,
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROPS_SPREAD_CONFLICTS_WITH_PROPS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
type PropsInFile = $ReadOnly<{|
|
||||
isEnabled: boolean,
|
||||
|}>;
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
isEnabled: boolean,
|
||||
...PropsInFile,
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_NUMBER_TYPE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp: number
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_MIXED_ENUM = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp?: WithDefault<'foo' | 1, 1>
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_ENUM_BOOLEAN = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp?: WithDefault<false | true, false>
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_ARRAY_MIXED_ENUM = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp?: WithDefault<$ReadOnlyArray<'foo' | 1>, 1>
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_ARRAY_ENUM_BOOLEAN = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp?: WithDefault<$ReadOnlyArray<false | true>, false>
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
const PROP_ARRAY_ENUM_INT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
export type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|
||||
someProp?: WithDefault<$ReadOnlyArray<0 | 1>, 0>
|
||||
|}>;
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
'Module',
|
||||
): HostComponent<ModuleProps>);
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
COMMANDS_DEFINED_INLINE,
|
||||
COMMANDS_DEFINED_MULTIPLE_TIMES,
|
||||
COMMANDS_DEFINED_WITH_MISMATCHED_METHOD_NAMES,
|
||||
COMMANDS_DEFINED_WITHOUT_METHOD_NAMES,
|
||||
COMMANDS_DEFINED_WITHOUT_REF,
|
||||
COMMANDS_DEFINED_WITH_NULLABLE_REF,
|
||||
NULLABLE_WITH_DEFAULT,
|
||||
NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE,
|
||||
PROPS_CONFLICT_NAMES,
|
||||
PROPS_CONFLICT_WITH_SPREAD_PROPS,
|
||||
PROPS_SPREAD_CONFLICTS_WITH_PROPS,
|
||||
PROP_NUMBER_TYPE,
|
||||
PROP_MIXED_ENUM,
|
||||
PROP_ENUM_BOOLEAN,
|
||||
PROP_ARRAY_MIXED_ENUM,
|
||||
PROP_ARRAY_ENUM_BOOLEAN,
|
||||
PROP_ARRAY_ENUM_INT,
|
||||
};
|
||||
Vendored
+1015
File diff suppressed because it is too large
Load Diff
+9422
File diff suppressed because it is too large
Load Diff
+44
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @emails oncall+react_native
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const FlowParser = require('../../../flow/index.js');
|
||||
const fixtures = require('../__test_fixtures__/fixtures.js');
|
||||
const failureFixtures = require('../__test_fixtures__/failures.js');
|
||||
jest.mock('fs', () => ({
|
||||
readFileSync: filename => fixtures[filename] || failureFixtures[filename],
|
||||
}));
|
||||
|
||||
describe('RN Codegen Flow Parser', () => {
|
||||
Object.keys(fixtures)
|
||||
.sort()
|
||||
.forEach(fixtureName => {
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
const schema = FlowParser.parseFile(fixtureName);
|
||||
const serializedSchema = JSON.stringify(schema, null, 2).replace(
|
||||
/"/g,
|
||||
"'",
|
||||
);
|
||||
expect(serializedSchema).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(failureFixtures)
|
||||
.sort()
|
||||
.forEach(fixtureName => {
|
||||
it(`Fails with error message ${fixtureName}`, () => {
|
||||
expect(() => {
|
||||
FlowParser.parseFile(fixtureName);
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
* @lint-ignore-every LICENSELINT
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
getString: (arg: string) => Array;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
getString: (arg : Array) => string;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
getString: (arg : $ReadOnly<>) => string;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULES_WITH_NOT_ONLY_METHODS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getBool: (arg: boolean) => boolean;
|
||||
+getNumber: (arg: number) => number;
|
||||
+getString: (arg: string) => string;
|
||||
sampleBool: boolean,
|
||||
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULES_WITH_UNNAMED_PARAMS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getBool: (boolean) => boolean;
|
||||
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getBool: (arg: boolean) => Promise;
|
||||
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec1>('SampleTurboModule1');
|
||||
export default TurboModuleRegistry.getEnforcing<Spec2>('SampleTurboModule2');
|
||||
|
||||
`;
|
||||
|
||||
const TWO_NATIVE_EXTENDING_TURBO_MODULE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getSth: (a : ?number) => void
|
||||
}
|
||||
|
||||
export interface Spec2 extends TurboModule {
|
||||
+getSth: (a : ?number) => void
|
||||
}
|
||||
|
||||
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
|
||||
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
|
||||
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
|
||||
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM,
|
||||
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT,
|
||||
TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT,
|
||||
NATIVE_MODULES_WITH_NOT_ONLY_METHODS,
|
||||
TWO_NATIVE_EXTENDING_TURBO_MODULE,
|
||||
};
|
||||
+596
@@ -0,0 +1,596 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
* @lint-ignore-every LICENSELINT
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const EMPTY_NATIVE_MODULE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// no methods
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_COMPLEX_OBJECTS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export type String = string;
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
+getObject: (arg: {|const1: {|const1: boolean|}|}) => {|
|
||||
const1: {|const1: boolean|},
|
||||
|};
|
||||
+getReadOnlyObject: (arg: $ReadOnly<{|const1: $ReadOnly<{|const1: boolean|}>|}>) => $ReadOnly<{|
|
||||
const1: {|const1: boolean|},
|
||||
|}>;
|
||||
+getObject2: (arg: { a: String }) => Object;
|
||||
+getObjectInArray: (arg: {const1: {|const1: boolean|}}) => Array<{|
|
||||
const1: {const1: boolean},
|
||||
|}>;
|
||||
}
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_COMPLEX_OBJECTS_WITH_NULLABLE_KEY = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getConstants: () => {|
|
||||
isTesting: boolean,
|
||||
reactNativeVersion: {|
|
||||
major: number,
|
||||
minor: number,
|
||||
patch?: number,
|
||||
prerelease: ?number,
|
||||
|},
|
||||
forceTouchAvailable: boolean,
|
||||
osVersion: string,
|
||||
systemName: string,
|
||||
interfaceIdiom: string,
|
||||
|};
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_BASIC_PARAM_TYPES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+passBool?: (arg: boolean) => void;
|
||||
+passNumber: (arg: number) => void;
|
||||
+passString: (arg: string) => void;
|
||||
+passStringish: (arg: Stringish) => void;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_ALIASES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
type NumNum = number;
|
||||
export type Num = (arg: NumNum) => void;
|
||||
type Num2 = Num;
|
||||
export type Void = void;
|
||||
export type A = number;
|
||||
export type B = number;
|
||||
export type ObjectAlias = {|
|
||||
x: number,
|
||||
y: number,
|
||||
label: string,
|
||||
truthy: boolean,
|
||||
|}
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
+getNumber: Num2;
|
||||
+getVoid: () => Void;
|
||||
+getArray: (a: Array<A>) => {| a: B |};
|
||||
+getStringFromAlias: (a: ObjectAlias) => string;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_NESTED_ALIASES = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
type Bar = {|
|
||||
z: number
|
||||
|};
|
||||
|
||||
type Foo = {|
|
||||
bar1: Bar,
|
||||
bar2: Bar,
|
||||
|};
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
foo1: (x: Foo) => Foo;
|
||||
foo2: (x: Foo) => void;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_FLOAT_AND_INT32 = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
import type {Int32, Float} from 'react-native/Libraries/Types/CodegenTypes';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getInt: (arg: Int32) => Int32;
|
||||
+getFloat: (arg: Float) => Float;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_SIMPLE_OBJECT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getObject: (o: Object) => Object,
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_UNSAFE_OBJECT = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
import type {UnsafeObject} from 'react-native/Libraries/Types/CodegenTypes';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getUnsafeObject: (o: UnsafeObject) => UnsafeObject,
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_ROOT_TAG = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {RootTag, TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getRootTag: (rootTag: RootTag) => RootTag,
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_NULLABLE_PARAM = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
+voidFunc: (arg: ?string) => void;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_BASIC_ARRAY = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getArray: (arg: Array<string>) => Array<string>;
|
||||
+getArray: (arg: $ReadOnlyArray<string>) => $ReadOnlyArray<string>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_OBJECT_WITH_OBJECT_DEFINED_IN_FILE_AS_PROPERTY = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
type DisplayMetricsAndroid = {|
|
||||
width: number,
|
||||
|};
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getConstants: () => {|
|
||||
+Dimensions: {
|
||||
windowPhysicalPixels: DisplayMetricsAndroid,
|
||||
},
|
||||
|};
|
||||
+getConstants2: () => $ReadOnly<{|
|
||||
+Dimensions: {
|
||||
windowPhysicalPixels: DisplayMetricsAndroid,
|
||||
},
|
||||
|}>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_ARRAY_WITH_UNION_AND_TOUPLE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getArray: (arg: Array<[string, string]>) => Array<string | number | boolean>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_ARRAY_WITH_ALIAS = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export type SomeString = string;
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getArray: (arg: Array<SomeString>) => Array<string>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_COMPLEX_ARRAY = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getArray: (arg: Array<Array<Array<Array<Array<string>>>>>) => Array<Array<Array<string>>>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_PROMISE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export type String = string;
|
||||
export type SomeObj = {| a: string |};
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+getValueWithPromise: () => Promise<string>;
|
||||
+getValueWithPromiseDefinedSomewhereElse: () => Promise<String>;
|
||||
+getValueWithPromiseObjDefinedSomewhereElse: () => Promise<SomeObj>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const NATIVE_MODULE_WITH_CALLBACK = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// Exported methods.
|
||||
+getValueWithCallback: (
|
||||
callback: (value: string, arr: Array<Array<string>>) => void,
|
||||
) => void;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
|
||||
|
||||
`;
|
||||
|
||||
const ANDROID_ONLY_NATIVE_MODULE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// no methods
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModuleAndroid');
|
||||
|
||||
`;
|
||||
|
||||
const IOS_ONLY_NATIVE_MODULE = `
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from '../RCTExport';
|
||||
import * as TurboModuleRegistry from '../TurboModuleRegistry';
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
// no methods
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModuleIOS');
|
||||
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
NATIVE_MODULE_WITH_OBJECT_WITH_OBJECT_DEFINED_IN_FILE_AS_PROPERTY,
|
||||
NATIVE_MODULE_WITH_ARRAY_WITH_UNION_AND_TOUPLE,
|
||||
NATIVE_MODULE_WITH_FLOAT_AND_INT32,
|
||||
NATIVE_MODULE_WITH_ALIASES,
|
||||
NATIVE_MODULE_WITH_NESTED_ALIASES,
|
||||
NATIVE_MODULE_WITH_PROMISE,
|
||||
NATIVE_MODULE_WITH_COMPLEX_OBJECTS,
|
||||
NATIVE_MODULE_WITH_COMPLEX_OBJECTS_WITH_NULLABLE_KEY,
|
||||
NATIVE_MODULE_WITH_SIMPLE_OBJECT,
|
||||
NATIVE_MODULE_WITH_UNSAFE_OBJECT,
|
||||
NATIVE_MODULE_WITH_ROOT_TAG,
|
||||
NATIVE_MODULE_WITH_NULLABLE_PARAM,
|
||||
NATIVE_MODULE_WITH_BASIC_ARRAY,
|
||||
NATIVE_MODULE_WITH_COMPLEX_ARRAY,
|
||||
NATIVE_MODULE_WITH_ARRAY_WITH_ALIAS,
|
||||
NATIVE_MODULE_WITH_BASIC_PARAM_TYPES,
|
||||
NATIVE_MODULE_WITH_CALLBACK,
|
||||
EMPTY_NATIVE_MODULE,
|
||||
ANDROID_ONLY_NATIVE_MODULE,
|
||||
IOS_ONLY_NATIVE_MODULE,
|
||||
};
|
||||
+1336
File diff suppressed because it is too large
Load Diff
+1240
File diff suppressed because it is too large
Load Diff
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @emails oncall+react_native
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const FlowParser = require('../../../flow/index.js');
|
||||
const fixtures = require('../__test_fixtures__/fixtures.js');
|
||||
const failureFixtures = require('../__test_fixtures__/failures.js');
|
||||
jest.mock('fs', () => ({
|
||||
readFileSync: filename => fixtures[filename] || failureFixtures[filename],
|
||||
}));
|
||||
|
||||
describe('RN Codegen Flow Parser', () => {
|
||||
Object.keys(fixtures)
|
||||
.sort()
|
||||
.forEach(fixtureName => {
|
||||
it(`can generate fixture ${fixtureName}`, () => {
|
||||
const schema = FlowParser.parseModuleFixture(fixtureName);
|
||||
const serializedSchema = JSON.stringify(schema, null, 2).replace(
|
||||
/"/g,
|
||||
"'",
|
||||
);
|
||||
|
||||
expect(serializedSchema).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(failureFixtures)
|
||||
.sort()
|
||||
.forEach(fixtureName => {
|
||||
it(`Fails with error message ${fixtureName}`, () => {
|
||||
expect(() => {
|
||||
FlowParser.parseModuleFixture(fixtureName);
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user