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 #34251

Closed
wants to merge 15 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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
* @flow strict-local
* @format
*/

'use strict';

const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');

const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js');
const flowSnaps = require('../../flow/components/__tests__/__snapshots__/component-parser-test.js.snap');
const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js');
const tsSnaps = require('../../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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 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
* @flow strict-local
* @format
*/

'use strict';

const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js');

const flowFixtures = require('../../flow/modules/__test_fixtures__/fixtures.js');
const flowSnaps = require('../../flow/modules/__tests__/__snapshots__/module-parser-snapshot-test.js.snap');
const tsFixtures = require('../../typescript/modules/__test_fixtures__/fixtures.js');
const tsSnaps = require('../../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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* 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
* @flow strict-local
* @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,
};