From d7bd034d7dcfaff5c9ee7ec447c95ea908fa59d6 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Fri, 14 Nov 2025 12:23:49 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 显式导入相关依赖以避免相关问题 --- app/utils/file.test.ts | 1 + server/mappers/documentMapper.ts | 2 ++ server/mappers/productMapper.ts | 1 + server/mappers/questionMapper.ts | 2 ++ server/mappers/solutionMapper.ts | 2 ++ server/utils/object.test.ts | 1 + ...rter.test.ts => search-converters.test.ts} | 3 +- vitest.config.ts | 35 +++++++++++++++++-- 8 files changed, 43 insertions(+), 4 deletions(-) rename server/utils/{search-converter.test.ts => search-converters.test.ts} (96%) diff --git a/app/utils/file.test.ts b/app/utils/file.test.ts index e95541a..42dff6d 100644 --- a/app/utils/file.test.ts +++ b/app/utils/file.test.ts @@ -1,4 +1,5 @@ import { expect, test, describe } from 'vitest'; +import { formatFileSize, getFileExtension, formatFileExtension } from './file'; /** * 单元测试: formatFileSize diff --git a/server/mappers/documentMapper.ts b/server/mappers/documentMapper.ts index d1d7113..88ca391 100644 --- a/server/mappers/documentMapper.ts +++ b/server/mappers/documentMapper.ts @@ -1,3 +1,5 @@ +import { isObject } from '../../server/utils/object'; + /** * 将 Directus 返回的 Document 数据转换为 ProductDocumentView 视图模型 * diff --git a/server/mappers/productMapper.ts b/server/mappers/productMapper.ts index 138659c..2fe637f 100644 --- a/server/mappers/productMapper.ts +++ b/server/mappers/productMapper.ts @@ -1,5 +1,6 @@ import { toProductQuestionView } from './questionMapper'; import { toProductDocumentView } from './documentMapper'; +import { isObject } from '../../server/utils/object'; /** * 将Directus返回的ProductType数据转换为ProductTypeView视图模型 diff --git a/server/mappers/questionMapper.ts b/server/mappers/questionMapper.ts index 497ca0f..1af5d66 100644 --- a/server/mappers/questionMapper.ts +++ b/server/mappers/questionMapper.ts @@ -1,3 +1,5 @@ +import { isObject } from '../../server/utils/object'; + /** * 将 Directus 返回的 Question 数据转换为 ProductQuestionView 视图模型 * diff --git a/server/mappers/solutionMapper.ts b/server/mappers/solutionMapper.ts index 9352092..b0a5331 100644 --- a/server/mappers/solutionMapper.ts +++ b/server/mappers/solutionMapper.ts @@ -1,3 +1,5 @@ +import { isObject } from '../../server/utils/object'; + /** * 将 Directus 返回的 SolutionType 数据转换为 SolutionTypeView 视图模型 * diff --git a/server/utils/object.test.ts b/server/utils/object.test.ts index b217543..0ee1429 100644 --- a/server/utils/object.test.ts +++ b/server/utils/object.test.ts @@ -1,4 +1,5 @@ import { expect, test, describe } from 'vitest'; +import { isObject, isArrayOfObject } from './object'; /** * 单元测试: isObject diff --git a/server/utils/search-converter.test.ts b/server/utils/search-converters.test.ts similarity index 96% rename from server/utils/search-converter.test.ts rename to server/utils/search-converters.test.ts index 5e079ab..07d0ee5 100644 --- a/server/utils/search-converter.test.ts +++ b/server/utils/search-converters.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'vitest'; +import { converters } from './search-converters'; /** * 单元测试: converters @@ -69,7 +70,7 @@ describe('converters', () => { expect(result).toEqual({ id: 'TEST-UUID', title: 'User Manual', - summary: undefined, + summary: '', type: 'document', }); }); diff --git a/vitest.config.ts b/vitest.config.ts index b519c1f..39d4ffc 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,7 +1,36 @@ -import { defineVitestConfig } from '@nuxt/test-utils/config'; +import { defineConfig } from 'vitest/config'; +import { defineVitestProject } from '@nuxt/test-utils/config'; -export default defineVitestConfig({ +export default defineConfig({ test: { - environment: 'nuxt', + globals: true, + projects: [ + { + test: { + name: 'unit', + include: [ + 'app/**/*.test.ts', + 'app/**/*.spec.ts', + 'server/**/*.test.ts', + 'server/**/*.spec.ts', + ], + environment: 'node', + }, + }, + await defineVitestProject({ + test: { + name: 'nuxt', + include: ['tests/nuxt/**/*.{test,spec}.ts'], + environment: 'nuxt', + }, + }), + { + test: { + name: 'e2e', + include: ['test/e2e/*.{test,spec}.ts'], + environment: 'node', + }, + }, + ], }, }); -- 2.49.0