Files
react-native/scripts/releases/set-version/__tests__/set-version-test.js
T
Alex Hunt a4d6be8908 Update set-version to reuse set-rn-version (#43109)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43109

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D53940616

fbshipit-source-id: 8ce85437ab5164dae81a9956706c517880ee1f74
2024-02-20 05:06:03 -08:00

94 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
*/
const setVersion = require('../index');
const path = require('path');
jest.mock('../../../consts', () => ({
REPO_ROOT: path.join(__dirname, '__fixtures__'),
PACKAGES_DIR: path.join(__dirname, '__fixtures__', 'packages'),
REACT_NATIVE_PACKAGE_DIR: path.join(
__dirname,
'__fixtures__',
'packages',
'react-native',
),
}));
let customWriteFileExpect = null;
const writeFileMock = jest.fn().mockImplementation((filePath, content) => {
if (customWriteFileExpect != null) {
customWriteFileExpect(filePath, content);
}
expect(content).toMatchSnapshot(
// Make snapshot names resilient to platform path sep differences
path
.relative(path.join(__dirname, '__fixtures__'), filePath)
.split(path.sep)
.join('/'),
);
});
describe('setVersion', () => {
beforeEach(() => {
jest.clearAllMocks();
});
beforeAll(() => {
jest.mock('fs', () => {
// $FlowIgnore[underconstrained-implicit-instantiation]
const originalFs = jest.requireActual('fs');
return {
...originalFs,
writeFileSync: writeFileMock,
promises: {
...originalFs.promises,
writeFile: writeFileMock,
},
};
});
});
test('updates monorepo for release-candidate', async () => {
await setVersion('0.80.0-rc.3');
});
test('updates monorepo for stable version', async () => {
await setVersion('0.80.1');
});
test('updates monorepo for nightly', async () => {
await setVersion('0.81.0-nightly-29282302-abcd1234');
});
test('updates monorepo on main after release cut', async () => {
customWriteFileExpect = (filePath /*: string */, content /*: string */) => {
const reactNativePath = path.join('react-native', 'package.json');
if (filePath.endsWith(reactNativePath)) {
expect(JSON.parse(content).version).toBe('1000.0.0');
}
const templatePath = path.join(
'react-native',
'template',
'package.json',
);
if (filePath.endsWith(templatePath)) {
expect(JSON.parse(content).dependencies['react-native']).toBe(
'1000.0.0',
);
}
};
await setVersion('0.82.0-main', true);
});
});