From b8c0ad30b5dc13c817e474ccbece808eeaf651ed Mon Sep 17 00:00:00 2001 From: ygqygq2 Date: Sun, 31 Mar 2024 00:06:48 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=85=AC=E5=85=B1=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ygqygq2 --- .editorconfig | 4 +--- src/test/globalMocks.ts | 13 ++++++++++++ .../commands/commentAllLogMessages.spec.ts | 21 +++---------------- .../commands/deleteAllLogMessages.spec.ts | 11 ++-------- .../unit/commands/displayLogMessage.spec.ts | 11 ++-------- .../commands/uncommentAllLogMessages.spec.ts | 11 ++-------- .../updateLineNumAllLogMessages.spec.ts | 11 ++-------- tsconfig.json | 7 ++++--- 8 files changed, 29 insertions(+), 60 deletions(-) create mode 100644 src/test/globalMocks.ts 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": {