Skip to content

Commit 272dc49

Browse files
Will-SommerspokeyAndreasArvidsson
authored
Force tab size on test run (#731)
* Force tab size on test run - This fixes problems related to different local configurations - Tests expect tabSize to be 4 * 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 * Move tab setting out of command loop and into test recorder * Remove unused import * Init tab setting as undefined * Force insert spaces on tests * Only show message if necessary * Move code to hooks * Fixes * Whoops Co-authored-by: Pokey Rule <[email protected]> Co-authored-by: Andreas Arvidsson <[email protected]>
1 parent f1e7b4c commit 272dc49

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/core/commandRunner/CommandRunner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ export default class CommandRunner {
177177
console.error(err.stack);
178178
throw err;
179179
} finally {
180-
this.graph.testCaseRecorder.finallyHook();
180+
if (this.graph.testCaseRecorder.isActive()) {
181+
this.graph.testCaseRecorder.finallyHook();
182+
}
181183
}
182184
}
183185

src/test/suite/recorded.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { promises as fsp } from "fs";
21
import { assert } from "chai";
2+
import { promises as fsp } from "fs";
33
import * as yaml from "js-yaml";
44
import * as vscode from "vscode";
55
import HatTokenMap from "../../core/HatTokenMap";
@@ -13,6 +13,7 @@ import {
1313
takeSnapshot,
1414
} from "../../testUtil/takeSnapshot";
1515
import { TestCaseFixture } from "../../testUtil/TestCase";
16+
import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "../../testUtil/testConstants";
1617
import {
1718
marksToPlainObject,
1819
PositionPlainObject,
@@ -74,6 +75,9 @@ async function runTest(file: string) {
7475
fixture.languageId,
7576
);
7677

78+
// Override any user settings and make sure tests run with default tabs.
79+
editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST;
80+
7781
if (fixture.postEditorOpenSleepTimeMs != null) {
7882
await sleepWithBackoff(fixture.postEditorOpenSleepTimeMs);
7983
}

src/testUtil/TestCaseRecorder.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { extractTargetedMarks } from "./extractTargetedMarks";
1414
import serialize from "./serialize";
1515
import { ExtraSnapshotField, takeSnapshot } from "./takeSnapshot";
1616
import { TestCase, TestCaseCommand, TestCaseContext } from "./TestCase";
17+
import { DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST } from "./testConstants";
1718
import { marksToPlainObject, SerializedMarks } from "./toPlainObject";
1819
import { walkDirsSync } from "./walkSync";
1920

@@ -82,6 +83,8 @@ export class TestCaseRecorder {
8283
private extraSnapshotFields?: ExtraSnapshotField[];
8384
private paused: boolean = false;
8485
private isErrorTest: boolean = false;
86+
/** We use this variable to capture editor settings and then restore them */
87+
private originalTextEditorOptions: vscode.TextEditorOptions = {};
8588
private calibrationStyle = vscode.window.createTextEditorDecorationType({
8689
backgroundColor: CALIBRATION_DISPLAY_BACKGROUND_COLOR,
8790
});
@@ -313,6 +316,12 @@ export class TestCaseRecorder {
313316
);
314317

315318
await this.testCase.recordInitialState();
319+
320+
const editor = vscode.window.activeTextEditor!;
321+
// NB: We need to copy the editor options rather than storing a reference
322+
// because its properties are lazy
323+
this.originalTextEditorOptions = { ...editor.options };
324+
editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST;
316325
}
317326
}
318327

@@ -439,6 +448,9 @@ export class TestCaseRecorder {
439448
finallyHook() {
440449
this.spyInfo?.dispose();
441450
this.spyInfo = undefined;
451+
452+
const editor = vscode.window.activeTextEditor!;
453+
editor.options = this.originalTextEditorOptions;
442454
}
443455

444456
dispose() {

src/testUtil/testConstants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as vscode from "vscode";
2+
3+
export const DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST: vscode.TextEditorOptions = {
4+
tabSize: 4,
5+
insertSpaces: true,
6+
};

0 commit comments

Comments
 (0)