Skip to content

Commit affc9d3

Browse files
committed
fix(regression-test): stabilize Windows selection and restart
Signed-off-by: kangfenmao <kangfenmao@qq.com>
1 parent d8c4a59 commit affc9d3

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

scripts/cherry-regression-test/__tests__/lifecycle.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ describe('owned application lifecycle', () => {
117117
execFileSyncMock.mockImplementation((file: string, args: string[]) => {
118118
const script = String(args.at(-1))
119119
if (file === 'taskkill.exe') {
120-
alive.delete(Number(args[1]))
120+
if (Number(args[1]) === runnerPid) alive.clear()
121+
else alive.delete(Number(args[1]))
121122
return ''
122123
}
123124
if (script.includes('Get-NetTCPConnection')) return String(electronPid)
@@ -128,7 +129,7 @@ describe('owned application lifecycle', () => {
128129

129130
try {
130131
await stopOwnedApp(paths)
131-
expect(execFileSyncMock).toHaveBeenCalledWith(
132+
expect(execFileSyncMock).not.toHaveBeenCalledWith(
132133
'taskkill.exe',
133134
['/PID', String(electronPid), '/T', '/F'],
134135
expect.anything()
@@ -182,7 +183,8 @@ describe('owned application lifecycle', () => {
182183
execFileSyncMock.mockImplementation((file: string, args: string[]) => {
183184
const script = String(args.at(-1))
184185
if (file === 'taskkill.exe') {
185-
alive.delete(Number(args[1]))
186+
if (Number(args[1]) === runnerPid) alive.clear()
187+
else alive.delete(Number(args[1]))
186188
return ''
187189
}
188190
if (script.includes('Get-NetTCPConnection')) return String(currentElectronPid)
@@ -202,12 +204,12 @@ describe('owned application lifecycle', () => {
202204
await stopOwnedApp(paths)
203205
expect(execFileSyncMock).toHaveBeenCalledWith(
204206
'taskkill.exe',
205-
['/PID', String(currentElectronPid), '/T', '/F'],
207+
['/PID', String(runnerPid), '/T', '/F'],
206208
expect.anything()
207209
)
208-
expect(execFileSyncMock).toHaveBeenCalledWith(
210+
expect(execFileSyncMock).not.toHaveBeenCalledWith(
209211
'taskkill.exe',
210-
['/PID', String(runnerPid), '/T', '/F'],
212+
['/PID', String(currentElectronPid), '/T', '/F'],
211213
expect.anything()
212214
)
213215
} finally {

scripts/cherry-regression-test/lifecycle.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ export async function stopOwnedApp(paths: RunPaths): Promise<void> {
566566
throw new Error('Refusing cleanup because the recorded Electron process is no longer owned by its runner')
567567
}
568568
}
569-
for (const pid of ownedPids) {
569+
const terminationPids = record.platform === 'windows' ? [record.runnerPid, ...ownedPids] : ownedPids
570+
for (const pid of new Set(terminationPids)) {
570571
if (!isAlive(pid)) continue
571572
try {
572573
terminateExactProcess(pid, record.platform)

scripts/cherry-regression-test/system-automation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { RunPaths } from './paths'
77
import { resolveAllowedPath } from './paths'
88
import type { Platform } from './types'
99

10-
const ALLOWED_KEYS = new Set(['Alt', 'Control', 'Enter', 'Escape', 'F8', 'Meta', 'Shift', 'Space', 'a', 'e', 'k', 's'])
10+
const ALLOWED_KEYS = new Set(['Alt', 'Control', 'Enter', 'Escape', 'Meta', 'Shift', 'Space', 'a', 'e', 'k', 's'])
1111
let activeWindowsExternalTextPid: number | undefined
1212

1313
function escapePowerShell(value: string): string {
@@ -48,7 +48,6 @@ function runWindowsHotkey(keys: string[]): void {
4848
Control: 0x11,
4949
Enter: 0x0d,
5050
Escape: 0x1b,
51-
F8: 0x77,
5251
Meta: 0x5b,
5352
Shift: 0x10,
5453
Space: 0x20

tests/e2e/cherry-regression/05-desktop-assistants.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ test('[C-03] 使用划词助手处理跨应用选中文本 @selection-assistant'
9898
}
9999
],
100100
'feature.selection.enabled': true,
101-
'feature.selection.trigger_mode': 'shortcut',
101+
'feature.selection.trigger_mode': platform === 'windows' ? 'selected' : 'shortcut',
102102
'shortcut.selection.capture_text': {
103-
binding: platform === 'windows' ? ['F8'] : ['CommandOrControl', 'Shift', 'K'],
104-
enabled: true
103+
binding: ['CommandOrControl', 'Shift', 'K'],
104+
enabled: platform !== 'windows'
105105
}
106106
})
107107
},
@@ -127,10 +127,10 @@ test('[C-03] 使用划词助手处理跨应用选中文本 @selection-assistant'
127127
await expect
128128
.poll(
129129
async () => {
130-
sendSystemHotkey(app.record.platform, [
131-
...(app.record.platform === 'macos' ? ['Meta', 'Shift'] : []),
132-
app.record.platform === 'windows' ? 'F8' : 'k'
133-
])
130+
sendSystemHotkey(
131+
app.record.platform,
132+
app.record.platform === 'macos' ? ['Meta', 'Shift', 'k'] : ['Control', 'a']
133+
)
134134
await selection.waitForTimeout(1_000)
135135
return selection.locator('body').getAttribute('data-selected-text')
136136
},

0 commit comments

Comments
 (0)