Skip to content

Commit 38cf5da

Browse files
authored
fix: error logging (#8)
1 parent 4c45755 commit 38cf5da

File tree

8 files changed

+38
-14
lines changed

8 files changed

+38
-14
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/), and this
66

77
## [Unreleased]
88

9+
## [0.1.2] - 2024-03-09
10+
11+
### Fixed
12+
13+
- Output channel error logging
14+
15+
### Changed
16+
17+
- Shields in `README.md`
18+
919
## [0.1.1] - 2024-03-08
1020

1121
### Added
@@ -39,7 +49,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/), and this
3949

4050
- Swap Tsconfig extension with command `swap-tsconfig` and settings `swap-tsconfig.exclude` and `swap-tsconfig.include`
4151

42-
[unreleased]: https://github.com/harrydowning/swap-tsconfig/compare/v0.1.1...HEAD
52+
[unreleased]: https://github.com/harrydowning/swap-tsconfig/compare/v0.1.2...HEAD
53+
[0.1.2]: https://github.com/harrydowning/swap-tsconfig/compare/v0.1.1...v0.1.2
4354
[0.1.1]: https://github.com/harrydowning/swap-tsconfig/compare/v0.1.0...v0.1.1
4455
[0.1.0]: https://github.com/harrydowning/swap-tsconfig/compare/v0.0.1...v0.1.0
4556
[0.0.1]: https://github.com/harrydowning/swap-tsconfig/releases/tag/v0.0.1

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
<h1 align="center">
2-
<img src="https://raw.githubusercontent.com/harrydowning/swap-tsconfig/main/assets/banner.png" alt="Swap Tsconfig">
3-
</h1>
4-
51
<div align="center">
62

3+
# ![Swap Tsconfig](https://raw.githubusercontent.com/harrydowning/swap-tsconfig/main/assets/banner.png)
4+
75
![GitHub License](https://img.shields.io/github/license/harrydowning/swap-tsconfig?style=for-the-badge)
86
![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/harrydowning.swap-tsconfig?style=for-the-badge)
97
![Visual Studio Marketplace Downloads](https://img.shields.io/visual-studio-marketplace/d/harrydowning.swap-tsconfig?style=for-the-badge)

__mocks__/vscode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ export const window = {
33
showInformationMessage: jest.fn(),
44
showWorkspaceFolderPick: jest.fn(),
55
showQuickPick: jest.fn(),
6+
createOutputChannel: jest.fn(() => ({
7+
error: jest.fn(),
8+
show: jest.fn(),
9+
})),
610
};
711

812
export const workspace = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "swap-tsconfig",
33
"displayName": "Swap Tsconfig",
4-
"version": "0.1.1",
4+
"version": "0.1.2",
55
"description": "Command to swap between multiple Typescript configuration files",
66
"categories": [
77
"Other"

src/extension.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from "vscode";
22
import { activate, deactivate } from "./extension";
33
import { FileSwap } from "./file-swap";
4+
import { logger } from "./utils";
45

56
jest.mock("./file-swap");
67

@@ -18,7 +19,7 @@ describe("extension", () => {
1819
activate(mockContext);
1920

2021
expect(vscode.commands.registerCommand).toHaveBeenCalledTimes(1);
21-
expect(mockContext.subscriptions).toContain(mockDisposable);
22+
expect(mockContext.subscriptions).toStrictEqual([mockDisposable, logger]);
2223

2324
const registeredCommand = jest.mocked(vscode.commands.registerCommand)
2425
.mock.calls[0][1];

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import { commandWrapper } from "./utils";
2+
import { commandWrapper, logger } from "./utils";
33
import { FileSwap } from "./file-swap";
44

55
const settings = vscode.workspace.getConfiguration("swap-tsconfig");
@@ -15,7 +15,7 @@ export const activate = (context: vscode.ExtensionContext) => {
1515
commandWrapper(async () => tsconfigFileSwap.swap()),
1616
);
1717

18-
context.subscriptions.push(disposable);
18+
context.subscriptions.push(disposable, logger);
1919
};
2020

2121
export const deactivate = () => {

src/utils.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as vscode from "vscode";
22
import { FatalExtensionError, NonFatalExtensionError } from "./extension-error";
3-
import { commandWrapper, getNonNullable, getWorkspaceFolder } from "./utils";
3+
import {
4+
commandWrapper,
5+
getNonNullable,
6+
getWorkspaceFolder,
7+
logger,
8+
} from "./utils";
49

510
describe("utils", () => {
611
describe("commandWrapper", () => {
@@ -25,7 +30,6 @@ describe("utils", () => {
2530

2631
it("should show a generic error message and log to console on any other Error", () => {
2732
const error = new Error();
28-
const consoleErrorSpy = jest.spyOn(console, "error");
2933
commandWrapper(() => {
3034
throw error;
3135
})();
@@ -34,8 +38,9 @@ describe("utils", () => {
3438
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith(
3539
"An error has occurred.",
3640
);
37-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
38-
expect(consoleErrorSpy).toHaveBeenCalledWith(error);
41+
expect(logger.error).toHaveBeenCalledTimes(1);
42+
expect(logger.error).toHaveBeenCalledWith(error);
43+
expect(logger.show).toHaveBeenCalledTimes(1);
3944
});
4045
});
4146

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
NonFatalExtensionError,
66
} from "./extension-error";
77

8+
export const logger = vscode.window.createOutputChannel("Swap Tsconfig", {
9+
log: true,
10+
});
11+
812
export const commandWrapper = (command: () => Promise<void> | void) => {
913
return async () => {
1014
try {
@@ -14,7 +18,8 @@ export const commandWrapper = (command: () => Promise<void> | void) => {
1418
vscode.window.showErrorMessage(error.message);
1519
} else if (error instanceof Error) {
1620
vscode.window.showErrorMessage("An error has occurred.");
17-
console.error(error);
21+
logger.error(error);
22+
logger.show();
1823
}
1924
}
2025
};

0 commit comments

Comments
 (0)