From 6a1433e0712ee0a4b44cced23ce6cd8c2bd367a2 Mon Sep 17 00:00:00 2001 From: Will Sommers Date: Fri, 3 Jun 2022 13:29:38 -0400 Subject: [PATCH 01/10] Force tab size on test run - This fixes problems related to different local configurations - Tests expect tabSize to be 4 --- src/test/suite/recorded.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/suite/recorded.test.ts b/src/test/suite/recorded.test.ts index 48ba988c4b..da1feb1eac 100644 --- a/src/test/suite/recorded.test.ts +++ b/src/test/suite/recorded.test.ts @@ -63,6 +63,8 @@ async function runTest(file: string) { fixture.initialState.documentContents, fixture.languageId ); + // Override any user defaults, all tests are recorded as tabSize = 4 + editor.options.tabSize = 4; if (!fixture.initialState.documentContents.includes("\n")) { await editor.edit((editBuilder) => { From 5c14acef4d60d2ed1231cd07a520bb416c244b9c Mon Sep 17 00:00:00 2001 From: Will Sommers Date: Wed, 8 Jun 2022 17:23:03 -0400 Subject: [PATCH 02/10] Ensure we set tab size on recording tests - Check if we're in debug mode and set tabSize if so - Move tabSize to constants file --- src/core/commandRunner/CommandRunner.ts | 5 +++++ src/core/constants.ts | 2 ++ src/test/suite/recorded.test.ts | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/commandRunner/CommandRunner.ts b/src/core/commandRunner/CommandRunner.ts index 84200426c6..85b24d0eee 100644 --- a/src/core/commandRunner/CommandRunner.ts +++ b/src/core/commandRunner/CommandRunner.ts @@ -6,6 +6,7 @@ import { Graph, ProcessedTargetsContext } from "../../typings/Types"; import { isString } from "../../util/type"; import { canonicalizeAndValidateCommand } from "../commandVersionUpgrades/canonicalizeAndValidateCommand"; import { PartialTargetV0V1 } from "../commandVersionUpgrades/upgradeV1ToV2/commandV1.types"; +import { DEFAULT_TAB_SIZE_FOR_TESTS } from "../constants"; import inferFullTargets from "../inferFullTargets"; import { ThatMark } from "../ThatMark"; import { Command } from "./command.types"; @@ -60,6 +61,10 @@ export default class CommandRunner { if (this.graph.debug.active) { this.graph.debug.log(`command:`); this.graph.debug.log(JSON.stringify(command, null, 3)); + if (vscode.window.activeTextEditor) { + vscode.window.activeTextEditor.options.tabSize = + DEFAULT_TAB_SIZE_FOR_TESTS; + } } const commandComplete = canonicalizeAndValidateCommand(command); diff --git a/src/core/constants.ts b/src/core/constants.ts index 36db8c8704..23f3982ec4 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -35,3 +35,5 @@ export interface HatStyle { color: HatColor; shape: HatShape; } + +export const DEFAULT_TAB_SIZE_FOR_TESTS = 4 as const; diff --git a/src/test/suite/recorded.test.ts b/src/test/suite/recorded.test.ts index 03e33e22d1..fb9c15e076 100644 --- a/src/test/suite/recorded.test.ts +++ b/src/test/suite/recorded.test.ts @@ -3,6 +3,7 @@ import { promises as fsp } from "fs"; import * as yaml from "js-yaml"; import * as sinon from "sinon"; import * as vscode from "vscode"; +import { DEFAULT_TAB_SIZE_FOR_TESTS } from "../../core/constants"; import HatTokenMap from "../../core/HatTokenMap"; import { ReadOnlyHatMap } from "../../core/IndividualHatMap"; import { extractTargetedMarks } from "../../testUtil/extractTargetedMarks"; @@ -76,7 +77,7 @@ async function runTest(file: string) { fixture.languageId ); // Override any user defaults, all tests are recorded as tabSize = 4 - editor.options.tabSize = 4; + editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; if (fixture.postEditorOpenSleepTimeMs != null) { await sleep(fixture.postEditorOpenSleepTimeMs); From faca8a2ae1e38496cc15f85eef52d3ce339e0855 Mon Sep 17 00:00:00 2001 From: Will Sommers Date: Sun, 12 Jun 2022 11:01:42 -0400 Subject: [PATCH 03/10] Move tab setting out of command loop and into test recorder --- src/core/commandRunner/CommandRunner.ts | 4 ---- src/testUtil/TestCaseRecorder.ts | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/core/commandRunner/CommandRunner.ts b/src/core/commandRunner/CommandRunner.ts index 85b24d0eee..488ce417d0 100644 --- a/src/core/commandRunner/CommandRunner.ts +++ b/src/core/commandRunner/CommandRunner.ts @@ -61,10 +61,6 @@ export default class CommandRunner { if (this.graph.debug.active) { this.graph.debug.log(`command:`); this.graph.debug.log(JSON.stringify(command, null, 3)); - if (vscode.window.activeTextEditor) { - vscode.window.activeTextEditor.options.tabSize = - DEFAULT_TAB_SIZE_FOR_TESTS; - } } const commandComplete = canonicalizeAndValidateCommand(command); diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index 665ef06b1e..dff8fe849e 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -13,6 +13,7 @@ import { ExtraSnapshotField, takeSnapshot } from "./takeSnapshot"; import { TestCase, TestCaseCommand, TestCaseContext } from "./TestCase"; import { marksToPlainObject, SerializedMarks } from "./toPlainObject"; import { walkDirsSync } from "./walkSync"; +import { DEFAULT_TAB_SIZE_FOR_TESTS } from "../core/constants"; const CALIBRATION_DISPLAY_BACKGROUND_COLOR = "#230026"; const CALIBRATION_DISPLAY_DURATION_MS = 30; @@ -74,6 +75,7 @@ export class TestCaseRecorder { private extraSnapshotFields?: ExtraSnapshotField[]; private paused: boolean = false; private isErrorTest: boolean = false; + private userTabSetting: string | number | undefined = 4; private calibrationStyle = vscode.window.createTextEditorDecorationType({ backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR, }); @@ -115,7 +117,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to pause recording, but no recording active"); } - + this.toggleUserTabSetting(false); this.paused = true; }), @@ -125,7 +127,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to resume recording, but no recording active"); } - + this.toggleUserTabSetting(true); this.paused = false; } ), @@ -208,6 +210,7 @@ export class TestCaseRecorder { vscode.window.showInformationMessage( `Recording test cases for following commands in:\n${this.targetDirectory}` ); + this.toggleUserTabSetting(true); return { startTimestampISO: timestampISO }; } @@ -230,10 +233,27 @@ export class TestCaseRecorder { } stop() { + this.toggleUserTabSetting(false); + this.active = false; this.paused = false; } + private toggleUserTabSetting(shouldSetTabs: boolean) { + let message: string; + if (shouldSetTabs) { + this.userTabSetting = vscode.window.activeTextEditor!.options.tabSize; + vscode.window.activeTextEditor!.options.tabSize = + DEFAULT_TAB_SIZE_FOR_TESTS; + message = `Setting default tab size to ${DEFAULT_TAB_SIZE_FOR_TESTS} spaces for test recording.`; + } else { + vscode.window.activeTextEditor!.options.tabSize = this.userTabSetting; + message = "Resetting tab size to user default."; + } + + vscode.window.showInformationMessage(message); + } + async preCommandHook(command: TestCaseCommand, context: TestCaseContext) { if (this.testCase != null) { // If testCase is not null and we are just before a command, this means From 44d7ee56589a23bcf8b717dd55425f1e4022de09 Mon Sep 17 00:00:00 2001 From: Will Sommers Date: Sun, 12 Jun 2022 11:02:35 -0400 Subject: [PATCH 04/10] Remove unused import --- src/core/commandRunner/CommandRunner.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/commandRunner/CommandRunner.ts b/src/core/commandRunner/CommandRunner.ts index 488ce417d0..84200426c6 100644 --- a/src/core/commandRunner/CommandRunner.ts +++ b/src/core/commandRunner/CommandRunner.ts @@ -6,7 +6,6 @@ import { Graph, ProcessedTargetsContext } from "../../typings/Types"; import { isString } from "../../util/type"; import { canonicalizeAndValidateCommand } from "../commandVersionUpgrades/canonicalizeAndValidateCommand"; import { PartialTargetV0V1 } from "../commandVersionUpgrades/upgradeV1ToV2/commandV1.types"; -import { DEFAULT_TAB_SIZE_FOR_TESTS } from "../constants"; import inferFullTargets from "../inferFullTargets"; import { ThatMark } from "../ThatMark"; import { Command } from "./command.types"; From 32f8f0c2867305d078d1dc410d770fe33c6064d3 Mon Sep 17 00:00:00 2001 From: Will Sommers Date: Sun, 12 Jun 2022 11:04:07 -0400 Subject: [PATCH 05/10] Init tab setting as undefined --- src/testUtil/TestCaseRecorder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index dff8fe849e..ee75070b74 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -75,7 +75,7 @@ export class TestCaseRecorder { private extraSnapshotFields?: ExtraSnapshotField[]; private paused: boolean = false; private isErrorTest: boolean = false; - private userTabSetting: string | number | undefined = 4; + private userTabSetting: string | number | undefined; private calibrationStyle = vscode.window.createTextEditorDecorationType({ backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR, }); From 3295eaacacf0ca26044a4c82761e8fa1abe1beeb Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 24 Oct 2022 15:40:17 +0200 Subject: [PATCH 06/10] Force insert spaces on tests --- src/test/suite/recorded.test.ts | 14 +++++++---- src/test/suite/runTestSubset.ts | 2 +- src/testUtil/TestCaseRecorder.ts | 41 +++++++++++++++++++------------- src/testUtil/testConstants.ts | 2 ++ 4 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 src/testUtil/testConstants.ts diff --git a/src/test/suite/recorded.test.ts b/src/test/suite/recorded.test.ts index aeff2614be..d06d38ab35 100644 --- a/src/test/suite/recorded.test.ts +++ b/src/test/suite/recorded.test.ts @@ -1,5 +1,5 @@ -import { promises as fsp } from "fs"; import { assert } from "chai"; +import { promises as fsp } from "fs"; import * as yaml from "js-yaml"; import * as vscode from "vscode"; import HatTokenMap from "../../core/HatTokenMap"; @@ -13,6 +13,10 @@ import { takeSnapshot, } from "../../testUtil/takeSnapshot"; import { TestCaseFixture } from "../../testUtil/TestCase"; +import { + DEFAULT_INSERT_SPACES_FOR_TEST, + DEFAULT_TAB_SIZE_FOR_TESTS, +} from "../../testUtil/testConstants"; import { marksToPlainObject, PositionPlainObject, @@ -30,8 +34,6 @@ import { injectFakeIde } from "./fakes/ide/FakeIDE"; import shouldUpdateFixtures from "./shouldUpdateFixtures"; import { sleepWithBackoff, standardSuiteSetup } from "./standardSuiteSetup"; -export const DEFAULT_TAB_SIZE_FOR_TESTS = 4; - function createPosition(position: PositionPlainObject) { return new vscode.Position(position.line, position.character); } @@ -75,8 +77,10 @@ async function runTest(file: string) { fixture.initialState.documentContents, fixture.languageId ); - // Override any user defaults, all tests are recorded as tabSize = 4 - // editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; + + // Override any user settings and make sure tests run with default tabs. + editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; + editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; if (fixture.postEditorOpenSleepTimeMs != null) { await sleepWithBackoff(fixture.postEditorOpenSleepTimeMs); diff --git a/src/test/suite/runTestSubset.ts b/src/test/suite/runTestSubset.ts index cbc5baa3cb..87840af76d 100644 --- a/src/test/suite/runTestSubset.ts +++ b/src/test/suite/runTestSubset.ts @@ -4,7 +4,7 @@ * configuration. * See https://mochajs.org/#-grep-regexp-g-regexp for supported syntax */ -export const TEST_SUBSET_GREP_STRING = "clearLineFine"; +export const TEST_SUBSET_GREP_STRING = "tokenizer"; /** * Determine whether we should run just the subset of the tests specified by diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index daa6612255..3dbeb9c4ee 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -6,7 +6,6 @@ import * as path from "path"; import * as vscode from "vscode"; import HatTokenMap from "../core/HatTokenMap"; import { injectSpyIde, SpyInfo } from "../ide/spies/SpyIDE"; -import { DEFAULT_TAB_SIZE_FOR_TESTS } from "../test/suite/recorded.test"; import { DecoratedSymbolMark } from "../typings/targetDescriptor.types"; import { Graph } from "../typings/Types"; import { getDocumentRange } from "../util/rangeUtils"; @@ -15,6 +14,10 @@ import { extractTargetedMarks } from "./extractTargetedMarks"; import serialize from "./serialize"; import { ExtraSnapshotField, takeSnapshot } from "./takeSnapshot"; import { TestCase, TestCaseCommand, TestCaseContext } from "./TestCase"; +import { + DEFAULT_INSERT_SPACES_FOR_TEST, + DEFAULT_TAB_SIZE_FOR_TESTS, +} from "./testConstants"; import { marksToPlainObject, SerializedMarks } from "./toPlainObject"; import { walkDirsSync } from "./walkSync"; @@ -84,6 +87,7 @@ export class TestCaseRecorder { private paused: boolean = false; private isErrorTest: boolean = false; private userTabSetting: string | number | undefined; + private userInsertSpacesSetting: boolean | string | undefined; private calibrationStyle = vscode.window.createTextEditorDecorationType({ backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR, }); @@ -127,7 +131,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to pause recording, but no recording active"); } - this.toggleUserTabSetting(false); + this.disableTabSetting(); this.paused = true; }), @@ -137,7 +141,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to resume recording, but no recording active"); } - this.toggleUserTabSetting(true); + this.enableTabSetting(); this.paused = false; } ), @@ -255,7 +259,7 @@ export class TestCaseRecorder { `Recording test cases for following commands in:\n${this.targetDirectory}` ); - this.toggleUserTabSetting(true); + this.enableTabSetting(); return { startTimestampISO }; } @@ -286,25 +290,28 @@ export class TestCaseRecorder { } stop() { - this.toggleUserTabSetting(false); + this.disableTabSetting(); this.active = false; this.paused = false; } - private toggleUserTabSetting(shouldSetTabs: boolean) { - let message: string; - if (shouldSetTabs) { - this.userTabSetting = vscode.window.activeTextEditor!.options.tabSize; - vscode.window.activeTextEditor!.options.tabSize = - DEFAULT_TAB_SIZE_FOR_TESTS; - message = `Setting default tab size to ${DEFAULT_TAB_SIZE_FOR_TESTS} spaces for test recording.`; - } else { - vscode.window.activeTextEditor!.options.tabSize = this.userTabSetting; - message = "Resetting tab size to user default."; - } + private enableTabSetting() { + const editor = vscode.window.activeTextEditor!; + this.userTabSetting = editor.options.tabSize; + this.userInsertSpacesSetting = editor.options.insertSpaces; + editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; + editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; + vscode.window.showInformationMessage( + `Setting default tab size to ${DEFAULT_TAB_SIZE_FOR_TESTS} spaces for test recording.` + ); + } - vscode.window.showInformationMessage(message); + private disableTabSetting() { + const editor = vscode.window.activeTextEditor!; + editor.options.tabSize = this.userTabSetting; + editor.options.insertSpaces = this.userInsertSpacesSetting; + vscode.window.showInformationMessage("Resetting tab size to user default."); } async preCommandHook(command: TestCaseCommand, context: TestCaseContext) { diff --git a/src/testUtil/testConstants.ts b/src/testUtil/testConstants.ts new file mode 100644 index 0000000000..4e0d4102f0 --- /dev/null +++ b/src/testUtil/testConstants.ts @@ -0,0 +1,2 @@ +export const DEFAULT_TAB_SIZE_FOR_TESTS = 4; +export const DEFAULT_INSERT_SPACES_FOR_TEST = true; From 1a8f694d9666480f0c48abddf2dce49b8694cdc9 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 24 Oct 2022 15:47:05 +0200 Subject: [PATCH 07/10] Only show message if necessary --- src/testUtil/TestCaseRecorder.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index 3dbeb9c4ee..184af2365d 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -300,18 +300,22 @@ export class TestCaseRecorder { const editor = vscode.window.activeTextEditor!; this.userTabSetting = editor.options.tabSize; this.userInsertSpacesSetting = editor.options.insertSpaces; - editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; - editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; - vscode.window.showInformationMessage( - `Setting default tab size to ${DEFAULT_TAB_SIZE_FOR_TESTS} spaces for test recording.` - ); + if ( + this.userTabSetting !== DEFAULT_TAB_SIZE_FOR_TESTS || + this.userInsertSpacesSetting !== DEFAULT_INSERT_SPACES_FOR_TEST + ) { + editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; + editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; + vscode.window.showInformationMessage( + "Setting default tab size for test recording." + ); + } } private disableTabSetting() { const editor = vscode.window.activeTextEditor!; editor.options.tabSize = this.userTabSetting; editor.options.insertSpaces = this.userInsertSpacesSetting; - vscode.window.showInformationMessage("Resetting tab size to user default."); } async preCommandHook(command: TestCaseCommand, context: TestCaseContext) { From 200cfb41bf414078aaf36ad4c50c66fc05b7e1d0 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 24 Oct 2022 16:05:50 +0200 Subject: [PATCH 08/10] Move code to hooks --- src/test/suite/recorded.test.ts | 8 ++---- src/testUtil/TestCaseRecorder.ts | 43 +++++++------------------------- src/testUtil/testConstants.ts | 8 ++++-- 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/test/suite/recorded.test.ts b/src/test/suite/recorded.test.ts index d06d38ab35..e9dd3efe9f 100644 --- a/src/test/suite/recorded.test.ts +++ b/src/test/suite/recorded.test.ts @@ -13,10 +13,7 @@ import { takeSnapshot, } from "../../testUtil/takeSnapshot"; import { TestCaseFixture } from "../../testUtil/TestCase"; -import { - DEFAULT_INSERT_SPACES_FOR_TEST, - DEFAULT_TAB_SIZE_FOR_TESTS, -} from "../../testUtil/testConstants"; +import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "../../testUtil/testConstants"; import { marksToPlainObject, PositionPlainObject, @@ -79,8 +76,7 @@ async function runTest(file: string) { ); // Override any user settings and make sure tests run with default tabs. - editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; - editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; + editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST; if (fixture.postEditorOpenSleepTimeMs != null) { await sleepWithBackoff(fixture.postEditorOpenSleepTimeMs); diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index 184af2365d..30759baf2c 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -14,10 +14,7 @@ import { extractTargetedMarks } from "./extractTargetedMarks"; import serialize from "./serialize"; import { ExtraSnapshotField, takeSnapshot } from "./takeSnapshot"; import { TestCase, TestCaseCommand, TestCaseContext } from "./TestCase"; -import { - DEFAULT_INSERT_SPACES_FOR_TEST, - DEFAULT_TAB_SIZE_FOR_TESTS, -} from "./testConstants"; +import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "./testConstants"; import { marksToPlainObject, SerializedMarks } from "./toPlainObject"; import { walkDirsSync } from "./walkSync"; @@ -86,8 +83,7 @@ export class TestCaseRecorder { private extraSnapshotFields?: ExtraSnapshotField[]; private paused: boolean = false; private isErrorTest: boolean = false; - private userTabSetting: string | number | undefined; - private userInsertSpacesSetting: boolean | string | undefined; + private textEditorOptions: vscode.TextEditorOptions = {}; private calibrationStyle = vscode.window.createTextEditorDecorationType({ backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR, }); @@ -131,7 +127,6 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to pause recording, but no recording active"); } - this.disableTabSetting(); this.paused = true; }), @@ -141,7 +136,6 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to resume recording, but no recording active"); } - this.enableTabSetting(); this.paused = false; } ), @@ -259,8 +253,6 @@ export class TestCaseRecorder { `Recording test cases for following commands in:\n${this.targetDirectory}` ); - this.enableTabSetting(); - return { startTimestampISO }; } @@ -290,34 +282,10 @@ export class TestCaseRecorder { } stop() { - this.disableTabSetting(); - this.active = false; this.paused = false; } - private enableTabSetting() { - const editor = vscode.window.activeTextEditor!; - this.userTabSetting = editor.options.tabSize; - this.userInsertSpacesSetting = editor.options.insertSpaces; - if ( - this.userTabSetting !== DEFAULT_TAB_SIZE_FOR_TESTS || - this.userInsertSpacesSetting !== DEFAULT_INSERT_SPACES_FOR_TEST - ) { - editor.options.tabSize = DEFAULT_TAB_SIZE_FOR_TESTS; - editor.options.insertSpaces = DEFAULT_INSERT_SPACES_FOR_TEST; - vscode.window.showInformationMessage( - "Setting default tab size for test recording." - ); - } - } - - private disableTabSetting() { - const editor = vscode.window.activeTextEditor!; - editor.options.tabSize = this.userTabSetting; - editor.options.insertSpaces = this.userInsertSpacesSetting; - } - async preCommandHook(command: TestCaseCommand, context: TestCaseContext) { if (this.testCase != null) { // If testCase is not null and we are just before a command, this means @@ -345,6 +313,10 @@ export class TestCaseRecorder { ); await this.testCase.recordInitialState(); + + const editor = vscode.window.activeTextEditor!; + this.textEditorOptions = editor.options; + editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST; } } @@ -471,6 +443,9 @@ export class TestCaseRecorder { finallyHook() { this.spyInfo?.dispose(); this.spyInfo = undefined; + + const editor = vscode.window.activeTextEditor!; + editor.options = this.textEditorOptions; } dispose() { diff --git a/src/testUtil/testConstants.ts b/src/testUtil/testConstants.ts index 4e0d4102f0..22bc06de80 100644 --- a/src/testUtil/testConstants.ts +++ b/src/testUtil/testConstants.ts @@ -1,2 +1,6 @@ -export const DEFAULT_TAB_SIZE_FOR_TESTS = 4; -export const DEFAULT_INSERT_SPACES_FOR_TEST = true; +import * as vscode from "vscode"; + +export const DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST: vscode.TextEditorOptions = { + tabSize: 4, + insertSpaces: true, +}; From 9f3fad8e97b86ac97d704ff1f650a9cecc9f8300 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Mon, 24 Oct 2022 20:59:59 +0100 Subject: [PATCH 09/10] Fixes --- src/core/commandRunner/CommandRunner.ts | 4 +++- src/testUtil/TestCaseRecorder.ts | 11 ++++++++--- src/testUtil/testConstants.ts | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/commandRunner/CommandRunner.ts b/src/core/commandRunner/CommandRunner.ts index 685f4c5ea8..310366b96e 100644 --- a/src/core/commandRunner/CommandRunner.ts +++ b/src/core/commandRunner/CommandRunner.ts @@ -177,7 +177,9 @@ export default class CommandRunner { console.error(err.stack); throw err; } finally { - this.graph.testCaseRecorder.finallyHook(); + if (this.graph.testCaseRecorder.isActive()) { + this.graph.testCaseRecorder.finallyHook(); + } } } diff --git a/src/testUtil/TestCaseRecorder.ts b/src/testUtil/TestCaseRecorder.ts index 30759baf2c..f8705d33c2 100644 --- a/src/testUtil/TestCaseRecorder.ts +++ b/src/testUtil/TestCaseRecorder.ts @@ -83,7 +83,8 @@ export class TestCaseRecorder { private extraSnapshotFields?: ExtraSnapshotField[]; private paused: boolean = false; private isErrorTest: boolean = false; - private textEditorOptions: vscode.TextEditorOptions = {}; + /** We use this variable to capture editor settings and then restore them */ + private originalTextEditorOptions: vscode.TextEditorOptions = {}; private calibrationStyle = vscode.window.createTextEditorDecorationType({ backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR, }); @@ -127,6 +128,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to pause recording, but no recording active"); } + this.paused = true; }), @@ -136,6 +138,7 @@ export class TestCaseRecorder { if (!this.active) { throw Error("Asked to resume recording, but no recording active"); } + this.paused = false; } ), @@ -315,7 +318,9 @@ export class TestCaseRecorder { await this.testCase.recordInitialState(); const editor = vscode.window.activeTextEditor!; - this.textEditorOptions = editor.options; + // NB: We need to copy the editor options rather than storing a reference + // because its properties are lazy + this.originalTextEditorOptions = { ...editor.options }; editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST; } } @@ -445,7 +450,7 @@ export class TestCaseRecorder { this.spyInfo = undefined; const editor = vscode.window.activeTextEditor!; - editor.options = this.textEditorOptions; + editor.options = this.originalTextEditorOptions; } dispose() { diff --git a/src/testUtil/testConstants.ts b/src/testUtil/testConstants.ts index 22bc06de80..8a83dc29ce 100644 --- a/src/testUtil/testConstants.ts +++ b/src/testUtil/testConstants.ts @@ -1,6 +1,6 @@ import * as vscode from "vscode"; export const DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST: vscode.TextEditorOptions = { - tabSize: 4, + tabSize: 8, insertSpaces: true, }; From 377d38702841cfb5c660a301928a7178db6b5c70 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Mon, 24 Oct 2022 21:00:54 +0100 Subject: [PATCH 10/10] Whoops --- src/testUtil/testConstants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/testUtil/testConstants.ts b/src/testUtil/testConstants.ts index 8a83dc29ce..22bc06de80 100644 --- a/src/testUtil/testConstants.ts +++ b/src/testUtil/testConstants.ts @@ -1,6 +1,6 @@ import * as vscode from "vscode"; export const DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST: vscode.TextEditorOptions = { - tabSize: 8, + tabSize: 4, insertSpaces: true, };