mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
5f60ad65ca
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45184 This is a follow-up to D59055522. > NOTE:This diff will be followed up by a merge of the set-rn-version script into set-version. (I had considered a rename to version-rn-artifacts, intentionally keeping this script separate and distinct from a future [lerna version + this script] setup — however the current UX and confusion with this naming would be too confusing. It can move into a util 👍🏻.) - Rename `set-rn-version` to `set-rn-artifacts-version` (more accurate). - Mark this script as deprecated. - For now, there are too many references to this script in CI test jobs to refactor away this entry point, so I am avoiding this — these should later be standardised to `set-version`. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D59058085 fbshipit-source-id: 4123ac73b5c7a2e07a1d1b6da61e0ad94fc31f84
79 lines
2.1 KiB
JavaScript
79 lines
2.1 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';
|
|
}
|
|
});
|
|
});
|
|
|
|
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 >>',
|
|
);
|
|
}
|