Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export interface HatStyle {
color: HatColor;
shape: HatShape;
}

export const DEFAULT_TAB_SIZE_FOR_TESTS = 4 as const;
3 changes: 3 additions & 0 deletions src/test/suite/recorded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -75,6 +76,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 = DEFAULT_TAB_SIZE_FOR_TESTS;

if (fixture.postEditorOpenSleepTimeMs != null) {
await sleep(fixture.postEditorOpenSleepTimeMs);
Expand Down
24 changes: 22 additions & 2 deletions src/testUtil/TestCaseRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,7 @@ export class TestCaseRecorder {
private extraSnapshotFields?: ExtraSnapshotField[];
private paused: boolean = false;
private isErrorTest: boolean = false;
private userTabSetting: string | number | undefined;
private calibrationStyle = vscode.window.createTextEditorDecorationType({
backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR,
});
Expand Down Expand Up @@ -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;
}),

Expand All @@ -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;
}
),
Expand Down Expand Up @@ -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 };
}
Expand All @@ -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
Expand Down