88// This is Node.js test infrastructure, not extension code
99import type { WorkerFixtures , TestFixtures } from './desktopFixtureTypes' ;
1010import { test as base , _electron as electron } from '@playwright/test' ;
11- import { downloadAndUnzipVSCode } from '@vscode/test-electron' ;
11+ import * as Duration from 'effect/Duration' ;
12+ import * as Effect from 'effect/Effect' ;
1213import type { ChildProcess } from 'node:child_process' ;
1314import * as fs from 'node:fs/promises' ;
1415import * as path from 'node:path' ;
1516
17+ import { downloadVSCodeWithRetry } from '../utils/downloadUtils' ;
1618import { filterErrors } from '../utils/helpers' ;
1719import { resolveRepoRoot } from '../utils/repoRoot' ;
1820import { createEmptyTestWorkspace , createTestWorkspace } from './desktopWorkspace' ;
@@ -30,7 +32,12 @@ const CLOSE_TIMEOUT_MS = 5000;
3032const forceKillProcessGroup = ( proc : ChildProcess ) : void => {
3133 const { pid } = proc ;
3234 if ( typeof pid !== 'number' ) return ;
33- try { process . kill ( - pid , 'SIGKILL' ) ; } catch { }
35+
36+ try {
37+ process . kill ( - pid , 'SIGKILL' ) ;
38+ } catch {
39+ // ignore
40+ }
3441 proc . stdin ?. destroy ( ) ;
3542 proc . stdout ?. destroy ( ) ;
3643 proc . stderr ?. destroy ( ) ;
@@ -69,7 +76,8 @@ export const createDesktopTest = (options: CreateDesktopTestOptions) => {
6976 const repoRoot = resolveRepoRoot ( fixturesDir ) ;
7077 const cachePath = path . join ( repoRoot , '.vscode-test' ) ;
7178 const version = process . env . PLAYWRIGHT_DESKTOP_VSCODE_VERSION ?? undefined ;
72- const executablePath = await downloadAndUnzipVSCode ( { version, cachePath } ) ;
79+
80+ const executablePath = await Effect . runPromise ( downloadVSCodeWithRetry ( version , cachePath ) ) ;
7381 await use ( executablePath ) ;
7482 } ,
7583 { scope : 'worker' }
@@ -93,10 +101,7 @@ export const createDesktopTest = (options: CreateDesktopTestOptions) => {
93101 if ( Object . keys ( effectiveUserSettings ) . length > 0 ) {
94102 const userSettingsDir = path . join ( userDataDir , 'User' ) ;
95103 await fs . mkdir ( userSettingsDir , { recursive : true } ) ;
96- await fs . writeFile (
97- path . join ( userSettingsDir , 'settings.json' ) ,
98- JSON . stringify ( effectiveUserSettings , null , 2 )
99- ) ;
104+ await fs . writeFile ( path . join ( userSettingsDir , 'settings.json' ) , JSON . stringify ( effectiveUserSettings , null , 2 ) ) ;
100105 }
101106 const extensionsDir = path . join ( workspaceDir , '.vscode-test-extensions' ) ;
102107 await fs . mkdir ( extensionsDir , { recursive : true } ) ;
@@ -151,22 +156,29 @@ export const createDesktopTest = (options: CreateDesktopTestOptions) => {
151156 forceKillProcessGroup ( proc ) ;
152157 // Wait for Node.js to register the exit (pipes closed → 'close' event → 'exit' event)
153158 await new Promise < void > ( resolve => {
154- if ( proc . exitCode !== null ) { resolve ( ) ; return ; }
159+ if ( proc . exitCode !== null ) {
160+ resolve ( ) ;
161+ return ;
162+ }
155163 proc . on ( 'close' , ( ) => resolve ( ) ) ;
156164 setTimeout ( resolve , 10_000 ) ;
157165 } ) ;
158166 }
159167 console . log ( `[teardown] exitCode=${ proc ?. exitCode } killed=${ proc ?. killed } ` ) ;
160168 } else {
161- try {
162- await Promise . race ( [
163- electronApp . close ( ) ,
164- new Promise < false > ( resolve => setTimeout ( ( ) => resolve ( false ) , CLOSE_TIMEOUT_MS ) )
165- ] ) ;
166- } catch { }
169+ await Effect . runPromise (
170+ Effect . tryPromise ( ( ) => electronApp . close ( ) ) . pipe (
171+ Effect . timeout ( Duration . millis ( CLOSE_TIMEOUT_MS ) ) ,
172+ Effect . catchAll ( ( ) => Effect . void )
173+ )
174+ ) ;
167175 // Force-kill if close didn't work (Windows timeout fallback)
168176 if ( proc ?. exitCode === null && process . platform === 'win32' ) {
169- try { process . kill ( proc . pid ! , 'SIGKILL' ) ; } catch { }
177+ try {
178+ process . kill ( proc . pid ! , 'SIGKILL' ) ;
179+ } catch {
180+ // ignore
181+ }
170182 }
171183 }
172184 console . log ( '[teardown] done' ) ;
0 commit comments