Skip to content
Open
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
29 changes: 29 additions & 0 deletions packages/react-native-babel-preset/src/__tests__/cache-key-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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.
*
* @format
* @noflow
*/

'use strict';

function getCacheKey(packageContents) {
jest.resetModules();
jest.doMock('node:fs', () => ({
readFileSync: filename =>
filename.endsWith('package.json')
? Buffer.from(packageContents)
: Buffer.from(filename),
}));

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"}'),
);
});
1 change: 1 addition & 0 deletions packages/react-native-babel-preset/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports.getCacheKey = () => {
const {readFileSync} = require('node:fs');
const key = createHash('md5');
[
readFileSync(require.resolve('../package.json')),
readFileSync(__filename),
readFileSync(require.resolve('./configs/main.js')),
readFileSync(require.resolve('./configs/hmr.js')),
Expand Down
Loading