Skip to content

Force tab size on test run #731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion src/core/commandRunner/CommandRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/test/suite/recorded.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -13,6 +13,7 @@ import {
takeSnapshot,
} from "../../testUtil/takeSnapshot";
import { TestCaseFixture } from "../../testUtil/TestCase";
import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "../../testUtil/testConstants";
import {
marksToPlainObject,
PositionPlainObject,
Expand Down Expand Up @@ -74,6 +75,9 @@ async function runTest(file: string) {
fixture.languageId,
);

// Override any user settings and make sure tests run with default tabs.
editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST;

if (fixture.postEditorOpenSleepTimeMs != null) {
await sleepWithBackoff(fixture.postEditorOpenSleepTimeMs);
}
Expand Down
12 changes: 12 additions & 0 deletions src/testUtil/TestCaseRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { extractTargetedMarks } from "./extractTargetedMarks";
import serialize from "./serialize";
import { ExtraSnapshotField, takeSnapshot } from "./takeSnapshot";
import { TestCase, TestCaseCommand, TestCaseContext } from "./TestCase";
import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "./testConstants";
import { marksToPlainObject, SerializedMarks } from "./toPlainObject";
import { walkDirsSync } from "./walkSync";

Expand Down Expand Up @@ -82,6 +83,8 @@ export class TestCaseRecorder {
private extraSnapshotFields?: ExtraSnapshotField[];
private paused: boolean = false;
private isErrorTest: boolean = false;
/** 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,
});
Expand Down Expand Up @@ -313,6 +316,12 @@ export class TestCaseRecorder {
);

await this.testCase.recordInitialState();

const editor = vscode.window.activeTextEditor!;
// 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;
}
}

Expand Down Expand Up @@ -439,6 +448,9 @@ export class TestCaseRecorder {
finallyHook() {
this.spyInfo?.dispose();
this.spyInfo = undefined;

const editor = vscode.window.activeTextEditor!;
editor.options = this.originalTextEditorOptions;
}

dispose() {
Expand Down
6 changes: 6 additions & 0 deletions src/testUtil/testConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as vscode from "vscode";

export const DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST: vscode.TextEditorOptions = {
tabSize: 4,
insertSpaces: true,
};