Skip to content

Commit 47b1e2a

Browse files
committed
🐛 fix: 修复 CI/CD 流水线中的 TypeScript 类型错误
- 添加缺失的 expect 导入到 test-helpers.ts - 添加缺失的 afterEach 导入到 performance 测试 - 添加缺失的 beforeEach 导入到 setup.ts - 修复 LocalStorageMock 中的 this 上下文问题 - 更新 config.ts 以适配重构后的 ConfigResult 类型 - 所有测试通过 ✅ - TypeScript 类型检查通过 ✅
1 parent 0cd0e79 commit 47b1e2a

4 files changed

Lines changed: 28 additions & 24 deletions

File tree

‎tests/setup.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* 测试环境设置
33
*/
44

5-
import { vi } from 'vitest'
5+
import { beforeEach, vi } from 'vitest'
66

77
// Mock console methods to avoid noise in tests
88
global.console = {

‎tests/utils/config-helpers.performance.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview config-helpers.ts 模块的性能和压力测试
33
*/
44

5-
import { beforeEach, describe, expect, it, vi } from 'vitest'
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
66
import {
77
fetchConfigFromServer,
88
getConfig,

‎tests/utils/test-helpers.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview 测试辅助工具和 Mock 函数
33
*/
44

5-
import { vi } from 'vitest'
5+
import { expect, vi } from 'vitest'
66
import type { SiteConfig } from '~/types/config'
77

88
// ============================================================================
@@ -147,21 +147,22 @@ export class LocalStorageMock {
147147
}
148148

149149
private createMockStorage() {
150+
const self = this
150151
return {
151-
getItem: (key: string) => this.store[key] || null,
152+
getItem: (key: string) => self.store[key] || null,
152153
setItem: (key: string, value: string) => {
153-
this.store[key] = value
154+
self.store[key] = value
154155
},
155156
removeItem: (key: string) => {
156-
delete this.store[key]
157+
delete self.store[key]
157158
},
158159
clear: () => {
159-
this.store = {}
160+
self.store = {}
160161
},
161162
get length() {
162-
return Object.keys(this.store).length
163+
return Object.keys(self.store).length
163164
},
164-
key: (index: number) => Object.keys(this.store)[index] || null,
165+
key: (index: number) => Object.keys(self.store)[index] || null,
165166
}
166167
}
167168
}

‎utils/config.ts‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,20 @@ export const configManager = {
2929
// 获取当前host配置
3030
getCurrentHostConfig(): SiteConfig {
3131
// 优先使用localStorage中保存的配置
32-
const storedConfig = getStoredHostConfig();
33-
if (storedConfig) {
34-
return storedConfig;
32+
const storedResult = getStoredHostConfig();
33+
if (storedResult.config) {
34+
return storedResult.config;
3535
}
3636

3737
// 使用当前浏览器地址
38-
const browserConfig = getCurrentBrowserConfig();
39-
if (browserConfig) {
40-
return browserConfig;
38+
const browserResult = getCurrentBrowserConfig();
39+
if (browserResult.config) {
40+
return browserResult.config;
4141
}
4242

4343
// 服务端fallback
44-
return getServerDefaultConfig();
44+
const defaultResult = getServerDefaultConfig();
45+
return defaultResult.config!;
4546
},
4647

4748
// 从 nuxt runtimeconfig 读取配置
@@ -78,7 +79,8 @@ export const configManager = {
7879
// 从服务器获取配置 (当前浏览器host:9001/config.json)
7980
async loadConfigFromServer(): Promise<SiteConfig | null> {
8081
try {
81-
return await fetchConfigFromServer();
82+
const result = await fetchConfigFromServer();
83+
return result.config;
8284
} catch (error) {
8385
const configError = handleConfigError(error, 'server config loading');
8486
logger.warn('Failed to load config from server:', configError.message);
@@ -97,27 +99,28 @@ export const configManager = {
9799
let config: SiteConfig;
98100

99101
// 1. 优先使用localStorage中保存的配置
100-
const storedConfig = getStoredHostConfig();
101-
if (storedConfig) {
102-
config = storedConfig;
102+
const storedResult = getStoredHostConfig();
103+
if (storedResult.config) {
104+
config = storedResult.config;
103105
} else {
104106
// 2. 尝试从服务器获取配置 (当前浏览器host:9001/config.json)
105107
const serverConfig = await this.loadConfigFromServer();
106108
if (serverConfig) {
107109
config = serverConfig;
108110
} else {
109111
// 3. 使用当前浏览器地址
110-
const browserConfig = getCurrentBrowserConfig();
111-
if (browserConfig) {
112-
config = browserConfig;
112+
const browserResult = getCurrentBrowserConfig();
113+
if (browserResult.config) {
114+
config = browserResult.config;
113115
} else {
114116
// 4. 使用 runtimeconfig
115117
const runtimeConfig = this.loadRuntimeConfig();
116118
if (runtimeConfig) {
117119
config = runtimeConfig;
118120
} else {
119121
// 5. 最后使用服务端默认值
120-
config = getServerDefaultConfig();
122+
const defaultResult = getServerDefaultConfig();
123+
config = defaultResult.config!;
121124
}
122125
}
123126
}

0 commit comments

Comments
 (0)