Skip to content

Commit 6e652f7

Browse files
Merge pull request #396 from salesforcecli/wr/sf2suggestion
fix: add doctor test for sf1/sfdx7 and suggest uninstall
2 parents 0b34448 + 6c94c68 commit 6e652f7

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

messages/diagnostics.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ The salesforcedx plugin is deprecated. Uninstall it by running: `%s plugins:unin
1414
# linkedPluginWarning
1515

1616
Warning: the [%s] plugin is linked.
17+
18+
# uninstallSuggestion
19+
20+
Uninstall the deprecated Salesforce CLI (%s) version %s and install the @salesforce/cli version 2. See https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_uninstall.htm for uninstall instructions.

src/diagnostics.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ export class Diagnostics {
8989
});
9090
}
9191

92+
/**
93+
* Checks to see if the cli is outdated and deprecated (sfdx7 sf1)
94+
*/
95+
public async deprecatedCliCheck(): Promise<void> {
96+
const cliName = this.config.name;
97+
const cliVersion = this.config.version;
98+
99+
if (cliName === 'sfdx-cli' && cliVersion.startsWith('7.')) {
100+
await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: 'using sfdx-cli version 7', status: 'fail' });
101+
this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion]));
102+
}
103+
104+
if (cliName === '@salesforce/cli' && cliVersion.startsWith('1.')) {
105+
await Lifecycle.getInstance().emit('Doctor:diagnostic', {
106+
testName: 'using @salesforce/cli version 1',
107+
status: 'fail',
108+
});
109+
this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion]));
110+
}
111+
}
112+
92113
/**
93114
* Checks if the salesforcedx plugin is installed and suggests
94115
* to uninstall it if there.

test/diagnostics.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('Diagnostics', () => {
8686
const results = diagnostics.run();
8787

8888
// This will have to be updated with each new test
89-
expect(results.length).to.equal(3);
89+
expect(results.length).to.equal(4);
9090
expect(childProcessExecStub.called).to.be.true;
9191
expect(lifecycleEmitSpy.called).to.be.true;
9292
expect(lifecycleEmitSpy.args[0][0]).to.equal('Doctor:diagnostic');
@@ -204,6 +204,46 @@ describe('Diagnostics', () => {
204204
});
205205
});
206206
});
207+
describe('deprecatedCliCheck', () => {
208+
it('fails when sfdx 7 installed', async () => {
209+
const dr = Doctor.init(oclifConfig);
210+
const diagnostics = new Diagnostics(dr, oclifConfig);
211+
await diagnostics.deprecatedCliCheck();
212+
213+
expect(drAddSuggestionSpy.called).to.be.true;
214+
expect(lifecycleEmitSpy.called).to.be.true;
215+
expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({
216+
testName: 'using sfdx-cli version 7',
217+
status: 'fail',
218+
});
219+
});
220+
221+
it('fails when sf 1 installed', async () => {
222+
oclifConfig.name = '@salesforce/cli';
223+
oclifConfig.version = '1.0.0';
224+
const dr = Doctor.init(oclifConfig);
225+
const diagnostics = new Diagnostics(dr, oclifConfig);
226+
await diagnostics.deprecatedCliCheck();
227+
228+
expect(drAddSuggestionSpy.called).to.be.true;
229+
expect(lifecycleEmitSpy.called).to.be.true;
230+
expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({
231+
testName: 'using @salesforce/cli version 1',
232+
status: 'fail',
233+
});
234+
});
235+
236+
it('passes when sf 2 is installed', async () => {
237+
oclifConfig.name = '@salesforce/cli';
238+
oclifConfig.version = '2.0.0';
239+
const dr = Doctor.init(oclifConfig);
240+
const diagnostics = new Diagnostics(dr, oclifConfig);
241+
await diagnostics.deprecatedCliCheck();
242+
243+
expect(drAddSuggestionSpy.called).to.be.false;
244+
expect(lifecycleEmitSpy.called).to.be.false;
245+
});
246+
});
207247

208248
describe('linkedPluginCheck', () => {
209249
it('passes when linked plugin not found', async () => {

0 commit comments

Comments
 (0)