diff --git a/.editorconfig b/.editorconfig index ec317dc..27d678a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,3 @@ -root = true - [*] charset = utf-8 end_of_line = lf @@ -7,4 +5,4 @@ indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true -max_line_length = 100 \ No newline at end of file +max_line_length = 120 diff --git a/src/test/globalMocks.ts b/src/test/globalMocks.ts new file mode 100644 index 0000000..9505019 --- /dev/null +++ b/src/test/globalMocks.ts @@ -0,0 +1,13 @@ +import { vi } from 'vitest'; + +export function mockLogger() { + return { + logger: { + trace: vi.fn(), + debug: vi.fn(), + info: vi.fn(), + warn: vi.fn(), + error: vi.fn(), + }, + }; +} diff --git a/src/test/unit/commands/commentAllLogMessages.spec.ts b/src/test/unit/commands/commentAllLogMessages.spec.ts index c6011e5..be9ecaf 100644 --- a/src/test/unit/commands/commentAllLogMessages.spec.ts +++ b/src/test/unit/commands/commentAllLogMessages.spec.ts @@ -1,26 +1,11 @@ import { commentAllLogMessagesCommand } from '@/commands/commentAllLogMessages'; import { ExtensionProperties } from '@/typings'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { - Position, - Range, - Selection, - TextDocument, - TextEditor, - TextEditorEdit, - window, -} from 'vscode'; +import { Position, Range, Selection, TextDocument, TextEditor, TextEditorEdit, window } from 'vscode'; vi.mock('vscode'); -vi.mock('@/extension', () => ({ - logger: { - trace: vi.fn(), - debug: vi.fn(), - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); +const { mockLogger } = await vi.hoisted(() => import('@/test/globalMocks')); +vi.mock('@/extension', mockLogger); describe('commentAllLogMessagesCommand', () => { let mockEditor: TextEditor | undefined; diff --git a/src/test/unit/commands/deleteAllLogMessages.spec.ts b/src/test/unit/commands/deleteAllLogMessages.spec.ts index 0eddfc7..7146560 100644 --- a/src/test/unit/commands/deleteAllLogMessages.spec.ts +++ b/src/test/unit/commands/deleteAllLogMessages.spec.ts @@ -12,15 +12,8 @@ import { } from 'vscode'; vi.mock('vscode'); -vi.mock('@/extension', () => ({ - logger: { - trace: vi.fn(), - debug: vi.fn(), - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); +const { mockLogger } = await vi.hoisted(() => import('@/test/globalMocks')); +vi.mock('@/extension', mockLogger); describe('deleteAllLogMessagesCommand', () => { let mockEditor: TextEditor | undefined; diff --git a/src/test/unit/commands/displayLogMessage.spec.ts b/src/test/unit/commands/displayLogMessage.spec.ts index 549b3fd..e097601 100644 --- a/src/test/unit/commands/displayLogMessage.spec.ts +++ b/src/test/unit/commands/displayLogMessage.spec.ts @@ -12,15 +12,8 @@ import { } from 'vscode'; vi.mock('vscode'); -vi.mock('@/extension', () => ({ - logger: { - trace: vi.fn(), - debug: vi.fn(), - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); +const { mockLogger } = await vi.hoisted(() => import('@/test/globalMocks')); +vi.mock('@/extension', mockLogger); describe('displayLogMessageCommand', () => { let mockEditor: TextEditor | undefined; diff --git a/src/test/unit/commands/uncommentAllLogMessages.spec.ts b/src/test/unit/commands/uncommentAllLogMessages.spec.ts index c762e1a..37d3703 100644 --- a/src/test/unit/commands/uncommentAllLogMessages.spec.ts +++ b/src/test/unit/commands/uncommentAllLogMessages.spec.ts @@ -12,15 +12,8 @@ import { } from 'vscode'; vi.mock('vscode'); -vi.mock('@/extension', () => ({ - logger: { - trace: vi.fn(), - debug: vi.fn(), - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); +const { mockLogger } = await vi.hoisted(() => import('@/test/globalMocks')); +vi.mock('@/extension', mockLogger); describe('uncommentAllLogMessagesCommand', () => { let mockEditor: TextEditor | undefined; diff --git a/src/test/unit/commands/updateLineNumAllLogMessages.spec.ts b/src/test/unit/commands/updateLineNumAllLogMessages.spec.ts index 14c9e1c..b3eb46e 100644 --- a/src/test/unit/commands/updateLineNumAllLogMessages.spec.ts +++ b/src/test/unit/commands/updateLineNumAllLogMessages.spec.ts @@ -12,15 +12,8 @@ import { } from 'vscode'; vi.mock('vscode'); -vi.mock('@/extension', () => ({ - logger: { - trace: vi.fn(), - debug: vi.fn(), - info: vi.fn(), - warn: vi.fn(), - error: vi.fn(), - }, -})); +const { mockLogger } = await vi.hoisted(() => import('@/test/globalMocks')); +vi.mock('@/extension', mockLogger); describe('updateLineNumAllLogMessagesCommand', () => { let mockEditor: TextEditor | undefined; diff --git a/tsconfig.json b/tsconfig.json index faba107..a0c6ee1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,15 @@ { "compilerOptions": { - "module": "commonjs", - "target": "es2020", + "module": "ESNext", + "target": "ESNext", "outDir": "out", - "lib": ["es2020"], + "lib": ["ESNext"], "sourceMap": true, "rootDir": "src", "baseUrl": "./", "strict": true, "esModuleInterop": true, + "moduleResolution": "Node", "resolveJsonModule": true, "skipLibCheck": true, "paths": {