Skip to content

Commit 6e862f9

Browse files
fabriziocuccimeta-codesync[bot]
authored andcommitted
Fix cache-key test on release branches (#58546)
Summary: Pull Request resolved: #58546 `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 fbshipit-source-id: 9ebe74bad70ffca7bc7eb8b61fa8020b56219e8f
1 parent 7a2963f commit 6e862f9

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎packages/react-native-babel-preset/src/__tests__/cache-key-test.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,19 @@ function getCacheKey(packageContents) {
2222
return require('../index').getCacheKey();
2323
}
2424

25-
test('cache key includes package metadata for main builds', () => {
26-
expect(getCacheKey('{"dependency":"1.0.0"}')).not.toBe(
27-
getCacheKey('{"dependency":"2.0.0"}'),
28-
);
29-
});
25+
const {version: packageVersion} = require('../../package.json');
26+
27+
// Only `-main` versions hash package contents; published releases short-circuit
28+
// to the version string, so each build asserts a different property.
29+
if (packageVersion.endsWith('-main')) {
30+
test('cache key includes package metadata for main builds', () => {
31+
expect(getCacheKey('{"dependency":"1.0.0"}')).not.toBe(
32+
getCacheKey('{"dependency":"2.0.0"}'),
33+
);
34+
});
35+
} else {
36+
test('cache key is the package version for published releases', () => {
37+
expect(getCacheKey('{"dependency":"1.0.0"}')).toBe(packageVersion);
38+
expect(getCacheKey('{"dependency":"2.0.0"}')).toBe(packageVersion);
39+
});
40+
}

0 commit comments

Comments
 (0)