mirror of
https://github.com/motajs/template.git
synced 2026-11-26 07:55:02 +08:00
test(08-01): migrate data-layer tests into __test__ dirs
Move 65 *.test.ts + 6 *.perf.ts across data-{common,base,system,state} into sibling __test__/ (data-state/test -> data-state/__test__), incl. fixtures/floors.json and non-test helpers; rewrite Rule A relative specifiers (+1 depth), keep Rule B unchanged; sync script/test-data-node.ts require paths. Gates: test:ci=66 files, test:perf=6 files, eslint clean, zero config/production changes.
This commit is contained in:
1 parent
109fad3b29
commit
36d8b4fb3c
75 files changed
+201
-201
No files matched your search
+4
-4
@@ -2,7 +2,7 @@
|
||||
import { beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
interface TestModules {
|
||||
CoreState: typeof import('./core').CoreState;
|
||||
CoreState: typeof import('../core').CoreState;
|
||||
}
|
||||
|
||||
interface FakeLayer {
|
||||
@@ -44,7 +44,7 @@ interface CoreInitializer {
|
||||
initMapState(floors: string[], data: Record<string, LegacyFloor>): void;
|
||||
}
|
||||
|
||||
vi.mock('./enemy', () => ({
|
||||
vi.mock('../enemy', () => ({
|
||||
CommonAuraConverter: class {},
|
||||
EnemyLegacyBridge: class {},
|
||||
GuardAuraConverter: class {},
|
||||
@@ -56,7 +56,7 @@ vi.mock('./enemy', () => ({
|
||||
registerSpecials: vi.fn()
|
||||
}));
|
||||
|
||||
vi.mock('./legacy', () => ({
|
||||
vi.mock('../legacy', () => ({
|
||||
ItemLegacyBridge: class {},
|
||||
TileLegacyBridge: class {}
|
||||
}));
|
||||
@@ -66,7 +66,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const coreModule = await import('./core');
|
||||
const coreModule = await import('../core');
|
||||
modules = { CoreState: coreModule.CoreState };
|
||||
});
|
||||
|
||||
+6
-6
@@ -13,7 +13,7 @@ import {
|
||||
type IReadonlyEnemy,
|
||||
type ISpecial
|
||||
} from '@user/data-base';
|
||||
import { type IHaloValue } from './special';
|
||||
import { type IHaloValue } from '../special';
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
@@ -42,10 +42,10 @@ vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
CommonAura: typeof import('./aura').CommonAura;
|
||||
CommonAuraConverter: typeof import('./aura').CommonAuraConverter;
|
||||
GuardAura: typeof import('./aura').GuardAura;
|
||||
GuardAuraConverter: typeof import('./aura').GuardAuraConverter;
|
||||
CommonAura: typeof import('../aura').CommonAura;
|
||||
CommonAuraConverter: typeof import('../aura').CommonAuraConverter;
|
||||
GuardAura: typeof import('../aura').GuardAura;
|
||||
GuardAuraConverter: typeof import('../aura').GuardAuraConverter;
|
||||
FullRange: typeof import('@motajs/common').FullRange;
|
||||
RectRange: typeof import('@motajs/common').RectRange;
|
||||
ManhattanRange: typeof import('@motajs/common').ManhattanRange;
|
||||
@@ -56,7 +56,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const auraModule = await import('./aura');
|
||||
const auraModule = await import('../aura');
|
||||
const motaModule = await import('@motajs/common');
|
||||
modules = {
|
||||
CommonAura: auraModule.CommonAura,
|
||||
+2
-2
@@ -41,7 +41,7 @@ vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
MainDamageCalculator: typeof import('./calculator').MainDamageCalculator;
|
||||
MainDamageCalculator: typeof import('../calculator').MainDamageCalculator;
|
||||
logger: typeof import('@motajs/common').logger;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const calculatorModule = await import('./calculator');
|
||||
const calculatorModule = await import('../calculator');
|
||||
const motaModule = await import('@motajs/common');
|
||||
modules = {
|
||||
MainDamageCalculator: calculatorModule.MainDamageCalculator,
|
||||
+2
-2
@@ -30,7 +30,7 @@ vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
MainEnemyComparer: typeof import('./comparer').MainEnemyComparer;
|
||||
MainEnemyComparer: typeof import('../comparer').MainEnemyComparer;
|
||||
}
|
||||
|
||||
let modules: TestModules;
|
||||
@@ -38,7 +38,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const comparerModule = await import('./comparer');
|
||||
const comparerModule = await import('../comparer');
|
||||
modules = {
|
||||
MainEnemyComparer: comparerModule.MainEnemyComparer
|
||||
};
|
||||
+2
-2
@@ -31,7 +31,7 @@ vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
MainEnemyFinalEffect: typeof import('./final').MainEnemyFinalEffect;
|
||||
MainEnemyFinalEffect: typeof import('../final').MainEnemyFinalEffect;
|
||||
}
|
||||
|
||||
let modules: TestModules;
|
||||
@@ -39,7 +39,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const finalModule = await import('./final');
|
||||
const finalModule = await import('../final');
|
||||
modules = {
|
||||
MainEnemyFinalEffect: finalModule.MainEnemyFinalEffect
|
||||
};
|
||||
+11
-11
@@ -13,7 +13,7 @@ import {
|
||||
type IReadonlyHeroAttribute,
|
||||
type ISpecial
|
||||
} from '@user/data-base';
|
||||
import { type IZoneValue } from './special';
|
||||
import { type IZoneValue } from '../special';
|
||||
|
||||
const testGlobals = vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
@@ -45,14 +45,14 @@ const testGlobals = vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
ZoneDamageView: typeof import('./mapDamage').ZoneDamageView;
|
||||
RepulseDamageView: typeof import('./mapDamage').RepulseDamageView;
|
||||
LaserDamageView: typeof import('./mapDamage').LaserDamageView;
|
||||
BetweenDamageView: typeof import('./mapDamage').BetweenDamageView;
|
||||
AmbushDamageView: typeof import('./mapDamage').AmbushDamageView;
|
||||
MainMapDamageConverter: typeof import('./mapDamage').MainMapDamageConverter;
|
||||
MainMapDamageReducer: typeof import('./mapDamage').MainMapDamageReducer;
|
||||
MapDamageType: typeof import('./types').MapDamageType;
|
||||
ZoneDamageView: typeof import('../mapDamage').ZoneDamageView;
|
||||
RepulseDamageView: typeof import('../mapDamage').RepulseDamageView;
|
||||
LaserDamageView: typeof import('../mapDamage').LaserDamageView;
|
||||
BetweenDamageView: typeof import('../mapDamage').BetweenDamageView;
|
||||
AmbushDamageView: typeof import('../mapDamage').AmbushDamageView;
|
||||
MainMapDamageConverter: typeof import('../mapDamage').MainMapDamageConverter;
|
||||
MainMapDamageReducer: typeof import('../mapDamage').MainMapDamageReducer;
|
||||
MapDamageType: typeof import('../types').MapDamageType;
|
||||
ManhattanRange: typeof import('@motajs/common').ManhattanRange;
|
||||
RectRange: typeof import('@motajs/common').RectRange;
|
||||
FaceGroup: typeof import('@user/data-common').FaceGroup;
|
||||
@@ -63,8 +63,8 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const mapDamageModule = await import('./mapDamage');
|
||||
const typesModule = await import('./types');
|
||||
const mapDamageModule = await import('../mapDamage');
|
||||
const typesModule = await import('../types');
|
||||
const motaModule = await import('@motajs/common');
|
||||
const commonModule = await import('@user/data-common');
|
||||
modules = {
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
// 测试怪物特殊属性注册:代码 0-27 全量注册、守卫默认值、名称与描述生成
|
||||
import { beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
import { type ISpecial } from '@user/data-base';
|
||||
import { type IHaloValue } from './special';
|
||||
import { type IHaloValue } from '../special';
|
||||
|
||||
vi.hoisted(() => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
@@ -30,7 +30,7 @@ vi.hoisted(() => {
|
||||
});
|
||||
|
||||
interface TestModules {
|
||||
registerSpecials: typeof import('./special').registerSpecials;
|
||||
registerSpecials: typeof import('../special').registerSpecials;
|
||||
}
|
||||
|
||||
let modules: TestModules;
|
||||
@@ -38,7 +38,7 @@ let modules: TestModules;
|
||||
beforeAll(async () => {
|
||||
vi.stubGlobal('main', { replayChecking: true });
|
||||
vi.stubGlobal('location', { origin: 'http://localhost' });
|
||||
const specialModule = await import('./special');
|
||||
const specialModule = await import('../special');
|
||||
modules = { registerSpecials: specialModule.registerSpecials };
|
||||
});
|
||||
|
||||
+7
-7
@@ -9,7 +9,7 @@ import {
|
||||
TileType
|
||||
} from '@user/data-common';
|
||||
import { BlockEventType, IBlockEventEnv } from '@user/data-system';
|
||||
import { CoreState } from '../core';
|
||||
import { CoreState } from '../../core';
|
||||
import {
|
||||
createEventRegistrations,
|
||||
EventRemoveBlock,
|
||||
@@ -19,10 +19,10 @@ import {
|
||||
EventMoveHero,
|
||||
EventStepHero,
|
||||
EventSetBlock
|
||||
} from './index';
|
||||
import { EventSetBlock as MapEventSetBlock } from './map';
|
||||
import { EventInsertEvent as ControlEventInsertEvent } from './event';
|
||||
import * as dataStateRoot from '../index';
|
||||
} from '../index';
|
||||
import { EventSetBlock as MapEventSetBlock } from '../map';
|
||||
import { EventInsertEvent as ControlEventInsertEvent } from '../event';
|
||||
import * as dataStateRoot from '../../index';
|
||||
|
||||
interface EventFixture {
|
||||
readonly state: CoreState;
|
||||
@@ -317,11 +317,11 @@ describe('event registration ownership', () => {
|
||||
// 验证事件 barrel 仅含导出语句且既有公开事件符号仍可从根索引导入
|
||||
it('keeps both barrels export-only and preserves public event symbols', () => {
|
||||
const eventBarrel = readFileSync(
|
||||
new URL('./index.ts', import.meta.url),
|
||||
new URL('../index.ts', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
const rootBarrel = readFileSync(
|
||||
new URL('../index.ts', import.meta.url),
|
||||
new URL('../../index.ts', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
expect(eventBarrel).not.toMatch(/^\s*import\s/m);
|
||||
+6
-6
@@ -12,15 +12,15 @@ import {
|
||||
} from '@user/data-common';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { createCoreState } from '../core';
|
||||
import { ReplaySystem } from '../../../data-common/src/replay/system';
|
||||
import { createCoreState } from '../../core';
|
||||
import { ReplaySystem } from '../../../../data-common/src/replay/system';
|
||||
import {
|
||||
ReplayEquip,
|
||||
ReplayMove,
|
||||
ReplayTeleport,
|
||||
ReplayUnequip,
|
||||
ReplayUseItem
|
||||
} from './commands';
|
||||
} from '../commands';
|
||||
|
||||
/** 供测试读取的稳定指令码顺序 */
|
||||
export const REPLAY_COMMAND_ORDER: readonly ReplayCode[] = [
|
||||
@@ -332,7 +332,7 @@ describe('replay commands', () => {
|
||||
// 验证注册直接写在 CoreState 内,且指令模块自包含、不含 replay safety
|
||||
it('keeps registration direct and the command module self-contained', () => {
|
||||
const commands = readFileSync(
|
||||
new URL('./commands.ts', import.meta.url),
|
||||
new URL('../commands.ts', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
expect(commands).not.toContain('createReplayCommandItems');
|
||||
@@ -343,7 +343,7 @@ describe('replay commands', () => {
|
||||
expect(commands).not.toContain('shouldReplay');
|
||||
|
||||
const core = readFileSync(
|
||||
new URL('../core.ts', import.meta.url),
|
||||
new URL('../../core.ts', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
expect(core).not.toContain('createReplayCommandItems');
|
||||
@@ -430,7 +430,7 @@ describe('replay safety decorators', () => {
|
||||
it('does not change user-owned attribute decorator placement', () => {
|
||||
const source = readFileSync(
|
||||
new URL(
|
||||
'../../../data-base/src/hero/attribute.ts',
|
||||
'../../../../data-base/src/hero/attribute.ts',
|
||||
import.meta.url
|
||||
),
|
||||
'utf8'
|
||||
Reference in new issue
Block a user