From 357e57da2d64b87c51a56314adcc072c85c8fa91 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:46:31 +0100 Subject: [PATCH] Cleanup --- .../assertCalledWithScopeInfo.ts | 49 +++++-------------- .../runCustomRegexScopeInfoTest.ts | 6 +-- .../runCustomSpokenFormScopeInfoTest.ts | 39 ++++++--------- 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/assertCalledWithScopeInfo.ts b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/assertCalledWithScopeInfo.ts index b85850a282..0697298880 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/assertCalledWithScopeInfo.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/assertCalledWithScopeInfo.ts @@ -4,47 +4,13 @@ import { assert } from "chai"; import { sleepWithBackoff } from "../../endToEndTestSetup"; import { isEqual } from "lodash"; -async function sleepAndCheck( +export async function assertCalledWithScopeInfo( fake: sinon.SinonSpy<[scopeInfos: T[]], void>, - check: () => void, + ...expectedScopeInfos: T[] ) { await sleepWithBackoff(25); sinon.assert.called(fake); - check(); - - fake.resetHistory(); -} - -export function assertCalled( - fake: sinon.SinonSpy<[scopeInfos: T[]], void>, - expectedScopeInfos: T[], - expectedNotToHaveScopeTypes: ScopeType[], -) { - return sleepAndCheck(fake, () => { - assertCalledWith(expectedScopeInfos, fake); - assertCalledWithout(expectedNotToHaveScopeTypes, fake); - }); -} - -export function assertCalledWithScopeInfo( - fake: sinon.SinonSpy<[scopeInfos: T[]], void>, - ...expectedScopeInfos: T[] -) { - return sleepAndCheck(fake, () => assertCalledWith(expectedScopeInfos, fake)); -} - -export async function assertCalledWithoutScopeType( - fake: sinon.SinonSpy<[scopeInfos: T[]], void>, - ...scopeTypes: ScopeType[] -) { - return sleepAndCheck(fake, () => assertCalledWithout(scopeTypes, fake)); -} - -function assertCalledWith( - expectedScopeInfos: T[], - fake: sinon.SinonSpy<[scopeInfos: T[]], void>, -) { for (const expectedScopeInfo of expectedScopeInfos) { const actualScopeInfo = fake.lastCall.args[0].find((scopeInfo) => isEqual(scopeInfo.scopeType, expectedScopeInfo.scopeType), @@ -52,12 +18,17 @@ function assertCalledWith( assert.isDefined(actualScopeInfo); assert.deepEqual(actualScopeInfo, expectedScopeInfo); } + + fake.resetHistory(); } -function assertCalledWithout( - scopeTypes: ScopeType[], +export async function assertCalledWithoutScopeInfo( fake: sinon.SinonSpy<[scopeInfos: T[]], void>, + ...scopeTypes: ScopeType[] ) { + await sleepWithBackoff(25); + sinon.assert.called(fake); + for (const scopeType of scopeTypes) { assert.isUndefined( fake.lastCall.args[0].find((scopeInfo) => @@ -65,4 +36,6 @@ function assertCalledWithout( ), ); } + + fake.resetHistory(); } diff --git a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomRegexScopeInfoTest.ts b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomRegexScopeInfoTest.ts index 740ca1cc28..e5db8c6038 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomRegexScopeInfoTest.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomRegexScopeInfoTest.ts @@ -10,7 +10,7 @@ import { import * as sinon from "sinon"; import { assertCalledWithScopeInfo, - assertCalledWithoutScopeType as assertCalledWithoutScope, + assertCalledWithoutScopeInfo, } from "./assertCalledWithScopeInfo"; import { stat, unlink, writeFile } from "fs/promises"; import { sleepWithBackoff } from "../../endToEndTestSetup"; @@ -30,7 +30,7 @@ export async function runCustomRegexScopeInfoTest() { const disposable = scopeProvider.onDidChangeScopeSupport(fake); try { - await assertCalledWithoutScope(fake, scopeType); + await assertCalledWithoutScopeInfo(fake, scopeType); await writeFile( spokenFormsJsonPath, @@ -44,7 +44,7 @@ export async function runCustomRegexScopeInfoTest() { await unlink(spokenFormsJsonPath); await sleepWithBackoff(50); - await assertCalledWithoutScope(fake, scopeType); + await assertCalledWithoutScopeInfo(fake, scopeType); } finally { disposable.dispose(); diff --git a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts index 208d765733..0afbe0ad8a 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopeProvider/runCustomSpokenFormScopeInfoTest.ts @@ -1,10 +1,7 @@ import { getCursorlessApi } from "@cursorless/vscode-common"; import { LATEST_VERSION, ScopeTypeInfo, sleep } from "@cursorless/common"; import * as sinon from "sinon"; -import { - assertCalled, - assertCalledWithScopeInfo, -} from "./assertCalledWithScopeInfo"; +import { assertCalledWithScopeInfo } from "./assertCalledWithScopeInfo"; import { stat, unlink, writeFile } from "fs/promises"; import { sleepWithBackoff } from "../../endToEndTestSetup"; @@ -19,17 +16,14 @@ export async function runCustomSpokenFormScopeInfoTest() { const disposable = scopeProvider.onDidChangeScopeInfo(fake); try { - await assertCalled( + await assertCalledWithScopeInfo( fake, - [ - roundStandard, - namedFunctionStandard, - lambdaStandard, - statementStandard, - squareStandard, - subjectStandard, - ], - [], + roundStandard, + namedFunctionStandard, + lambdaStandard, + statementStandard, + squareStandard, + subjectStandard, ); await writeFile( @@ -49,17 +43,14 @@ export async function runCustomSpokenFormScopeInfoTest() { await unlink(spokenFormsJsonPath); await sleepWithBackoff(50); - await assertCalled( + await assertCalledWithScopeInfo( fake, - [ - roundStandard, - namedFunctionStandard, - lambdaStandard, - statementStandard, - squareStandard, - subjectStandard, - ], - [], + roundStandard, + namedFunctionStandard, + lambdaStandard, + statementStandard, + squareStandard, + subjectStandard, ); } finally { disposable.dispose();