Skip to content

Commit dc681c7

Browse files
authored
Merge pull request #736 from salesforcecli/sm/ut-cleanup
test: accurate async/await and tighter eslint
2 parents b3f2c6c + 9c41622 commit dc681c7

14 files changed

+44
-47
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"devDependencies": {
1818
"@oclif/plugin-command-snapshot": "^4.0.6",
19-
"@salesforce/cli-plugins-testkit": "^4.1.1",
19+
"@salesforce/cli-plugins-testkit": "^4.2.0",
2020
"@salesforce/dev-config": "^4.0.1",
2121
"@salesforce/dev-scripts": "^5.4.2",
2222
"@salesforce/plugin-command-reference": "^3.0.7",
@@ -234,4 +234,4 @@
234234
"output": []
235235
}
236236
}
237-
}
237+
}

test/.eslintrc.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@ module.exports = {
1212
rules: {
1313
// Allow assert style expressions. i.e. expect(true).to.be.true
1414
'no-unused-expressions': 'off',
15-
16-
// It is common for tests to stub out method.
17-
1815
// Return types are defined by the source code. Allows for quick overwrites.
1916
'@typescript-eslint/explicit-function-return-type': 'off',
2017
// Mocked out the methods that shouldn't do anything in the tests.
2118
'@typescript-eslint/no-empty-function': 'off',
22-
// Easily return a promise in a mocked method.
23-
'@typescript-eslint/require-await': 'off',
24-
2519
'@typescript-eslint/no-unsafe-member-access': 'off',
26-
'@typescript-eslint/no-unsafe-return': 'off',
27-
'@typescript-eslint/no-unsafe-assignment': 'off',
2820
},
2921
};

test/nut/legacy/sandbox.sandboxNut.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ describe('Sandbox Orgs via legacy org:create', () => {
2424
});
2525
});
2626

27-
it('will create a sandbox, verify it can be opened, and then attempt to delete it', async () => {
27+
it('will create a sandbox, verify it can be opened, and then attempt to delete it', () => {
2828
let result: SandboxProcessObject | undefined;
2929
try {
30-
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => {
30+
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) =>
3131
// eslint-disable-next-line no-console
32-
console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress);
33-
});
32+
Promise.resolve(console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress))
33+
);
3434
result = execCmd<SandboxProcessObject>(
3535
// escaped, pending outcome W-12683861
3636
// eslint-disable-next-line sf-plugin/no-execcmd-double-quotes

test/nut/legacy/status.sandboxNut.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('test sandbox status command', () => {
6767
logoutSandbox(hubOrgUsername);
6868
});
6969

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

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

110-
it('sandbox status command set alias', async () => {
110+
it('sandbox status command set alias', () => {
111111
const orgStatusResult = execCmd<SandboxProcessObject>(
112112
`force:org:status --sandboxname ${sandboxName} -u ${hubOrgUsername} -a ${sandboxName} --json`,
113113
{

test/nut/sandbox.sandboxNut.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe('Sandbox Orgs', () => {
2525
hubOrgUsername = session.hubOrg.username;
2626
});
2727

28-
it('will create a sandbox, verify it can be opened, and then attempt to delete it', async () => {
28+
it('will create a sandbox, verify it can be opened, and then attempt to delete it', () => {
2929
let result: SandboxProcessObject | undefined;
3030
try {
31-
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) => {
31+
Lifecycle.getInstance().on(SandboxEvents.EVENT_STATUS, async (results: StatusEvent) =>
3232
// eslint-disable-next-line no-console
33-
console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress);
34-
});
33+
Promise.resolve(console.log('sandbox copy progress', results.sandboxProcessObj.CopyProgress))
34+
);
3535
let rawResult = execCmd(
3636
`env:create:sandbox -a mySandbox -s -l Developer -o ${hubOrgUsername} --no-prompt --json --async`,
3737
{ timeout: 3600000 }

test/shared/orgListUtil.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe('orgListUtil tests', () => {
123123
sandbox.stub(utils, 'getAliasByUsername').withArgs('[email protected]').resolves('gaz');
124124
});
125125

126-
afterEach(async () => {
126+
afterEach(() => {
127127
sandbox.restore();
128128
});
129129

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

224-
afterEach(async () => {
224+
afterEach(() => {
225225
sandbox.restore();
226226
});
227227

test/shared/sandboxProgress.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('sandbox progress', () => {
3030
sandboxProgress = new SandboxProgress();
3131
});
3232
describe('getSandboxProgress', () => {
33-
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', async () => {
33+
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', () => {
3434
const data: StatusEvent = {
3535
// 186*30 = 5580 = 1 hour, 33 min, 0 seconds. so 186 attempts left, at a 30 second polling interval
3636
sandboxProcessObj,
@@ -45,7 +45,7 @@ describe('sandbox progress', () => {
4545
expect(res).to.have.property('remainingWaitTimeHuman', '01:33:00 until timeout.');
4646
});
4747

48-
it('will calculate the correct human readable message (5 min 30seconds seconds left)', async () => {
48+
it('will calculate the correct human readable message (5 min 30seconds seconds left)', () => {
4949
const data: StatusEvent = {
5050
sandboxProcessObj,
5151
interval: 30,

test/shared/sandboxReporter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const sandboxProcessObj: SandboxProcessObject = {
2828

2929
describe('sandboxReporter', () => {
3030
describe('sandboxProgress', () => {
31-
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', async () => {
31+
it('will calculate the correct human readable message (1h 33min 00seconds seconds left)', () => {
3232
const data = {
3333
sandboxProcessObj,
3434
interval: 30,
@@ -41,7 +41,7 @@ describe('sandboxReporter', () => {
4141
);
4242
});
4343

44-
it('will calculate the correct human readable message (5 min 30seconds seconds left)', async () => {
44+
it('will calculate the correct human readable message (5 min 30seconds seconds left)', () => {
4545
const data: StatusEvent = {
4646
sandboxProcessObj,
4747
interval: 30,

test/shared/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { getAliasByUsername } from '../../src/shared/utils';
1212

1313
describe('getAliasByUsername', () => {
1414
const sandbox = sinon.createSandbox();
15-
beforeEach(async () => {
15+
beforeEach(() => {
1616
const getAllStub = sandbox.stub();
1717
getAllStub.withArgs('username1').returns(['alias1']);
1818
getAllStub.withArgs('username2').returns(['alias2', 'alias2b']);

test/unit/force/org/sandboxCreate.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ describe('org:create (sandbox paths)', () => {
141141
expect(result).to.deep.equal(data);
142142
const logs = $$.TEST_LOGGER.getBufferedRecords();
143143
expect(logs.some((line) => line.msg.includes('Set defaultUsername:')));
144+
return Promise.resolve();
144145
});
145146

146147
const sandboxRes: SandboxUserAuthResponse = {

0 commit comments

Comments
 (0)