Files
react-native/scripts/releases/__tests__/set-rn-version-test.js
T
Blake Friedman bc1735f014 test_android_template → test_android_helloworld but disabled until template is removed (#44908)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44908

Changelog: [General] [Changed] - CircleCI test to Helloworld, but disabled for now until we remove the template

Reviewed By: cipolleschi

Differential Revision: D58469912

fbshipit-source-id: 718a774946bd70347697f18bbfc470b2897d2f87
2024-06-17 15:11:08 -07:00

93 lines
2.5 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 {setReactNativeVersion} = require('../set-rn-version');
const path = require('path');
describe('setReactNativeVersion', () => {
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/package.json')
) {
return JSON.stringify({
name: 'react-native',
version: '1000.0.0',
dependencies: {
'@react-native/package-a': '1000.0.0',
},
});
}
});
});
afterEach(() => {
writeFileMock.mockReset();
});
test('should set nightly version', async () => {
const version = '0.81.0-nightly-29282302-abcd1234';
const dependencyVersions = {
'@react-native/package-a': version,
};
await setReactNativeVersion(version, dependencyVersions, '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 setReactNativeVersion(version, null, '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 >>',
);
}