mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 17:34:07 +08:00
Enable Schema everywhere
Summary: Change the codegen `srcs` to match any `**/*Schema.js` Reviewed By: TheSavior Differential Revision: D14401232 fbshipit-source-id: 61e60b1c9ca2f33efacc5caa1903b02a93cc644e
This commit is contained in:
committed by
Facebook Github Bot
parent
ed5ed23deb
commit
bcd259a355
@@ -35,14 +35,18 @@ jest.mock(
|
||||
{virtual: true},
|
||||
);
|
||||
|
||||
jest.mock('/test/module/NotASchema', () => ({}), {virtual: true});
|
||||
|
||||
test('should combine files', () => {
|
||||
const files = ['/test/module/SchemaOne', '/test/module/SchemaTwo'];
|
||||
const files = [
|
||||
'/test/module/SchemaOne',
|
||||
'/test/module/SchemaTwo',
|
||||
'/test/module/NotASchema',
|
||||
];
|
||||
expect(combine(files)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should throw for failed require', () => {
|
||||
test('should not throw for failed require', () => {
|
||||
const files = ['/test/module/does/not/exist'];
|
||||
expect(() => combine(files)).toThrow(
|
||||
"Can't require file at /test/module/does/not/exist",
|
||||
);
|
||||
expect(() => combine(files)).not.toThrow();
|
||||
});
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
'use strict';
|
||||
import type {SchemaType} from '../src/CodegenSchema.js';
|
||||
|
||||
function parse(filename: string): SchemaType {
|
||||
function parse(filename: string): ?SchemaType {
|
||||
try {
|
||||
// $FlowFixMe Can't require dynamic variables
|
||||
return require(filename);
|
||||
} catch (err) {
|
||||
throw new Error(`Can't require file at ${filename} ${err}`);
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ function combineSchemas(files: Array<string>): SchemaType {
|
||||
return files.reduce(
|
||||
(merged, filename) => {
|
||||
const schema = parse(filename);
|
||||
merged.modules = {...merged.modules, ...schema.modules};
|
||||
if (schema && schema.modules) {
|
||||
merged.modules = {...merged.modules, ...schema.modules};
|
||||
}
|
||||
return merged;
|
||||
},
|
||||
{modules: {}},
|
||||
|
||||
Reference in New Issue
Block a user