feat(core): 启用 TypeScript 最严格的类型检查 (#199)
* feat(core): 启用 TypeScript 最严格的类型检查 * ci: 配置 Codecov 以适应类型安全改进 * fix(core): 修复 CodeQL 安全警告 * fix(core): eslint.config.mjs
This commit is contained in:
@@ -49,24 +49,24 @@ describe('DI - 依赖注入装饰器测试', () => {
|
||||
|
||||
describe('@Injectable 装饰器', () => {
|
||||
test('应该正确标记类为可注入', () => {
|
||||
expect(isInjectable(SimpleService)).toBe(true);
|
||||
expect(isInjectable(DependentService)).toBe(true);
|
||||
expect(isInjectable(SimpleService as any)).toBe(true);
|
||||
expect(isInjectable(DependentService as any)).toBe(true);
|
||||
});
|
||||
|
||||
test('未标记的类不应该是可注入的', () => {
|
||||
expect(isInjectable(NonInjectableService)).toBe(false);
|
||||
expect(isInjectable(NonInjectableService as any)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('@Inject 装饰器', () => {
|
||||
test('应该记录参数注入元数据', () => {
|
||||
const metadata = getInjectMetadata(DependentService);
|
||||
const metadata = getInjectMetadata(DependentService as any);
|
||||
expect(metadata.size).toBe(1);
|
||||
expect(metadata.get(0)).toBe(SimpleService);
|
||||
});
|
||||
|
||||
test('应该记录多个参数的注入元数据', () => {
|
||||
const metadata = getInjectMetadata(MultiDependencyService);
|
||||
const metadata = getInjectMetadata(MultiDependencyService as any);
|
||||
expect(metadata.size).toBe(2);
|
||||
expect(metadata.get(0)).toBe(SimpleService);
|
||||
expect(metadata.get(1)).toBe(DependentService);
|
||||
|
||||
@@ -17,7 +17,9 @@ class DependentService {
|
||||
public testService?: TestService;
|
||||
|
||||
constructor(...args: unknown[]) {
|
||||
this.testService = args[0] as TestService | undefined;
|
||||
if (args[0] !== undefined) {
|
||||
this.testService = args[0] as TestService;
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
||||
@@ -507,10 +507,10 @@ describe('ComponentStorageManager - 组件存储管理器测试', () => {
|
||||
expect(allStats.has('PositionComponent')).toBe(true);
|
||||
|
||||
const testStats = allStats.get('TestComponent');
|
||||
expect(testStats.usedSlots).toBe(2);
|
||||
|
||||
expect(testStats?.usedSlots).toBe(2);
|
||||
|
||||
const positionStats = allStats.get('PositionComponent');
|
||||
expect(positionStats.usedSlots).toBe(1);
|
||||
expect(positionStats?.usedSlots).toBe(1);
|
||||
});
|
||||
|
||||
test('应该能够清空所有存储器', () => {
|
||||
@@ -591,7 +591,7 @@ describe('ComponentStorageManager - 组件存储管理器测试', () => {
|
||||
expect(manager.hasComponent(2, TestComponent)).toBe(true);
|
||||
|
||||
const stats = manager.getAllStats();
|
||||
expect(stats.get('TestComponent').usedSlots).toBeLessThan(entityCount);
|
||||
expect(stats.get('TestComponent')?.usedSlots).toBeLessThan(entityCount);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -108,8 +108,8 @@ describe('WorldManager', () => {
|
||||
};
|
||||
|
||||
const world = worldManager.createWorld('configured-world', worldConfig);
|
||||
|
||||
expect(world.name).toBe('ConfiguredWorld');
|
||||
|
||||
expect(world.name).toBe('configured-world');
|
||||
});
|
||||
|
||||
test('重复的World ID应该抛出错误', () => {
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
// 设置测试超时时间(毫秒)
|
||||
jest.setTimeout(10000);
|
||||
|
||||
// 模拟控制台方法以减少测试输出噪音
|
||||
const originalConsoleLog = console.log;
|
||||
const originalConsoleWarn = console.warn;
|
||||
const originalConsoleError = console.error;
|
||||
|
||||
// 在测试环境中可以选择性地静默某些日志
|
||||
beforeAll(() => {
|
||||
// 在测试开始前确保 WorldManager 使用无定时器配置
|
||||
|
||||
Reference in New Issue
Block a user