Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure equivalent Flow and TypeScript turbo module definition generates the same output #34620

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ 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 flowExtraCases = [];
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'];
const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS'];

compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases);
compareSnaps(
flowFixtures,
flowSnaps,
flowExtraCases,
tsFixtures,
tsSnaps,
tsExtraCases,
ignoredCases,
);
compareTsArraySnaps(tsSnaps, tsExtraCases);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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 flowExtraCases = [];
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 = [
Expand All @@ -22,6 +23,15 @@ const tsExtraCases = [
'NATIVE_MODULE_WITH_BASIC_ARRAY2',
'NATIVE_MODULE_WITH_COMPLEX_ARRAY2',
];
const ignoredCases = [];

compareSnaps(flowFixtures, flowSnaps, [], tsFixtures, tsSnaps, tsExtraCases);
compareSnaps(
flowFixtures,
flowSnaps,
flowExtraCases,
tsFixtures,
tsSnaps,
tsExtraCases,
ignoredCases,
);
compareTsArraySnaps(tsSnaps, tsExtraCases);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function compareSnaps(
tsFixtures,
tsSnaps,
tsExtraCases,
ignoredCases,
) {
const flowCases = Object.keys(flowFixtures).sort();
const tsCases = Object.keys(tsFixtures).sort();
Expand All @@ -36,17 +37,32 @@ function compareSnaps(
});

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}`
],
);
const flowSnap =
flowSnaps[
`RN Codegen Flow Parser can generate fixture ${commonCase} 1`
];
const tsSnap =
tsSnaps[
`RN Codegen TypeScript Parser can generate fixture ${commonCase} 1`
];

it(`should be able to find the snapshot for Flow for case ${commonCase}`, () => {
expect(typeof flowSnap).toEqual('string');
});

it(`should be able to find the snapshot for TypeScript for case ${commonCase}`, () => {
expect(typeof tsSnap).toEqual('string');
});

if (ignoredCases.indexOf(commonCase) === -1) {
it(`should generate the same snapshot from Flow and TypeScript for fixture ${commonCase}`, () => {
expect(flowSnap).toEqual(tsSnap);
});
} else {
it(`should generate the different snapshot from Flow and TypeScript for fixture ${commonCase}`, () => {
expect(flowSnap).not.toEqual(tsSnap);
});
}
}
});
}
Expand Down