Skip to content

Commit 821382b

Browse files
charlesbdudleyfacebook-github-bot
authored andcommitted
TypeScript Module Tests
Summary: Tests for Native Modules. Fixtures, Failures and the e2e tests were copied from the flow parser, modified for TypeScript and then the snapshots were diff'ed to ensure the parsers generated the same schema given the same (in spirit, different in syntax) input. Changelog: [General][Add] - Tests for TypeScript support for Native Module Codegen spec parsing Reviewed By: RSNara Differential Revision: D33081127 fbshipit-source-id: 3d7270dddd568090ec93d475a08a6a6011dad63c
1 parent f9e512e commit 821382b

File tree

5 files changed

+223
-347
lines changed

5 files changed

+223
-347
lines changed

packages/react-native-codegen/src/parsers/typescript/modules/__test_fixtures__/failures.js

+14-70
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,24 @@
99
* @lint-ignore-every LICENSELINT
1010
*/
1111

12-
'use strict';
13-
1412
const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT = `
1513
/**
1614
* Copyright (c) Facebook, Inc. and its affiliates.
1715
*
1816
* This source code is licensed under the MIT license found in the
1917
* LICENSE file in the root directory of this source tree.
2018
*
21-
* @flow strict-local
2219
* @format
2320
*/
2421
25-
'use strict';
26-
27-
import type {TurboModule} from '../RCTExport';
28-
import * as TurboModuleRegistry from '../TurboModuleRegistry';
22+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
23+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
2924
3025
export interface Spec extends TurboModule {
3126
getString: (arg: string) => Array;
3227
}
3328
3429
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
35-
3630
`;
3731

3832
const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM = `
@@ -42,45 +36,17 @@ const NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM = `
4236
* This source code is licensed under the MIT license found in the
4337
* LICENSE file in the root directory of this source tree.
4438
*
45-
* @flow strict-local
46-
* @format
47-
*/
48-
49-
'use strict';
50-
51-
import type {TurboModule} from '../RCTExport';
52-
import * as TurboModuleRegistry from '../TurboModuleRegistry';
53-
54-
export interface Spec extends TurboModule {
55-
getString: (arg : Array) => string;
56-
}
57-
58-
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
59-
60-
`;
61-
62-
const NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT = `
63-
/**
64-
* Copyright (c) Facebook, Inc. and its affiliates.
65-
*
66-
* This source code is licensed under the MIT license found in the
67-
* LICENSE file in the root directory of this source tree.
68-
*
69-
* @flow strict-local
7039
* @format
7140
*/
7241
73-
'use strict';
74-
75-
import type {TurboModule} from '../RCTExport';
76-
import * as TurboModuleRegistry from '../TurboModuleRegistry';
42+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
43+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
7744
7845
export interface Spec extends TurboModule {
79-
getString: (arg : $ReadOnly<>) => string;
46+
getString: (arg: Array) => string;
8047
}
8148
8249
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
83-
8450
`;
8551

8652
const NATIVE_MODULES_WITH_NOT_ONLY_METHODS = `
@@ -90,19 +56,16 @@ const NATIVE_MODULES_WITH_NOT_ONLY_METHODS = `
9056
* This source code is licensed under the MIT license found in the
9157
* LICENSE file in the root directory of this source tree.
9258
*
93-
* @flow strict-local
9459
* @format
9560
*/
9661
97-
'use strict';
98-
9962
import type {TurboModule} from '../RCTExport';
10063
import * as TurboModuleRegistry from '../TurboModuleRegistry';
10164
10265
export interface Spec extends TurboModule {
103-
+getBool: (arg: boolean) => boolean;
104-
+getNumber: (arg: number) => number;
105-
+getString: (arg: string) => string;
66+
readonly getBool: (arg: boolean) => boolean;
67+
readonly getNumber: (arg: number) => number;
68+
readonly getString: (arg: string) => string;
10669
sampleBool: boolean,
10770
10871
}
@@ -118,22 +81,17 @@ const NATIVE_MODULES_WITH_UNNAMED_PARAMS = `
11881
* This source code is licensed under the MIT license found in the
11982
* LICENSE file in the root directory of this source tree.
12083
*
121-
* @flow strict-local
12284
* @format
12385
*/
12486
125-
'use strict';
126-
127-
import type {TurboModule} from '../RCTExport';
128-
import * as TurboModuleRegistry from '../TurboModuleRegistry';
87+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
88+
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';
12989
13090
export interface Spec extends TurboModule {
131-
+getBool: (boolean) => boolean;
132-
91+
readonly getBool: (boolean) => boolean;
13392
}
13493
13594
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
136-
13795
`;
13896

13997
const NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE = `
@@ -143,17 +101,14 @@ const NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE = `
143101
* This source code is licensed under the MIT license found in the
144102
* LICENSE file in the root directory of this source tree.
145103
*
146-
* @flow strict-local
147104
* @format
148105
*/
149106
150-
'use strict';
151-
152107
import type {TurboModule} from '../RCTExport';
153108
import * as TurboModuleRegistry from '../TurboModuleRegistry';
154109
155110
export interface Spec extends TurboModule {
156-
+getBool: (arg: boolean) => Promise;
111+
readonly getBool: (arg: boolean) => Promise;
157112
158113
}
159114
@@ -168,19 +123,14 @@ const TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT = `
168123
* This source code is licensed under the MIT license found in the
169124
* LICENSE file in the root directory of this source tree.
170125
*
171-
* @flow strict-local
172126
* @format
173127
*/
174128
175-
'use strict';
176-
177129
import type {TurboModule} from '../RCTExport';
178130
import * as TurboModuleRegistry from '../TurboModuleRegistry';
179131
180-
181132
export default TurboModuleRegistry.getEnforcing<Spec1>('SampleTurboModule1');
182133
export default TurboModuleRegistry.getEnforcing<Spec2>('SampleTurboModule2');
183-
184134
`;
185135

186136
const TWO_NATIVE_EXTENDING_TURBO_MODULE = `
@@ -190,28 +140,22 @@ const TWO_NATIVE_EXTENDING_TURBO_MODULE = `
190140
* This source code is licensed under the MIT license found in the
191141
* LICENSE file in the root directory of this source tree.
192142
*
193-
* @flow strict-local
194143
* @format
195144
*/
196145
197-
'use strict';
198-
199146
import type {TurboModule} from '../RCTExport';
200147
import * as TurboModuleRegistry from '../TurboModuleRegistry';
201148
202149
export interface Spec extends TurboModule {
203-
+getSth: (a : ?number) => void
150+
readonly getSth: (a: number | null | void) => void;
204151
}
205152
206153
export interface Spec2 extends TurboModule {
207-
+getSth: (a : ?number) => void
154+
readonly getSth: (a: number | null | void) => void;
208155
}
209-
210-
211156
`;
212157

213158
module.exports = {
214-
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
215159
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
216160
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
217161
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM,

0 commit comments

Comments
 (0)