Skip to content

Commit

Permalink
fix: add doctor test for sf1/sfdx7 and suggest uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed May 3, 2023
1 parent 34db545 commit 593642a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
4 changes: 4 additions & 0 deletions messages/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ The salesforcedx plugin is deprecated. Uninstall it by running: `%s plugins:unin
# linkedPluginWarning

Warning: the [%s] plugin is linked.

# uninstallSuggestion

Please uninstall the 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.
4 changes: 2 additions & 2 deletions src/commands/info/releasenotes/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Display extends SfCommand<DisplayOutput | undefined> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');

public static aliases = ['whatsnew'];
public static readonly aliases = ['whatsnew'];

public static readonly examples = messages.getMessages('examples', [Display.helpers.join(', ')]);

Expand All @@ -57,7 +57,7 @@ export default class Display extends SfCommand<DisplayOutput | undefined> {
const { flags } = await this.parse(Display);
const env = new Env();

const isHook = !!flags.hook;
const isHook = flags.hook;

if (env.getBoolean(HIDE_NOTES) && isHook) {
// We don't ever want to exit the process for info:releasenotes:display (whatsnew)
Expand Down
21 changes: 21 additions & 0 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ export class Diagnostics {
});
}

/**
* Checks to see if the cli is outdated and deprecated (sfdx7 sf1)
*/
public async deprecatedCliCheck(): Promise<void> {
const cliName = this.config.name;
const cliVersion = this.config.version;

if (cliName === 'sfdx-cli' && cliVersion.startsWith('7.')) {
await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: 'using sfdx-cli version 7', status: 'fail' });
this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion]));
}

if (cliName === '@salesforce/cli' && cliVersion.startsWith('1.')) {
await Lifecycle.getInstance().emit('Doctor:diagnostic', {
testName: 'using @salesforce/cli version 1',
status: 'fail',
});
this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion]));
}
}

/**
* Checks if the salesforcedx plugin is installed and suggests
* to uninstall it if there.
Expand Down
42 changes: 41 additions & 1 deletion test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Diagnostics', () => {
const results = diagnostics.run();

// This will have to be updated with each new test
expect(results.length).to.equal(3);
expect(results.length).to.equal(4);
expect(childProcessExecStub.called).to.be.true;
expect(lifecycleEmitSpy.called).to.be.true;
expect(lifecycleEmitSpy.args[0][0]).to.equal('Doctor:diagnostic');
Expand Down Expand Up @@ -204,6 +204,46 @@ describe('Diagnostics', () => {
});
});
});
describe('deprecatedCliCheck', () => {
it('fails when sfdx 7 installed', async () => {
const dr = Doctor.init(oclifConfig);
const diagnostics = new Diagnostics(dr, oclifConfig);
await diagnostics.deprecatedCliCheck();

expect(drAddSuggestionSpy.called).to.be.true;
expect(lifecycleEmitSpy.called).to.be.true;
expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({
testName: 'using sfdx-cli version 7',
status: 'fail',
});
});

it('fails when sf 1 installed', async () => {
oclifConfig.name = '@salesforce/cli';
oclifConfig.version = '1.0.0';
const dr = Doctor.init(oclifConfig);
const diagnostics = new Diagnostics(dr, oclifConfig);
await diagnostics.deprecatedCliCheck();

expect(drAddSuggestionSpy.called).to.be.true;
expect(lifecycleEmitSpy.called).to.be.true;
expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({
testName: 'using @salesforce/cli version 1',
status: 'fail',
});
});

it('passes when sf 2 is installed', async () => {
oclifConfig.name = '@salesforce/cli';
oclifConfig.version = '2.0.0';
const dr = Doctor.init(oclifConfig);
const diagnostics = new Diagnostics(dr, oclifConfig);
await diagnostics.deprecatedCliCheck();

expect(drAddSuggestionSpy.called).to.be.false;
expect(lifecycleEmitSpy.called).to.be.false;
});
});

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

0 comments on commit 593642a

Please sign in to comment.