Skip to content

Commit c70fbff

Browse files
committed
fix: incorrect condition for upgrade newer version check (#455)
1 parent a3c6f38 commit c70fbff

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

packages/cli/src/commands/upgrade/__tests__/upgrade.test.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ test('errors when older version passed', async () => {
145145
expect(logger.error).toBeCalledWith(
146146
`Trying to upgrade from newer version "${currentVersion}" to older "${olderVersion}"`,
147147
);
148+
await upgrade.func(['0.57.10'], ctx, opts);
149+
expect(logger.error).not.toBeCalledWith(
150+
`Trying to upgrade from newer version "${currentVersion}" to older "0.57.10"`,
151+
);
148152
});
149153

150154
test('warns when dependency upgrade version is in semver range', async () => {
@@ -170,12 +174,10 @@ success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the
170174
`);
171175
});
172176

173-
test(
174-
'fetches regular patch, adds remote, applies patch, installs deps, removes remote,',
175-
async () => {
176-
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
177-
await upgrade.func([newVersion], ctx, opts);
178-
expect(flushOutput()).toMatchInlineSnapshot(`
177+
test('fetches regular patch, adds remote, applies patch, installs deps, removes remote,', async () => {
178+
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
179+
await upgrade.func([newVersion], ctx, opts);
180+
expect(flushOutput()).toMatchInlineSnapshot(`
179181
"info Fetching diff between v0.57.8 and v0.58.4...
180182
[fs] write tmp-upgrade-rn.patch
181183
$ execa git rev-parse --show-prefix
@@ -194,22 +196,18 @@ info Running \\"git status\\" to check what changed...
194196
$ execa git status
195197
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
196198
`);
197-
expect(
198-
snapshotDiff(samplePatch, fs.writeFileSync.mock.calls[0][1], {
199-
contextLines: 1,
200-
}),
201-
).toMatchSnapshot('RnDiffApp is replaced with app name (TestApp)');
202-
},
203-
60000,
204-
);
205-
test(
206-
'fetches regular patch, adds remote, applies patch, installs deps, removes remote when updated from nested directory',
207-
async () => {
208-
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
209-
(execa: any).mockImplementation(mockExecaNested);
210-
const config = {...ctx, root: '/project/root/NestedApp'};
211-
await upgrade.func([newVersion], config, opts);
212-
expect(flushOutput()).toMatchInlineSnapshot(`
199+
expect(
200+
snapshotDiff(samplePatch, fs.writeFileSync.mock.calls[0][1], {
201+
contextLines: 1,
202+
}),
203+
).toMatchSnapshot('RnDiffApp is replaced with app name (TestApp)');
204+
}, 60000);
205+
test('fetches regular patch, adds remote, applies patch, installs deps, removes remote when updated from nested directory', async () => {
206+
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
207+
(execa: any).mockImplementation(mockExecaNested);
208+
const config = {...ctx, root: '/project/root/NestedApp'};
209+
await upgrade.func([newVersion], config, opts);
210+
expect(flushOutput()).toMatchInlineSnapshot(`
213211
"info Fetching diff between v0.57.8 and v0.58.4...
214212
[fs] write tmp-upgrade-rn.patch
215213
$ execa git rev-parse --show-prefix
@@ -228,9 +226,7 @@ info Running \\"git status\\" to check what changed...
228226
$ execa git status
229227
success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes"
230228
`);
231-
},
232-
60000,
233-
);
229+
}, 60000);
234230
test('cleans up if patching fails,', async () => {
235231
(fetch: any).mockImplementation(() => Promise.resolve(samplePatch));
236232
(execa: any).mockImplementation((command, args) => {

packages/cli/src/commands/upgrade/upgrade.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ const getVersionToUpgradeTo = async (argv, currentVersion, projectDir) => {
7878
return null;
7979
}
8080

81-
if (currentVersion > newVersion) {
81+
if (semver.gt(currentVersion, newVersion)) {
8282
logger.error(
8383
`Trying to upgrade from newer version "${currentVersion}" to older "${newVersion}"`,
8484
);
8585
return null;
8686
}
87-
if (currentVersion === newVersion) {
87+
if (semver.eq(currentVersion, newVersion)) {
8888
const {
8989
dependencies: {'react-native': version},
9090
} = require(path.join(projectDir, 'package.json'));

0 commit comments

Comments
 (0)