mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-06 13:54:10 +08:00
test: 完善 2.3.0 跨平台测试与 CI 稳定性
- 修复 Windows 与 macOS 单元测试环境差异\n- 完善组件、集成与 Electron E2E 测试\n- 修复异步等待、平台路径和环境依赖问题\n- 统一 E2E 窗口尺寸与 Visual 测试策略\n- 提升 GitHub Actions 跨平台 CI 稳定性
This commit is contained in:
@@ -7,6 +7,7 @@ const root = path.resolve(__dirname, '../../..')
|
||||
const fixture = structuredClone(require(path.join(root, 'tests/fixtures/chat-data.json')))
|
||||
const userData = process.env.WXE_E2E_USER_DATA
|
||||
if (!userData) throw new Error('WXE_E2E_USER_DATA is required')
|
||||
const backgroundE2E = process.env.WXE_E2E_HEADLESS === '1'
|
||||
app.setPath('userData', userData)
|
||||
app.setPath('logs', path.join(userData, 'logs'))
|
||||
app.commandLine.appendSwitch('disable-gpu')
|
||||
@@ -253,6 +254,7 @@ const groupExitEvent = {
|
||||
detectedAt: fixtureNowMs - 60 * 1000
|
||||
}
|
||||
let groupExitMonitorState = {
|
||||
enabled: connected,
|
||||
events: [groupExitEvent],
|
||||
running: connected,
|
||||
nativeMonitorActive: connected,
|
||||
@@ -1215,8 +1217,9 @@ for (const channel of [
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const window = new BrowserWindow({
|
||||
width: 1440,
|
||||
height: 960,
|
||||
// Keep the E2E window aligned with createWindow() in src/main/index.ts.
|
||||
width: 1400,
|
||||
height: 800,
|
||||
show: false,
|
||||
backgroundColor: '#ffffff',
|
||||
webPreferences: {
|
||||
@@ -1226,7 +1229,7 @@ app.whenReady().then(() => {
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
window.once('ready-to-show', () => window.show())
|
||||
if (!backgroundE2E) window.once('ready-to-show', () => window.show())
|
||||
window.loadFile(path.join(root, 'out/renderer/index.html'))
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ export interface TestApplication {
|
||||
app: ElectronApplication
|
||||
page: Page
|
||||
userData: string
|
||||
setWindowContentSize: (size: { width: number; height: number }) => Promise<void>
|
||||
close: () => Promise<void>
|
||||
}
|
||||
|
||||
@@ -60,28 +59,10 @@ export async function launchTestApp(
|
||||
const page = await app.firstWindow()
|
||||
await page.waitForLoadState('domcontentloaded')
|
||||
if (options.now) await page.clock.setFixedTime(options.now)
|
||||
const setWindowContentSize = async (size: { width: number; height: number }): Promise<void> => {
|
||||
await app.evaluate(({ BrowserWindow, screen }, nextSize) => {
|
||||
const [window] = BrowserWindow.getAllWindows()
|
||||
if (!window) throw new Error('E2E BrowserWindow is unavailable')
|
||||
const { workArea } = screen.getPrimaryDisplay()
|
||||
window.setPosition(workArea.x + 40, workArea.y + 40)
|
||||
window.setContentSize(nextSize.width, nextSize.height)
|
||||
}, size)
|
||||
await page.waitForFunction(
|
||||
(nextSize) => window.innerWidth === nextSize.width && window.innerHeight === nextSize.height,
|
||||
size
|
||||
)
|
||||
await page.evaluate(
|
||||
() =>
|
||||
new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))
|
||||
)
|
||||
}
|
||||
return {
|
||||
app,
|
||||
page,
|
||||
userData,
|
||||
setWindowContentSize,
|
||||
close: async () => {
|
||||
if (!page.isClosed() && closeDelayMs > 0) await page.waitForTimeout(closeDelayMs)
|
||||
await app.close().catch(() => undefined)
|
||||
|
||||
Reference in New Issue
Block a user