Initial commit: Text Adventure Game
Features: - Combat system with AP/EP hit calculation and three-layer defense - Auto-combat/farming mode - Item system with stacking support - Skill system with levels, milestones, and parent skill sync - Shop system with dynamic pricing - Inventory management with bulk selling - Event system - Game loop with offline earnings - Save/Load system Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
64
tests/helpers/timer.js
Normal file
64
tests/helpers/timer.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 时间相关测试辅助函数
|
||||
*/
|
||||
|
||||
import { vi } from 'vitest'
|
||||
|
||||
/**
|
||||
* Mock Date.now()
|
||||
* @param {number} timestamp - 时间戳
|
||||
* @returns {Object} spy
|
||||
*/
|
||||
export function mockDateNow(timestamp = Date.now()) {
|
||||
return vi.spyOn(Date, 'now').mockReturnValue(timestamp)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock setInterval/setTimeout
|
||||
* @returns {Object} { useFakeTimers, useRealTimers }
|
||||
*/
|
||||
export function mockTimers() {
|
||||
return {
|
||||
useFakeTimers: () => vi.useFakeTimers(),
|
||||
useRealTimers: () => vi.useRealTimers(),
|
||||
runAllTimers: () => vi.runAllTimers(),
|
||||
runOnlyPendingTimers: () => vi.runOnlyPendingTimers(),
|
||||
advanceTimersByTime: (ms) => vi.advanceTimersByTime(ms)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待指定时间
|
||||
* @param {number} ms - 毫秒
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function wait(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速时间(用于测试)
|
||||
* @param {number} seconds - 秒数
|
||||
* @returns {number} 毫秒
|
||||
*/
|
||||
export function seconds(seconds) {
|
||||
return seconds * 1000
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速时间(分钟)
|
||||
* @param {number} minutes - 分钟数
|
||||
* @returns {number} 毫秒
|
||||
*/
|
||||
export function minutes(minutes) {
|
||||
return minutes * 60 * 1000
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速时间(小时)
|
||||
* @param {number} hours - 小时数
|
||||
* @returns {number} 毫秒
|
||||
*/
|
||||
export function hours(hours) {
|
||||
return hours * 60 * 60 * 1000
|
||||
}
|
||||
Reference in New Issue
Block a user