Skip to content

Commit ff3daf4

Browse files
committed
Cleanup
1 parent 73bbc55 commit ff3daf4

File tree

3 files changed

+29
-65
lines changed

3 files changed

+29
-65
lines changed

Diff for: packages/cursorless-vscode-e2e/src/suite/scopeProvider/assertCalledWithScopeInfo.ts

+11-38
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,38 @@ import { assert } from "chai";
44
import { sleepWithBackoff } from "../../endToEndTestSetup";
55
import { isEqual } from "lodash";
66

7-
async function sleepAndCheck<T>(
7+
export async function assertCalledWithScopeInfo<T extends ScopeTypeInfo>(
88
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
9-
check: () => void,
9+
...expectedScopeInfos: T[]
1010
) {
1111
await sleepWithBackoff(25);
1212
sinon.assert.called(fake);
1313

14-
check();
15-
16-
fake.resetHistory();
17-
}
18-
19-
export function assertCalled<T extends ScopeTypeInfo>(
20-
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
21-
expectedScopeInfos: T[],
22-
expectedNotToHaveScopeTypes: ScopeType[],
23-
) {
24-
return sleepAndCheck(fake, () => {
25-
assertCalledWith(expectedScopeInfos, fake);
26-
assertCalledWithout(expectedNotToHaveScopeTypes, fake);
27-
});
28-
}
29-
30-
export function assertCalledWithScopeInfo<T extends ScopeTypeInfo>(
31-
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
32-
...expectedScopeInfos: T[]
33-
) {
34-
return sleepAndCheck(fake, () => assertCalledWith(expectedScopeInfos, fake));
35-
}
36-
37-
export async function assertCalledWithoutScopeType<T extends ScopeTypeInfo>(
38-
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
39-
...scopeTypes: ScopeType[]
40-
) {
41-
return sleepAndCheck(fake, () => assertCalledWithout(scopeTypes, fake));
42-
}
43-
44-
function assertCalledWith<T extends ScopeTypeInfo>(
45-
expectedScopeInfos: T[],
46-
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
47-
) {
4814
for (const expectedScopeInfo of expectedScopeInfos) {
4915
const actualScopeInfo = fake.lastCall.args[0].find((scopeInfo) =>
5016
isEqual(scopeInfo.scopeType, expectedScopeInfo.scopeType),
5117
);
5218
assert.isDefined(actualScopeInfo);
5319
assert.deepEqual(actualScopeInfo, expectedScopeInfo);
5420
}
21+
22+
fake.resetHistory();
5523
}
5624

57-
function assertCalledWithout<T extends ScopeTypeInfo>(
58-
scopeTypes: ScopeType[],
25+
export async function assertCalledWithoutScopeInfo<T extends ScopeTypeInfo>(
5926
fake: sinon.SinonSpy<[scopeInfos: T[]], void>,
27+
...scopeTypes: ScopeType[]
6028
) {
29+
await sleepWithBackoff(25);
30+
sinon.assert.called(fake);
31+
6132
for (const scopeType of scopeTypes) {
6233
assert.isUndefined(
6334
fake.lastCall.args[0].find((scopeInfo) =>
6435
isEqual(scopeInfo.scopeType, scopeType),
6536
),
6637
);
6738
}
39+
40+
fake.resetHistory();
6841
}

Diff for: packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomRegexScopeInfoTest.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import * as sinon from "sinon";
1111
import {
1212
assertCalledWithScopeInfo,
13-
assertCalledWithoutScopeType as assertCalledWithoutScope,
13+
assertCalledWithoutScopeInfo,
1414
} from "./assertCalledWithScopeInfo";
1515
import { stat, unlink, writeFile } from "fs/promises";
1616
import { sleepWithBackoff } from "../../endToEndTestSetup";
@@ -30,7 +30,7 @@ export async function runCustomRegexScopeInfoTest() {
3030
const disposable = scopeProvider.onDidChangeScopeSupport(fake);
3131

3232
try {
33-
await assertCalledWithoutScope(fake, scopeType);
33+
await assertCalledWithoutScopeInfo(fake, scopeType);
3434

3535
await writeFile(
3636
spokenFormsJsonPath,
@@ -44,7 +44,7 @@ export async function runCustomRegexScopeInfoTest() {
4444

4545
await unlink(spokenFormsJsonPath);
4646
await sleepWithBackoff(50);
47-
await assertCalledWithoutScope(fake, scopeType);
47+
await assertCalledWithoutScopeInfo(fake, scopeType);
4848
} finally {
4949
disposable.dispose();
5050

Diff for: packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { getCursorlessApi } from "@cursorless/vscode-common";
22
import { LATEST_VERSION, ScopeTypeInfo, sleep } from "@cursorless/common";
33
import * as sinon from "sinon";
4-
import {
5-
assertCalled,
6-
assertCalledWithScopeInfo,
7-
} from "./assertCalledWithScopeInfo";
4+
import { assertCalledWithScopeInfo } from "./assertCalledWithScopeInfo";
85
import { stat, unlink, writeFile } from "fs/promises";
96
import { sleepWithBackoff } from "../../endToEndTestSetup";
107

@@ -19,17 +16,14 @@ export async function runCustomSpokenFormScopeInfoTest() {
1916
const disposable = scopeProvider.onDidChangeScopeInfo(fake);
2017

2118
try {
22-
await assertCalled(
19+
await assertCalledWithScopeInfo(
2320
fake,
24-
[
25-
roundStandard,
26-
namedFunctionStandard,
27-
lambdaStandard,
28-
statementStandard,
29-
squareStandard,
30-
subjectStandard,
31-
],
32-
[],
21+
roundStandard,
22+
namedFunctionStandard,
23+
lambdaStandard,
24+
statementStandard,
25+
squareStandard,
26+
subjectStandard,
3327
);
3428

3529
await writeFile(
@@ -49,17 +43,14 @@ export async function runCustomSpokenFormScopeInfoTest() {
4943

5044
await unlink(spokenFormsJsonPath);
5145
await sleepWithBackoff(50);
52-
await assertCalled(
46+
await assertCalledWithScopeInfo(
5347
fake,
54-
[
55-
roundStandard,
56-
namedFunctionStandard,
57-
lambdaStandard,
58-
statementStandard,
59-
squareStandard,
60-
subjectStandard,
61-
],
62-
[],
48+
roundStandard,
49+
namedFunctionStandard,
50+
lambdaStandard,
51+
statementStandard,
52+
squareStandard,
53+
subjectStandard,
6354
);
6455
} finally {
6556
disposable.dispose();

0 commit comments

Comments
 (0)