-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure equivalent Flow and TypeScript turbo module definition generat…
…es the same output (#34251) Summary: Flow and TypeScript are two very similar programming languages. They are both recognizable as inputs for turbo module codegen. It is reasonable to require equivalent Flow and TypeScript turbo module definition generates the same output. I add some test cases to ensure this. Glad that no functional inconsistency is found here. ## Changelog [General] [Changed] - codegen: ensure equivalent Flow and TypeScript TM definition generates the same output Pull Request resolved: #34251 Test Plan: `yarn jest` passed in `packages/react-native-codegen` Reviewed By: dmitryrykun Differential Revision: D38116756 Pulled By: cipolleschi fbshipit-source-id: 476adbd171a35813923f2020c826d21b1fc2eeed
- Loading branch information
1 parent
e441504
commit 0ce4ea2
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and 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 | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js'); | ||
|
||
const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js'); | ||
const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap'); | ||
const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js'); | ||
const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap'); | ||
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS']; | ||
|
||
compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases); | ||
compareTsArraySnaps(tsSnaps, tsExtraCases); |
27 changes: 27 additions & 0 deletions
27
packages/react-native-codegen/src/parsers/consistency/__tests__/checkModuleSnaps-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and 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 | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js'); | ||
|
||
const flowFixtures = require('../../flow/modules/__test_fixtures__/fixtures.js'); | ||
const flowSnaps = require('../../../../src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap'); | ||
const tsFixtures = require('../../typescript/modules/__test_fixtures__/fixtures.js'); | ||
const tsSnaps = require('../../../../src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap'); | ||
const tsExtraCases = [ | ||
'NATIVE_MODULE_WITH_ARRAY2_WITH_ALIAS', | ||
'NATIVE_MODULE_WITH_ARRAY2_WITH_UNION_AND_TOUPLE', | ||
'NATIVE_MODULE_WITH_BASIC_ARRAY2', | ||
'NATIVE_MODULE_WITH_COMPLEX_ARRAY2', | ||
]; | ||
|
||
compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases); | ||
compareTsArraySnaps(tsSnaps, tsExtraCases); |
76 changes: 76 additions & 0 deletions
76
packages/react-native-codegen/src/parsers/consistency/compareSnaps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and 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 | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function compareSnaps( | ||
flowFixtures, | ||
flowSnaps, | ||
flowExtraCases, | ||
tsFixtures, | ||
tsSnaps, | ||
tsExtraCases, | ||
) { | ||
const flowCases = Object.keys(flowFixtures).sort(); | ||
const tsCases = Object.keys(tsFixtures).sort(); | ||
const commonCases = flowCases.filter(name => tsCases.indexOf(name) !== -1); | ||
|
||
describe('RN Codegen Parsers', () => { | ||
it('should not unintentionally contains test case for Flow but not for TypeScript', () => { | ||
expect( | ||
flowCases.filter(name => commonCases.indexOf(name) === -1), | ||
).toEqual(flowExtraCases); | ||
}); | ||
|
||
it('should not unintentionally contains test case for TypeScript but not for Flow', () => { | ||
expect(tsCases.filter(name => commonCases.indexOf(name) === -1)).toEqual( | ||
tsExtraCases, | ||
); | ||
}); | ||
|
||
for (const commonCase of commonCases) { | ||
it(`should generate the same snap from Flow and TypeScript for fixture ${commonCase}`, () => { | ||
expect( | ||
flowSnaps[ | ||
`RN Codegen Flow Parser can generate fixture ${commonCase}` | ||
], | ||
).toEqual( | ||
tsSnaps[ | ||
`RN Codegen TypeScript Parser can generate fixture ${commonCase}` | ||
], | ||
); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function compareTsArraySnaps(tsSnaps, tsExtraCases) { | ||
for (const array2Case of tsExtraCases.filter( | ||
name => name.indexOf('ARRAY2') !== -1, | ||
)) { | ||
const arrayCase = array2Case.replace('ARRAY2', 'ARRAY'); | ||
it(`should generate the same snap from fixture ${arrayCase} and ${array2Case}`, () => { | ||
expect( | ||
tsSnaps[ | ||
`RN Codegen TypeScript Parser can generate fixture ${arrayCase}` | ||
], | ||
).toEqual( | ||
tsSnaps[ | ||
`RN Codegen TypeScript Parser can generate fixture ${array2Case}` | ||
], | ||
); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { | ||
compareSnaps, | ||
compareTsArraySnaps, | ||
}; |