1
+ import { BUT_SERVER_PORT , BUT_TESTING , DESKTOP_PORT } from './env.ts' ;
1
2
import { type BrowserContext } from '@playwright/test' ;
2
3
import { ChildProcess , spawn } from 'node:child_process' ;
3
4
import { existsSync , mkdirSync } from 'node:fs' ;
4
5
import { Socket } from 'node:net' ;
5
6
import path from 'node:path' ;
6
7
7
- const DESKTOP_PORT = process . env . DESKTOP_PORT || '3000' ;
8
- const BUTLER_PORT = process . env . BUTLER_PORT || '6978' ;
9
-
10
8
export function getBaseURL ( ) {
11
9
const parallelId = process . env . TEST_PARALLEL_INDEX ?? '0' ;
12
10
const id = parseInt ( parallelId , 10 ) ;
@@ -18,7 +16,7 @@ export function getBaseURL() {
18
16
export function getButlerPort ( ) : string {
19
17
const parallelId = process . env . TEST_PARALLEL_INDEX ?? '0' ;
20
18
const id = parseInt ( parallelId , 10 ) ;
21
- return `${ parseInt ( BUTLER_PORT , 10 ) + id } ` ;
19
+ return `${ parseInt ( BUT_SERVER_PORT , 10 ) + id } ` ;
22
20
}
23
21
24
22
export interface GitButler {
@@ -49,7 +47,7 @@ class GitButlerManager implements GitButler {
49
47
}
50
48
51
49
this . butServerProcess = spawnProcess ( 'cargo' , [ 'run' , '-p' , 'but-server' ] , this . rootDir , {
52
- E2E_TEST_APP_DATA_DIR : this . configDir || path . join ( this . workdir , 'config' ) ,
50
+ E2E_TEST_APP_DATA_DIR : this . configDir ,
53
51
BUTLER_PORT : getButlerPort ( )
54
52
} ) ;
55
53
@@ -69,9 +67,10 @@ class GitButlerManager implements GitButler {
69
67
}
70
68
71
69
async init ( ) {
72
- const butReady = await waitForServer ( process . env . BUTLER_PORT || '6978' , 'localhost' ) ;
70
+ const port = getButlerPort ( ) ;
71
+ const butReady = await waitForServer ( port , 'localhost' ) ;
73
72
if ( ! butReady ) {
74
- throw new Error ( `Butler server failed to start on localhost:${ process . env . BUTLER_PORT } ` ) ;
73
+ throw new Error ( `Butler server failed to start on localhost:${ port } ` ) ;
75
74
}
76
75
}
77
76
@@ -88,10 +87,16 @@ class GitButlerManager implements GitButler {
88
87
const scriptPath = path . resolve ( this . scriptsDir , scriptName ) ;
89
88
if ( ! existsSync ( scriptPath ) ) log ( `Script not found: ${ scriptPath } ` , colors . red ) ;
90
89
const scriptArgs = args ?? [ ] ;
91
- await runCommand ( 'bash' , [ scriptPath , ...scriptArgs ] , this . workdir ) ;
90
+ await runCommand ( 'bash' , [ scriptPath , ...scriptArgs ] , this . workdir , {
91
+ GITBUTLER_CLI_DATA_DIR : getButlerDataDir ( this . configDir )
92
+ } ) ;
92
93
}
93
94
}
94
95
96
+ function getButlerDataDir ( configDir : string ) : string {
97
+ return path . join ( configDir , 'com.gitbutler.app' ) ;
98
+ }
99
+
95
100
async function waitForServer ( port : string , host = 'localhost' , maxAttempts = 500 ) {
96
101
const parsed = parseInt ( port , 10 ) ;
97
102
@@ -163,6 +168,7 @@ function spawnProcess(
163
168
...process . env ,
164
169
ELECTRON_ENV : 'development' ,
165
170
VITE_BUILD_TARGET : 'web' ,
171
+ BUT_TESTING : BUT_TESTING ,
166
172
VITE_HOST ,
167
173
...env
168
174
}
@@ -192,11 +198,16 @@ async function setProjectPathCookie(context: BrowserContext, workdir: string): P
192
198
] ) ;
193
199
}
194
200
195
- async function runCommand ( command : string , args : string [ ] , cwd = process . cwd ( ) ) {
201
+ async function runCommand (
202
+ command : string ,
203
+ args : string [ ] ,
204
+ cwd = process . cwd ( ) ,
205
+ env : Record < string , string > = { }
206
+ ) : Promise < void > {
196
207
return await new Promise < void > ( ( resolve , reject ) => {
197
208
log ( `Running: ${ command } ${ args . join ( ' ' ) } ` , colors . cyan ) ;
198
209
199
- const child = spawnProcess ( command , args , cwd ) ;
210
+ const child = spawnProcess ( command , args , cwd , env ) ;
200
211
201
212
child . on ( 'message' , ( message ) => {
202
213
log ( `Child process message: ${ message } ` , colors . blue ) ;
0 commit comments