@@ -154,14 +154,18 @@ func NewNode(in *ClusterInput, index int, networkID string) (*Node, error) {
154
154
}
155
155
node .privateIP = privateIP
156
156
157
- if err := ensureAssetsDir (node ); err != nil {
157
+ if err := ensureTestDirs (node ); err != nil {
158
158
return nil , fmt .Errorf ("ensure assets dir on node %s: %v" , node .Name , err )
159
159
}
160
160
161
161
if err := copyScriptsToNode (node ); err != nil {
162
162
return nil , fmt .Errorf ("copy scripts to node %s: %v" , node .Name , err )
163
163
}
164
164
165
+ if err := copyPlaywrightToNode (node ); err != nil {
166
+ return nil , fmt .Errorf ("copy playwright to node %s: %v" , node .Name , err )
167
+ }
168
+
165
169
if index == 0 {
166
170
in .T .Logf ("exposing port 30003 on node %s" , node .Name )
167
171
hostname , err := exposePort (node , "30003" )
@@ -189,8 +193,8 @@ func discoverPrivateIP(node Node) (string, error) {
189
193
return "" , fmt .Errorf ("find private ip starting with 10." )
190
194
}
191
195
192
- func ensureAssetsDir (node Node ) error {
193
- stdout , stderr , err := runCommandOnNode (node , []string {"mkdir" , "-p" , "/assets" })
196
+ func ensureTestDirs (node Node ) error {
197
+ stdout , stderr , err := runCommandOnNode (node , []string {"mkdir" , "-p" , "/assets" , "/automation/playwright" })
194
198
if err != nil {
195
199
return fmt .Errorf ("create directory: %v: %s: %s" , err , stdout , stderr )
196
200
}
@@ -232,6 +236,47 @@ func copyScriptsToNode(node Node) error {
232
236
return nil
233
237
}
234
238
239
+ func copyPlaywrightToNode (node Node ) error {
240
+ // Create a temporary directory for the archive
241
+ tempDir , err := os .MkdirTemp ("" , "playwright-archive" )
242
+ if err != nil {
243
+ return fmt .Errorf ("create temp directory: %v" , err )
244
+ }
245
+ defer os .RemoveAll (tempDir )
246
+
247
+ // Create the archive, excluding node_modules, test-results, and playwright-report
248
+ archivePath := filepath .Join (tempDir , "playwright.tgz" )
249
+ output , err := exec .Command ("tar" ,
250
+ "--exclude=node_modules" ,
251
+ "--exclude=test-results" ,
252
+ "--exclude=playwright-report" ,
253
+ "-czf" , archivePath ,
254
+ "-C" , "playwright" , "." ,
255
+ ).CombinedOutput ()
256
+ if err != nil {
257
+ return fmt .Errorf ("create playwright archive: %v: %s" , err , string (output ))
258
+ }
259
+
260
+ // Copy the archive to the node
261
+ if err := copyFileToNode (node , archivePath , "/tmp/playwright.tgz" ); err != nil {
262
+ return fmt .Errorf ("copy playwright archive to node: %v" , err )
263
+ }
264
+
265
+ // Extract the archive in /automation
266
+ _ , stderr , err := runCommandOnNode (node , []string {"tar" , "-xzf" , "/tmp/playwright.tgz" , "-C" , "/automation/playwright" })
267
+ if err != nil {
268
+ return fmt .Errorf ("extract playwright archive: %v: %s" , err , stderr )
269
+ }
270
+
271
+ // Clean up the archive on the node
272
+ _ , stderr , err = runCommandOnNode (node , []string {"rm" , "-f" , "/tmp/playwright.tgz" })
273
+ if err != nil {
274
+ return fmt .Errorf ("clean up playwright archive: %v: %s" , err , stderr )
275
+ }
276
+
277
+ return nil
278
+ }
279
+
235
280
func getSSHEndpoint (nodeID string ) (string , error ) {
236
281
output , err := exec .Command ("replicated" , "vm" , "ssh-endpoint" , nodeID ).CombinedOutput ()
237
282
if err != nil {
@@ -353,23 +398,19 @@ func runCommandOnNode(node Node, line []string, envs ...map[string]string) (stri
353
398
return stdout .String (), stderr .String (), err
354
399
}
355
400
356
- func (c * Cluster ) SetupPlaywrightAndRunTest (testName string , args ... string ) (string , string , error ) {
357
- if err := c .SetupPlaywright (); err != nil {
358
- return "" , "" , fmt .Errorf ("setup playwright: %w" , err )
359
- }
360
- return c .RunPlaywrightTest (testName , args ... )
361
- }
362
-
363
- func (c * Cluster ) SetupPlaywright (envs ... map [string ]string ) error {
401
+ func (c * Cluster ) BypassKurlProxy (envs ... map [string ]string ) error {
364
402
c .t .Logf ("%s: bypassing kurl-proxy" , time .Now ().Format (time .RFC3339 ))
365
403
_ , stderr , err := c .RunCommandOnNode (0 , []string {"bypass-kurl-proxy.sh" }, envs ... )
366
404
if err != nil {
367
405
return fmt .Errorf ("bypass kurl-proxy: %v: %s" , err , string (stderr ))
368
406
}
369
- c .t .Logf ("%s: installing playwright" , time .Now ().Format (time .RFC3339 ))
370
- output , err := exec .Command ("sh" , "-c" , "cd playwright && npm ci && npx playwright install --with-deps" ).CombinedOutput ()
371
- if err != nil {
372
- return fmt .Errorf ("install playwright: %v: %s" , err , string (output ))
407
+ return nil
408
+ }
409
+
410
+ func (c * Cluster ) SetupPlaywright (envs ... map [string ]string ) error {
411
+ c .t .Logf ("%s: installing playwright on node 0" , time .Now ().Format (time .RFC3339 ))
412
+ if _ , stderr , err := c .RunCommandOnNode (0 , []string {"install-playwright.sh" }); err != nil {
413
+ return fmt .Errorf ("install playwright on node 0: %v: %s" , err , string (stderr ))
373
414
}
374
415
return nil
375
416
}
@@ -378,10 +419,10 @@ func (c *Cluster) RunPlaywrightTest(testName string, args ...string) (string, st
378
419
c .t .Logf ("%s: running playwright test %s" , time .Now ().Format (time .RFC3339 ), testName )
379
420
cmdArgs := []string {testName }
380
421
cmdArgs = append (cmdArgs , args ... )
381
- cmd := exec .Command ("scripts/ playwright.sh" , cmdArgs ... )
422
+ cmd := exec .Command ("playwright.sh" , cmdArgs ... )
382
423
cmd .Env = os .Environ ()
383
- cmd .Env = append (cmd .Env , fmt . Sprintf ( "BASE_URL=%s" , c . Nodes [ 0 ]. adminConsoleURL ) )
384
- cmd .Env = append (cmd .Env , "PLAYWRIGHT_DIR=. /playwright" )
424
+ cmd .Env = append (cmd .Env , "BASE_URL=http://localhost:30003" )
425
+ cmd .Env = append (cmd .Env , "PLAYWRIGHT_DIR=/automation /playwright" )
385
426
var stdout , stderr bytes.Buffer
386
427
cmd .Stdout = & stdout
387
428
cmd .Stderr = & stderr
0 commit comments