Skip to content

Commit

Permalink
refactor: simplify test status decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
Tymek committed Jun 26, 2020
1 parent e115488 commit fa38ae8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
31 changes: 9 additions & 22 deletions src/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,33 @@ import {
TextEditorDecorationType,
} from 'vscode';

export enum TestState {
Passing = 'passing',
Skip = 'skip',
Failing = 'failing',
NotRan = 'notRan',
}

const overviewRulerColors = {
passing: 'green',
skip: 'yellow',
failing: 'red',
notRan: 'darkgrey',
};

export function createTestStatusDecoration(
function createTestStateDecoration(
context: ExtensionContext,
name: TestState
icon: string,
overviewRulerColor: string
): TextEditorDecorationType {
return window.createTextEditorDecorationType({
overviewRulerColor: overviewRulerColors[name],
gutterIconPath: context.asAbsolutePath(`images/icons/${name}.svg`),
overviewRulerColor,
gutterIconPath: context.asAbsolutePath(`images/icons/${icon}.svg`),
overviewRulerLane: OverviewRulerLane.Left,
rangeBehavior: DecorationRangeBehavior.ClosedClosed,
});
}

export function failingItName(context: ExtensionContext): TextEditorDecorationType {
return createTestStatusDecoration(context, TestState.Failing);
return createTestStateDecoration(context, 'passing', 'green');
}

export function skipItName(context: ExtensionContext): TextEditorDecorationType {
return createTestStatusDecoration(context, TestState.Skip);
return createTestStateDecoration(context, 'skip', 'yellow');
}

export function passingItName(context: ExtensionContext): TextEditorDecorationType {
return createTestStatusDecoration(context, TestState.Passing);
return createTestStateDecoration(context, 'failing', 'red');
}

export function notRanItName(context: ExtensionContext): TextEditorDecorationType {
return createTestStatusDecoration(context, TestState.NotRan);
return createTestStateDecoration(context, 'notRan', 'darkgrey');
}

export function failingAssertionStyle(text: string): TextEditorDecorationType {
Expand Down
2 changes: 0 additions & 2 deletions tests/decorations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function testRangeBehavior(

factoryMethod((context as unknown) as vscode.ExtensionContext);

console.log(mock.mock.calls[0][0]);

expect(mock).toHaveBeenCalledTimes(1);
expect(mock.mock.calls[0][0].rangeBehavior).toBe(vscode.DecorationRangeBehavior.ClosedClosed);
expect(mock.mock.calls[0][0].overviewRulerLane).toBe(vscode.OverviewRulerLane.Left);
Expand Down

0 comments on commit fa38ae8

Please sign in to comment.