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', + }, + }, + ], }, });