Skip to content

Commit

Permalink
test: accurate async/await and tighter eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 6, 2023
1 parent b3f2c6c commit 653cb18
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 41 deletions.
8 changes: 0 additions & 8 deletions test/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@ module.exports = {
rules: {
// Allow assert style expressions. i.e. expect(true).to.be.true
'no-unused-expressions': 'off',

// It is common for tests to stub out method.

// Return types are defined by the source code. Allows for quick overwrites.
'@typescript-eslint/explicit-function-return-type': 'off',
// Mocked out the methods that shouldn't do anything in the tests.
'@typescript-eslint/no-empty-function': 'off',
// Easily return a promise in a mocked method.
'@typescript-eslint/require-await': 'off',

'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
},
};
8 changes: 4 additions & 4 deletions test/nut/legacy/sandbox.sandboxNut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ describe('Sandbox Orgs via legacy org:create', () => {
});
});

it('will create a sandbox, verify it can be opened, and then attempt to delete it', async () => {
it('will create a sandbox, verify it can be opened, and then attempt to delete it', () => {
let result: SandboxProcessObject | undefined;
try {
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => {
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) =>
// eslint-disable-next-line no-console
console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress);
});
Promise.resolve(console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress))
);
result = execCmd<SandboxProcessObject>(
// escaped, pending outcome W-12683861
// eslint-disable-next-line sf-plugin/no-execcmd-double-quotes
Expand Down
6 changes: 3 additions & 3 deletions test/nut/legacy/status.sandboxNut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('test sandbox status command', () => {
logoutSandbox(hubOrgUsername);
});

it('sandbox status command', async () => {
it('sandbox status command', () => {
const orgStatusResult = execCmd<SandboxProcessObject>(
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} --json`,
{
Expand All @@ -91,7 +91,7 @@ describe('test sandbox status command', () => {
]);
});

it('sandbox status command sets setdefaultusername', async () => {
it('sandbox status command sets setdefaultusername', () => {
const orgStatusResult = execCmd<SandboxProcessObject>(
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} -s --json`,
{
Expand All @@ -107,7 +107,7 @@ describe('test sandbox status command', () => {
expect(result.stdout).to.contain(`"${hubOrgUsername}.${sandboxName.toLowerCase()}"`);
});

it('sandbox status command set alias', async () => {
it('sandbox status command set alias', () => {
const orgStatusResult = execCmd<SandboxProcessObject>(
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} -a ${sandboxName} --json`,
{
Expand Down
8 changes: 4 additions & 4 deletions test/nut/sandbox.sandboxNut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ describe('Sandbox Orgs', () => {
hubOrgUsername = session.hubOrg.username;
});

it('will create a sandbox, verify it can be opened, and then attempt to delete it', async () => {
it('will create a sandbox, verify it can be opened, and then attempt to delete it', () => {
let result: SandboxProcessObject | undefined;
try {
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => {
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) =>
// eslint-disable-next-line no-console
console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress);
});
Promise.resolve(console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress))
);
let rawResult = execCmd(
`env:create:sandbox -a mySandbox -s -l Developer -o ${hubOrgUsername} --no-prompt --json --async`,
{ timeout: 3600000 }
Expand Down
4 changes: 2 additions & 2 deletions test/shared/orgListUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('orgListUtil tests', () => {
sandbox.stub(utils, 'getAliasByUsername').withArgs('[email protected]').resolves('gaz');
});

afterEach(async () => {
afterEach(() => {
sandbox.restore();
});

Expand Down Expand Up @@ -221,7 +221,7 @@ describe('orgListUtil tests', () => {
stubMethod(sandbox, fs, 'readdir').resolves(['00D000000000000001.json', '00D000000000000002.json']);
});

afterEach(async () => {
afterEach(() => {
sandbox.restore();
});

Expand Down
4 changes: 2 additions & 2 deletions test/shared/sandboxProgress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('sandbox progress', () => {
sandboxProgress = new SandboxProgress();
});
describe('getSandboxProgress', () => {
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', async () => {
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', () => {
const data: StatusEvent = {
// 186*30 = 5580 = 1 hour, 33 min, 0 seconds. so 186 attempts left, at a 30 second polling interval
sandboxProcessObj,
Expand All @@ -45,7 +45,7 @@ describe('sandbox progress', () => {
expect(res).to.have.property('remainingWaitTimeHuman', '01:33:00 until timeout.');
});

it('will calculate the correct human readable message (5 min 30seconds seconds left)', async () => {
it('will calculate the correct human readable message (5 min 30seconds seconds left)', () => {
const data: StatusEvent = {
sandboxProcessObj,
interval: 30,
Expand Down
4 changes: 2 additions & 2 deletions test/shared/sandboxReporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sandboxProcessObj: SandboxProcessObject = {

describe('sandboxReporter', () => {
describe('sandboxProgress', () => {
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', async () => {
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', () => {
const data = {
sandboxProcessObj,
interval: 30,
Expand All @@ -41,7 +41,7 @@ describe('sandboxReporter', () => {
);
});

it('will calculate the correct human readable message (5 min 30seconds seconds left)', async () => {
it('will calculate the correct human readable message (5 min 30seconds seconds left)', () => {
const data: StatusEvent = {
sandboxProcessObj,
interval: 30,
Expand Down
2 changes: 1 addition & 1 deletion test/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getAliasByUsername } from '../../src/shared/utils';

describe('getAliasByUsername', () => {
const sandbox = sinon.createSandbox();
beforeEach(async () => {
beforeEach(() => {
const getAllStub = sandbox.stub();
getAllStub.withArgs('username1').returns(['alias1']);
getAllStub.withArgs('username2').returns(['alias2', 'alias2b']);
Expand Down
1 change: 1 addition & 0 deletions test/unit/force/org/sandboxCreate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ describe('org:create (sandbox paths)', () => {
expect(result).to.deep.equal(data);
const logs = $$.TEST_LOGGER.getBufferedRecords();
expect(logs.some((line) => line.msg.includes('Set defaultUsername:')));
return Promise.resolve();
});

const sandboxRes: SandboxUserAuthResponse = {
Expand Down
7 changes: 5 additions & 2 deletions test/unit/org/createSandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ const fakeOrg: AuthFields = {

describe('org:create:sandbox', () => {
beforeEach(() => {
stubMethod(sandbox, OrgAccessor.prototype, 'read').callsFake(async (): Promise<AuthFields> => fakeOrg);
stubMethod(sandbox, OrgAccessor.prototype, 'write').callsFake(async (): Promise<AuthFields> => fakeOrg);
// stubMethod(sandbox, OrgAccessor.prototype, 'read').callsFake(async (): Promise<AuthFields> => fakeOrg);
// stubMethod(sandbox, OrgAccessor.prototype, 'write').callsFake(async (): Promise<AuthFields> => fakeOrg);
stubMethod(sandbox, OrgAccessor.prototype, 'read').resolves(fakeOrg);
stubMethod(sandbox, OrgAccessor.prototype, 'write').resolves(fakeOrg);
sfCommandUxStubs = stubSfCommandUx(sandbox);
stubUx(sandbox);
stubSpinner(sandbox);
Expand All @@ -63,6 +65,7 @@ describe('org:create:sandbox', () => {
Lifecycle.getInstance().on(SandboxEvents.EVENT_ASYNC_RESULT, async (result) => {
expect(result).to.deep.equal(sandboxProcessObj);
expect(sfCommandUxStubs.info.firstCall.firstArg).to.include(sandboxProcessObj.Id);
return Promise.resolve();
});

await Lifecycle.getInstance().emit(SandboxEvents.EVENT_ASYNC_RESULT, sandboxProcessObj);
Expand Down
23 changes: 12 additions & 11 deletions test/unit/org/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,18 @@ describe('org:display', () => {
await $$.stubAuths(testOrg, testHub);

$$.SANDBOX.stub(Connection.prototype, 'sobject').returns({
// @ts-expect-error we all know this is not the full type
find: async () => [
{
Status: 'Active',
ExpirationDate: '2021-01-23',
CreatedBy: { Username: testHub.username },
Edition: 'Developer',
OrgName: 'MyOrg',
CreatedDate: '2020-12-24T15:18:55.000+0000',
},
],
find: async () =>
// @ts-expect-error we all know this is not the full type
Promise.resolve([
{
Status: 'Active',
ExpirationDate: '2021-01-23',
CreatedBy: { Username: testHub.username },
Edition: 'Developer',
OrgName: 'MyOrg',
CreatedDate: '2020-12-24T15:18:55.000+0000',
},
]),
});

const result = await OrgDisplayCommand.run(['--json', '--targetusername', testOrg.username]);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/org/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('org:list', () => {
// done automatically by the TestContext.
const $$ = new TestContext();

beforeEach(async () => {
beforeEach(() => {
// Stub the ux methods on SfCommand so that you don't get any command output in your tests.
stubSfCommandUx($$.SANDBOX);
stubMethod($$.SANDBOX, AuthInfo, 'listAllAuthorizations').resolves([
Expand All @@ -33,7 +33,7 @@ describe('org:list', () => {
});

describe('hub org defined', () => {
beforeEach(async () => {
beforeEach(() => {
stubMethod($$.SANDBOX, OrgListUtil, 'readLocallyValidatedMetaConfigsGroupedByOrgType').resolves(
OrgListMock.AUTH_INFO
);
Expand Down

0 comments on commit 653cb18

Please sign in to comment.