From 7bb204a16030c8c50a5e686cbbf77d10b683f2ae Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Fri, 8 Mar 2024 08:53:49 -0800 Subject: [PATCH] Fix public-api-test "expected parse error" assertion (#43378) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43378 ## Overview I noticed while running this test, that there's an existing `console.error` to remove a file from the `FILES_WITH_KNOWN_ERRORS` list, but the tests pass despite the error. This happens because the `console.error` throws to fail the test, but this `console.error` is inside a try/catch, so the error is swallowed. This diff moves the check to a finally, which fails the test. I also fixed the `FILES_WITH_KNOWN_ERRORS` list. Changelog: [Internal] Reviewed By: yungsters Differential Revision: D54587062 fbshipit-source-id: c46e98326ef6654452871337364d7e66ff204e2c --- .../Libraries/__tests__/public-api-test.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/react-native/Libraries/__tests__/public-api-test.js b/packages/react-native/Libraries/__tests__/public-api-test.js index 6fcd7671d76..66ff7f27556 100644 --- a/packages/react-native/Libraries/__tests__/public-api-test.js +++ b/packages/react-native/Libraries/__tests__/public-api-test.js @@ -87,19 +87,22 @@ describe('public API', () => { return; } + let success = false; try { expect(await translateFlowToExportedAPI(source)).toMatchSnapshot(); - if (FILES_WITH_KNOWN_ERRORS.has(file)) { + success = true; + } catch (e) { + if (!FILES_WITH_KNOWN_ERRORS.has(file)) { + console.error('Unable to parse file:', file, '\n' + e); + } + } finally { + if (success && FILES_WITH_KNOWN_ERRORS.has(file)) { console.error( 'Expected parse error, please remove file exclude from FILES_WITH_KNOWN_ERRORS:', file, ); } - } catch (e) { - if (!FILES_WITH_KNOWN_ERRORS.has(file)) { - console.error('Unable to parse file:', file, '\n' + e); - } } } else { expect('UNTYPED MODULE').toMatchSnapshot();