Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): bump @oclif/core from 3.25.2 to 3.26.0 #689

Merged
merged 2 commits into from
Apr 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@inquirer/input": "^2.1.0",
"@oclif/core": "^3.23.0",
"@oclif/core": "^3.26.0",
"@salesforce/core": "^6.7.1",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^8.0.1",
Expand Down
8 changes: 6 additions & 2 deletions src/commands/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
const hasDoctorHook = plugin.hooks && Object.keys(plugin.hooks).some((hook) => hook === eventName);
if (hasDoctorHook) {
this.styledHeader(`Running diagnostics for plugin: ${flags.plugin}`);
this.tasks.push(this.config.runHook(eventName, { doctor: this.doctor }));
this.tasks.push(this.runDoctorHook(eventName));
} else {
this.log(`${flags.plugin} doesn't have diagnostic tests to run.`);
}
Expand All @@ -94,7 +94,7 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
this.config.getPluginsList().forEach((plugin) => {
const eventName = `sf-doctor-${plugin.name}`;
if (plugin.hooks && Object.keys(plugin.hooks).find((hook) => hook === eventName)) {
this.tasks.push(this.config.runHook(eventName, { doctor: this.doctor }));
this.tasks.push(this.runDoctorHook(eventName));
}
});
this.doctor.diagnose().map((p) => this.tasks.push(p));
Expand Down Expand Up @@ -137,6 +137,10 @@ export default class Doctor extends SfCommand<SfDoctorDiagnosis> {
return diagnosis;
}

private runDoctorHook(event: string): Promise<unknown> {
return this.config.runHook(event, { doctor: this.doctor });
}

/**
* Only made into its own method for unit testing purposes
*
Expand Down
156 changes: 73 additions & 83 deletions test/commands/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import childProcess from 'node:child_process';
import fs from 'node:fs';
import Sinon from 'sinon';
import { expect } from 'chai';
import { stubMethod } from '@salesforce/ts-sinon';
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { Lifecycle, Messages } from '@salesforce/core';
import { Config, Interfaces } from '@oclif/core';
import { SfCommand } from '@salesforce/sf-plugins-core';
import DoctorCmd from '../../src/commands/doctor.js';
import { Diagnostics, DiagnosticStatus, Doctor, SfDoctorDiagnosis } from '../../src/index.js';
import { Diagnostics, Doctor, SfDoctorDiagnosis } from '../../src/index.js';
import { formatPlugins } from '../../src/doctor.js';
import { prompts } from '../../src/shared/prompts.js';

Expand Down Expand Up @@ -81,57 +81,67 @@ describe('Doctor Command', () => {
let childProcessExecStub: sinon.SinonStub;
let promptStub: sinon.SinonStub;
let openStub: sinon.SinonStub;
let runHookStub: sinon.SinonStub;

oclifConfig = {
runHook: sandbox.stub(),
const plugins = [
{
name: '@salesforce/plugin-org',
hooks: { 'sf-doctor-@salesforce/plugin-org': ['./lib/hooks/diagnostics'] },
},
{
name: '@salesforce/plugin-source',
hooks: { 'sf-doctor-@salesforce/plugin-source': ['./lib/hooks/diagnostics'] },
},
{
name: 'salesforce-alm',
hooks: {},
},
{
name: '@salesforce/plugin-data',
hooks: {},
},
].map((p) => ({
...p,
commands: [],
topics: [],
pjson: {
engines: {
node: 'node-v16.17.0',
name: p.name,
oclif: {
hooks: p.hooks,
},
oclif: {},
},
plugins: [
{
name: '@salesforce/plugin-org',
hooks: { 'sf-doctor-@salesforce/plugin-org': './lib/hooks/diagnostics' },
},
{
name: '@salesforce/plugin-source',
hooks: { 'sf-doctor-@salesforce/plugin-source': './lib/hooks/diagnostics' },
},
{
name: 'salesforce-alm',
},
{
name: '@salesforce/plugin-data',
}));

oclifConfig = fromStub(
stubInterface<Config>(sandbox, {
runHook: async () => ({
successes: [],
failures: [],
}),
pjson: {
engines: {
node: 'node-v16.17.0',
},
oclif: {},
},
],
getPluginsList: () => oclifConfig.plugins,
bin: 'sfdx',
versionDetails: {},
} as unknown as Config;

// eslint-disable-next-line @typescript-eslint/unbound-method
const runHookStub = oclifConfig.runHook as sinon.SinonStub;

class TestDoctor extends DoctorCmd {
public async runIt() {
await this.init();
return this.run();
}
}
plugins: new Map(plugins.map((p) => [p.name, p])),
getPluginsList: () => plugins,
bin: 'sfdx',
versionDetails: getVersionDetailStub(),
})
);

const runDoctorCmd = async (params: string[]) => {
const cmd = new TestDoctor(params, oclifConfig);
const cmd = new DoctorCmd(params, oclifConfig);
uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log');
promptStub = sandbox.stub(prompts, 'titleInput').resolves('my new and crazy issue');
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// @ts-expect-error because private method
openStub = sandbox.stub(cmd, 'openUrl').resolves();

uxStyledHeaderStub = stubMethod(sandbox, SfCommand.prototype, 'styledHeader');

return cmd.runIt();
// @ts-expect-error because private method
runHookStub = sandbox.stub(DoctorCmd.prototype, 'runDoctorHook');
return cmd.run();
};

beforeEach(async () => {
Expand All @@ -146,7 +156,6 @@ describe('Doctor Command', () => {
stubMethod(sandbox, Doctor.prototype, 'createStderrWriteStream');
stubMethod(sandbox, Doctor.prototype, 'closeStdout');
stubMethod(sandbox, Doctor.prototype, 'closeStderr');
runHookStub.reset();
});

afterEach(() => {
Expand Down Expand Up @@ -186,10 +195,7 @@ describe('Doctor Command', () => {
it('runs doctor command with no flags', async () => {
const suggestion = 'work smarter, not faster';
fsExistsSyncStub.returns(true);
const versionDetail = getVersionDetailStub();
const diagnosticStatus: DiagnosticStatus = { testName: 'doctor test', status: 'pass' };
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
const diagnosticStatus = { testName: 'doctor test', status: 'pass' };
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => {
const dr = Doctor.getInstance();
Expand All @@ -215,18 +221,15 @@ describe('Doctor Command', () => {
expect(drWriteStderr.called).to.be.false;
expect(fsWriteFileSyncStub.calledOnce).to.be.true;
expect(runHookStub.calledTwice).to.be.true;
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args[1][0]).to.equal('sf-doctor-@salesforce/plugin-source');
expect(runHookStub.args[1][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([
['sf-doctor-@salesforce/plugin-org'],
['sf-doctor-@salesforce/plugin-source'],
]);
});

it('runs doctor command with outputdir flag (existing dir)', async () => {
const outputdir = path.resolve('foo', 'bar', 'test');
fsExistsSyncStub.returns(true);
const versionDetail = getVersionDetailStub();
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => [Promise.resolve()]);

Expand All @@ -247,18 +250,15 @@ describe('Doctor Command', () => {
expect(drWriteStdout.called).to.be.false;
expect(drWriteStderr.called).to.be.false;
expect(runHookStub.callCount, 'Expected runHooks to be called twice').to.equal(2);
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args[1][0]).to.equal('sf-doctor-@salesforce/plugin-source');
expect(runHookStub.args[1][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([
['sf-doctor-@salesforce/plugin-org'],
['sf-doctor-@salesforce/plugin-source'],
]);
});

it('runs doctor command with outputdir flag (non-existing dir)', async () => {
const outputdir = path.resolve('foo', 'bar', 'test');
fsExistsSyncStub.returns(false);
const versionDetail = getVersionDetailStub();
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => [Promise.resolve()]);

Expand All @@ -279,19 +279,16 @@ describe('Doctor Command', () => {
expect(drWriteStderr.called).to.be.false;
expect(fsWriteFileSyncStub.calledOnce).to.be.true;
expect(runHookStub.calledTwice).to.be.true;
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args[1][0]).to.equal('sf-doctor-@salesforce/plugin-source');
expect(runHookStub.args[1][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([
['sf-doctor-@salesforce/plugin-org'],
['sf-doctor-@salesforce/plugin-source'],
]);
});

it('runs doctor command with command flag (minimal)', async () => {
const cmd = 'force:org:list --all';
const expectedCmd = `${oclifConfig.bin} ${cmd} --dev-debug`;
fsExistsSyncStub.returns(true);
const versionDetail = getVersionDetailStub();
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => [Promise.resolve()]);
childProcessExecStub.callsFake((cmdString, opts, cb: () => void) => {
Expand All @@ -316,19 +313,16 @@ describe('Doctor Command', () => {
expect(drWriteStdout.called).to.be.true;
expect(drWriteStderr.called).to.be.true;
expect(runHookStub.calledTwice).to.be.true;
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args[1][0]).to.equal('sf-doctor-@salesforce/plugin-source');
expect(runHookStub.args[1][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([
['sf-doctor-@salesforce/plugin-org'],
['sf-doctor-@salesforce/plugin-source'],
]);
expect(result).to.have.property('commandName', expectedCmd);
});

it('runs doctor command with command flag (full)', async () => {
const cmd = `${oclifConfig.bin} force:org:list --all --dev-debug`;
fsExistsSyncStub.returns(true);
const versionDetail = getVersionDetailStub();
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => [Promise.resolve()]);
childProcessExecStub.callsFake((cmdString, opts, cb: () => void) => {
Expand All @@ -354,18 +348,15 @@ describe('Doctor Command', () => {
expect(drWriteStdout.called).to.be.true;
expect(drWriteStderr.called).to.be.true;
expect(runHookStub.calledTwice).to.be.true;
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args[1][0]).to.equal('sf-doctor-@salesforce/plugin-source');
expect(runHookStub.args[1][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([
['sf-doctor-@salesforce/plugin-org'],
['sf-doctor-@salesforce/plugin-source'],
]);
expect(result).to.have.property('commandName', cmd);
});

it('runs doctor command with plugin flag', async () => {
fsExistsSyncStub.returns(true);
const versionDetail = getVersionDetailStub();
// @ts-expect-error: stubbing a private property
oclifConfig.versionDetails = versionDetail;
Doctor.init(oclifConfig);
diagnosticsRunStub.callsFake(() => [Promise.resolve()]);

Expand All @@ -386,8 +377,7 @@ describe('Doctor Command', () => {
expect(drWriteStdout.called).to.be.false;
expect(drWriteStderr.called).to.be.false;
expect(runHookStub.calledOnce).to.be.true;
expect(runHookStub.args[0][0]).to.equal('sf-doctor-@salesforce/plugin-org');
expect(runHookStub.args[0][1]).to.deep.equal({ doctor: Doctor.getInstance() });
expect(runHookStub.args).to.deep.equal([['sf-doctor-@salesforce/plugin-org']]);
});

it('runs doctor command with plugin flag (no plugin tests)', async () => {
Expand Down
47 changes: 23 additions & 24 deletions test/commands/info/releasenotes/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,23 @@ describe('sfdx info:releasenotes:display', () => {
let parseReleaseNotesSpy: Sinon.SinonSpy;
let markedParserSpy: Sinon.SinonSpy;

const oclifConfigStub = fromStub(stubInterface<Config>(sandbox));

class TestDisplay extends Display {
public async runIt() {
await this.init();
return this.run();
}
}
const oclifConfigStub = fromStub(
stubInterface<Config>(sandbox, {
runHook: async () => ({
successes: [],
failures: [],
}),
bin: 'sfdx',
})
);

const runDisplayCmd = async (params: string[]) => {
oclifConfigStub.bin = 'sfdx';

const cmd = new TestDisplay(params, oclifConfigStub);
const cmd = new Display(params, oclifConfigStub);

uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log');
uxWarnStub = stubMethod(sandbox, SfCommand.prototype, 'warn');

return cmd.runIt();
return cmd.run();
};

beforeEach(() => {
Expand Down Expand Up @@ -261,6 +260,7 @@ describe('sfdx info:releasenotes:display', () => {
expect(json).to.deep.equal(expected);
});
});

describe('sf info:releasenotes:display', () => {
const sandbox = Sinon.createSandbox();

Expand All @@ -274,24 +274,23 @@ describe('sf info:releasenotes:display', () => {
let parseReleaseNotesSpy: Sinon.SinonSpy;
let markedParserSpy: Sinon.SinonSpy;

const oclifConfigStub = fromStub(stubInterface<Config>(sandbox));

class TestDisplay extends Display {
public async runIt() {
await this.init();
return this.run();
}
}
const oclifConfigStub = fromStub(
stubInterface<Config>(sandbox, {
runHook: async () => ({
successes: [],
failures: [],
}),
bin: 'sf',
})
);

const runDisplayCmd = async (params: string[]) => {
oclifConfigStub.bin = 'sf';

const cmd = new TestDisplay(params, oclifConfigStub);
const cmd = new Display(params, oclifConfigStub);

uxLogStub = stubMethod(sandbox, SfCommand.prototype, 'log');
uxWarnStub = stubMethod(sandbox, SfCommand.prototype, 'warn');

return cmd.runIt();
return cmd.run();
};

beforeEach(() => {
Expand Down
Loading
Loading