Files
react-native/packages/react-native-codegen/src/__tests__/SchemaValidator-test.js
T
Michał OsadnikandFacebook Github Bot 96318e438f Split component generator and module generator into separated dirs
Summary: Code generators for modules and components don't have a lot of in common so there's no point to keepo them in the same directory and mix their files.

Reviewed By: rickhanlonii

Differential Revision: D16183434

fbshipit-source-id: b6ee32c6b223e8d6e4bc843b2e111598bee94dc5
2019-07-11 12:58:10 -07:00

80 lines
1.9 KiB
JavaScript

/**
* 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 fixtures = require('../generators/components/__test_fixtures__/fixtures.js');
const schemaValidator = require('../SchemaValidator.js');
import type {SchemaType} from '../CodegenSchema.js';
const simpleProp = {
name: 'disabled',
optional: true,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
default: false,
},
};
describe('SchemaValidator', () => {
it('fails on components across modules with same name', () => {
const fixture: SchemaType = {
modules: {
Module1: {
components: {
Component1: {
extendsProps: [
{
type: 'ReactNativeBuiltInType',
knownTypeName: 'ReactNativeCoreViewProps',
},
],
events: [],
props: [simpleProp],
commands: [],
},
},
},
Module2: {
components: {
Component1: {
extendsProps: [
{
type: 'ReactNativeBuiltInType',
knownTypeName: 'ReactNativeCoreViewProps',
},
],
events: [],
props: [simpleProp],
commands: [],
},
},
},
},
};
expect(schemaValidator.getErrors(fixture)).toMatchSnapshot();
});
describe('fixture', () => {
Object.keys(fixtures)
.sort()
.forEach(fixtureName => {
const fixture = fixtures[fixtureName];
it(`${fixtureName} has no errors`, () => {
expect(schemaValidator.getErrors(fixture)).toHaveLength(0);
});
});
});
});