Skip to content
Closed
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
47 changes: 1 addition & 46 deletions scripts/__tests__/set-rn-version-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @format
*/

const execMock = jest.fn();
const echoMock = jest.fn();
const catMock = jest.fn();
const sedMock = jest.fn();
Expand All @@ -16,23 +15,15 @@ const updateTemplatePackageMock = jest.fn();

jest
.mock('shelljs', () => ({
exec: execMock,
echo: echoMock,
cat: catMock,
sed: sedMock,
}))
.mock('./../update-template-package', () => updateTemplatePackageMock)
.mock('./../scm-utils', () => ({
saveFiles: jest.fn(),
}))
.mock('path', () => ({
join: () => '../packages/react-native',
}))
.mock('fs', () => ({
writeFileSync: writeFileSyncMock,
mkdtempSync: () => './rn-set-version/',
}))
.mock('os');
}));

const setReactNativeVersion = require('../set-rn-version');

Expand All @@ -58,7 +49,6 @@ describe('set-rn-version', () => {
}
});

execMock.mockReturnValueOnce({stdout: 'line1\nline2\nline3\n'});
sedMock.mockReturnValueOnce({code: 0});

const version = '0.81.0-nightly-29282302-abcd1234';
Expand Down Expand Up @@ -115,7 +105,6 @@ describe('set-rn-version', () => {
return 'exports.version = {major: ${major}, minor: ${minor}, patch: ${patch}, prerelease: ${prerelease}}';
});

execMock.mockReturnValueOnce({stdout: 'line1\nline2\nline3\n'});
sedMock.mockReturnValueOnce({code: 0});

const version = '0.81.0';
Expand Down Expand Up @@ -144,39 +133,5 @@ describe('set-rn-version', () => {
expect(updateTemplatePackageMock).toHaveBeenCalledWith({
'react-native': version,
});
expect(execMock.mock.calls[0][0]).toBe(
`diff -r ./rn-set-version/ . | grep '^[>]' | grep -c ${version} `,
);
});

it('should fail validation', () => {
catMock.mockReturnValue('{}');

execMock.mockReturnValueOnce({stdout: 'line1\nline2\n'});
sedMock.mockReturnValueOnce({code: 0});
const filesToValidate = [
'packages/react-native/package.json',
'packages/react-native/ReactAndroid/gradle.properties',
'packages/react-native/template/package.json',
];

const version = '0.81.0';
setReactNativeVersion(version, null, 'release');

expect(echoMock).toHaveBeenNthCalledWith(
1,
'The tmp versioning folder is ./rn-set-version/',
);

expect(echoMock).toHaveBeenNthCalledWith(2, 'WARNING:');

expect(echoMock.mock.calls[2][0]).toBe(
`Failed to update all the files: [${filesToValidate.join(
', ',
)}] must have versions in them`,
);
expect(echoMock.mock.calls[3][0]).toBe(
`These files already had version ${version} set.`,
);
});
});
39 changes: 1 addition & 38 deletions scripts/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
'use strict';

const fs = require('fs');
const os = require('os');
const path = require('path');
const {cat, echo, exec, exit, sed} = require('shelljs');
const {cat, echo, exit, sed} = require('shelljs');
const yargs = require('yargs');
const {parseVersion, validateBuildType} = require('./version-utils');
const {saveFiles} = require('./scm-utils');
const updateTemplatePackage = require('./update-template-package');
const {applyPackageVersions} = require('./npm-utils');

Expand Down Expand Up @@ -152,18 +149,6 @@ function setReactNativeVersion(argVersion, dependencyVersions, buildType) {

const version = parseVersion(argVersion, buildType);

// Create tmp folder for copies of files to verify files have changed
const filesToValidate = [
'packages/react-native/package.json',
'packages/react-native/ReactAndroid/gradle.properties',
'packages/react-native/template/package.json',
];
const tmpVersioningFolder = fs.mkdtempSync(
path.join(os.tmpdir(), 'rn-set-version'),
);
echo(`The tmp versioning folder is ${tmpVersioningFolder}`);
saveFiles(tmpVersioningFolder);

setSource(version);
setPackage(version, dependencyVersions);

Expand All @@ -174,28 +159,6 @@ function setReactNativeVersion(argVersion, dependencyVersions, buildType) {
updateTemplatePackage(templateDependencyVersions);

setGradle(version);

// Validate changes
// We just do a git diff and check how many times version is added across files
const numberOfChangedLinesWithNewVersion = exec(
`diff -r ${tmpVersioningFolder} . | grep '^[>]' | grep -c ${version.version} `,
{silent: true},
).stdout.trim();

if (+numberOfChangedLinesWithNewVersion !== filesToValidate.length) {
// TODO: the logic that checks whether all the changes have been applied
// is missing several files. For example, it is not checking Ruby version nor that
// the Objecive-C files, the codegen and other files are properly updated.
// We are going to work on this in another PR.
echo('WARNING:');
echo(
`Failed to update all the files: [${filesToValidate.join(
', ',
)}] must have versions in them`,
);
echo(`These files already had version ${version.version} set.`);
}

return;
}

Expand Down