Skip to content

Commit 737ce36

Browse files
ZihanChen-MSFTfacebook-github-bot
authored andcommitted
Ensure equivalent Flow and TypeScript turbo module definition generates the same output (#34620)
Summary: Pull request #34251 only partially worked because I didn't notice that there is ` 1` after the snapshot name. In this change I fixed the issue and find out there is one case that Flow and TypeScript parser generate different result. It is expected since the test inputs are different. TypeScript removes one member because there is no `{...X, ...}` type in TypeScript. We could make the codegen support intersection type and rewrite it to `X & {...}`, but this will not be included here anyway. ## Changelog [General] [Changed] - codegen: ensure equivalent Flow and TypeScript TM definition generates the same output Pull Request resolved: #34620 Test Plan: `yarn jest` passed in `packages/react-native-codegen` Reviewed By: NickGerleman Differential Revision: D39321965 Pulled By: cipolleschi fbshipit-source-id: aec60f5c9c18323cbd833bf5705af544d7db2e73
1 parent 5cb02ee commit 737ce36

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,19 @@ const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');
1414

1515
const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js');
1616
const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap');
17+
const flowExtraCases = [];
1718
const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js');
1819
const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap');
1920
const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'];
21+
const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS'];
2022

21-
compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases);
23+
compareSnaps(
24+
flowFixtures,
25+
flowSnaps,
26+
flowExtraCases,
27+
tsFixtures,
28+
tsSnaps,
29+
tsExtraCases,
30+
ignoredCases,
31+
);
2232
compareTsArraySnaps(tsSnaps, tsExtraCases);

packages/react-native-codegen/src/parsers/consistency/__tests__/checkModuleSnaps-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');
1414

1515
const flowFixtures = require('../../flow/modules/__test_fixtures__/fixtures.js');
1616
const flowSnaps = require('../../../../src/parsers/flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap');
17+
const flowExtraCases = [];
1718
const tsFixtures = require('../../typescript/modules/__test_fixtures__/fixtures.js');
1819
const tsSnaps = require('../../../../src/parsers/typescript/modules/__tests__/__snapshots__/typescript-module-parser-snapshot-test.js.snap');
1920
const tsExtraCases = [
@@ -22,6 +23,15 @@ const tsExtraCases = [
2223
'NATIVE_MODULE_WITH_BASIC_ARRAY2',
2324
'NATIVE_MODULE_WITH_COMPLEX_ARRAY2',
2425
];
26+
const ignoredCases = [];
2527

26-
compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases);
28+
compareSnaps(
29+
flowFixtures,
30+
flowSnaps,
31+
flowExtraCases,
32+
tsFixtures,
33+
tsSnaps,
34+
tsExtraCases,
35+
ignoredCases,
36+
);
2737
compareTsArraySnaps(tsSnaps, tsExtraCases);

packages/react-native-codegen/src/parsers/consistency/compareSnaps.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function compareSnaps(
1717
tsFixtures,
1818
tsSnaps,
1919
tsExtraCases,
20+
ignoredCases,
2021
) {
2122
const flowCases = Object.keys(flowFixtures).sort();
2223
const tsCases = Object.keys(tsFixtures).sort();
@@ -36,17 +37,32 @@ function compareSnaps(
3637
});
3738

3839
for (const commonCase of commonCases) {
39-
it(`should generate the same snap from Flow and TypeScript for fixture ${commonCase}`, () => {
40-
expect(
41-
flowSnaps[
42-
`RN Codegen Flow Parser can generate fixture ${commonCase}`
43-
],
44-
).toEqual(
45-
tsSnaps[
46-
`RN Codegen TypeScript Parser can generate fixture ${commonCase}`
47-
],
48-
);
40+
const flowSnap =
41+
flowSnaps[
42+
`RN Codegen Flow Parser can generate fixture ${commonCase} 1`
43+
];
44+
const tsSnap =
45+
tsSnaps[
46+
`RN Codegen TypeScript Parser can generate fixture ${commonCase} 1`
47+
];
48+
49+
it(`should be able to find the snapshot for Flow for case ${commonCase}`, () => {
50+
expect(typeof flowSnap).toEqual('string');
4951
});
52+
53+
it(`should be able to find the snapshot for TypeScript for case ${commonCase}`, () => {
54+
expect(typeof tsSnap).toEqual('string');
55+
});
56+
57+
if (ignoredCases.indexOf(commonCase) === -1) {
58+
it(`should generate the same snapshot from Flow and TypeScript for fixture ${commonCase}`, () => {
59+
expect(flowSnap).toEqual(tsSnap);
60+
});
61+
} else {
62+
it(`should generate the different snapshot from Flow and TypeScript for fixture ${commonCase}`, () => {
63+
expect(flowSnap).not.toEqual(tsSnap);
64+
});
65+
}
5066
}
5167
});
5268
}

0 commit comments

Comments
 (0)