From 487443292d6a780b23ad691ee9ebe4618ac43a46 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 15 Sep 2026 13:11:12 -0700 Subject: [PATCH] Fix cache-key test on release branches Summary: `getCacheKey` only hashes package contents when the package version ends in `-main`; published releases short-circuit and return the version string. The test asserted only the main-build property, so it could never pass on a release branch, where two calls with different package contents both return the version. The test now asserts the property that actually holds for each case: differing keys on main builds, and the version string on published releases. This also adds coverage for the published-release path, which previously had none. Changelog: [Internal] Differential Revision: D120209439 --- .../src/__tests__/cache-key-test.js | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/react-native-babel-preset/src/__tests__/cache-key-test.js b/packages/react-native-babel-preset/src/__tests__/cache-key-test.js index a14ad66633c2..5c75fddbca42 100644 --- a/packages/react-native-babel-preset/src/__tests__/cache-key-test.js +++ b/packages/react-native-babel-preset/src/__tests__/cache-key-test.js @@ -22,8 +22,19 @@ function getCacheKey(packageContents) { return require('../index').getCacheKey(); } -test('cache key includes package metadata for main builds', () => { - expect(getCacheKey('{"dependency":"1.0.0"}')).not.toBe( - getCacheKey('{"dependency":"2.0.0"}'), - ); -}); +const {version: packageVersion} = require('../../package.json'); + +// Only `-main` versions hash package contents; published releases short-circuit +// to the version string, so each build asserts a different property. +if (packageVersion.endsWith('-main')) { + test('cache key includes package metadata for main builds', () => { + expect(getCacheKey('{"dependency":"1.0.0"}')).not.toBe( + getCacheKey('{"dependency":"2.0.0"}'), + ); + }); +} else { + test('cache key is the package version for published releases', () => { + expect(getCacheKey('{"dependency":"1.0.0"}')).toBe(packageVersion); + expect(getCacheKey('{"dependency":"2.0.0"}')).toBe(packageVersion); + }); +}