Files
react-native/scripts/releases/__tests__/set-rn-artifacts-version-test.js
T
Riccardo Cipolleschi 130fb7fd30 Fix set-rn-version to account for codegen snapshot test files (#51157)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51157

test-js jobs are failing because the codegen snapshot tests generates a Podspecs withan hardcoded version that does not matches the version we are about to release.

This fix updates the script that set the RN version to make sure it also updates the Codegen snapshots.

This is a porting to `main` of [this PR](https://github.com/facebook/react-native/pull/51156).

## Changelog:
[Internal] - Fix set-rn-version to account for codegen snapshot test files

Reviewed By: fabriziocucci, cortinico

Differential Revision: D74321590

fbshipit-source-id: 6837e60a0a2834030680f7ec0c7584bf2622f33e
2025-05-07 07:18:45 -07:00

93 lines
2.4 KiB
JavaScript

/**
* 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.
*
* @flow
* @format
* @oncall react_native
*/
const readFileMock = jest.fn();
const writeFileMock = jest.fn();
jest.mock('fs', () => ({
...jest.requireActual<$FlowFixMe>('fs'),
promises: {
...jest.requireActual<$FlowFixMe>('fs').promises,
readFile: readFileMock,
writeFile: writeFileMock,
},
}));
const {REPO_ROOT} = require('../../consts');
const {updateReactNativeArtifacts} = require('../set-rn-artifacts-version');
const path = require('path');
describe('updateReactNativeArtifacts', () => {
beforeAll(() => {
readFileMock.mockImplementation(filePath => {
if (
filePath ===
path.join(
REPO_ROOT,
'packages/react-native/ReactAndroid/gradle.properties',
)
) {
return 'VERSION_NAME=1000.0.0\n';
}
if (
filePath ===
path.join(
REPO_ROOT,
'packages/react-native/scripts/codegen/__tests__/__snapshots__/generate-artifacts-executor-test.js.snap',
)
) {
return `
version = "1000.0.0\\
other text
version = "1000.0.0\\
`;
}
});
});
afterEach(() => {
writeFileMock.mockReset();
});
test('should set nightly version', async () => {
const version = '0.81.0-nightly-29282302-abcd1234';
await updateReactNativeArtifacts(version, 'nightly');
for (const [filePath, contents] of writeFileMock.mock.calls) {
// Make snapshot names resilient to platform path sep differences
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath).split(path.sep).join('/'),
);
}
});
test('should set release version', async () => {
const version = '0.81.0';
await updateReactNativeArtifacts(version, 'release');
for (const [filePath, contents] of writeFileMock.mock.calls) {
// Make snapshot names resilient to platform path sep differences
expect(formatGeneratedFile(contents)).toMatchSnapshot(
path.relative(REPO_ROOT, filePath).split(path.sep).join('/'),
);
}
});
});
function formatGeneratedFile(source: string) {
// Strip \@\generated annotation
return source.replace(
new RegExp('^ \\* @' + 'generated.*', 'gm'),
' * << GENERATED >>',
);
}