@@ -154,14 +154,18 @@ func NewNode(in *ClusterInput, index int, networkID string) (*Node, error) {
154154 }
155155 node .privateIP = privateIP
156156
157- if err := ensureAssetsDir (node ); err != nil {
157+ if err := ensureTestDirs (node ); err != nil {
158158 return nil , fmt .Errorf ("ensure assets dir on node %s: %v" , node .Name , err )
159159 }
160160
161161 if err := copyScriptsToNode (node ); err != nil {
162162 return nil , fmt .Errorf ("copy scripts to node %s: %v" , node .Name , err )
163163 }
164164
165+ if err := copyPlaywrightToNode (node ); err != nil {
166+ return nil , fmt .Errorf ("copy playwright to node %s: %v" , node .Name , err )
167+ }
168+
165169 if index == 0 {
166170 in .T .Logf ("exposing port 30003 on node %s" , node .Name )
167171 hostname , err := exposePort (node , "30003" )
@@ -189,8 +193,8 @@ func discoverPrivateIP(node Node) (string, error) {
189193 return "" , fmt .Errorf ("find private ip starting with 10." )
190194}
191195
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" })
194198 if err != nil {
195199 return fmt .Errorf ("create directory: %v: %s: %s" , err , stdout , stderr )
196200 }
@@ -232,6 +236,47 @@ func copyScriptsToNode(node Node) error {
232236 return nil
233237}
234238
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+
235280func getSSHEndpoint (nodeID string ) (string , error ) {
236281 output , err := exec .Command ("replicated" , "vm" , "ssh-endpoint" , nodeID ).CombinedOutput ()
237282 if err != nil {
@@ -353,23 +398,19 @@ func runCommandOnNode(node Node, line []string, envs ...map[string]string) (stri
353398 return stdout .String (), stderr .String (), err
354399}
355400
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 {
364402 c .t .Logf ("%s: bypassing kurl-proxy" , time .Now ().Format (time .RFC3339 ))
365403 _ , stderr , err := c .RunCommandOnNode (0 , []string {"bypass-kurl-proxy.sh" }, envs ... )
366404 if err != nil {
367405 return fmt .Errorf ("bypass kurl-proxy: %v: %s" , err , string (stderr ))
368406 }
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 ))
373414 }
374415 return nil
375416}
@@ -378,10 +419,10 @@ func (c *Cluster) RunPlaywrightTest(testName string, args ...string) (string, st
378419 c .t .Logf ("%s: running playwright test %s" , time .Now ().Format (time .RFC3339 ), testName )
379420 cmdArgs := []string {testName }
380421 cmdArgs = append (cmdArgs , args ... )
381- cmd := exec .Command ("scripts/ playwright.sh" , cmdArgs ... )
422+ cmd := exec .Command ("playwright.sh" , cmdArgs ... )
382423 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" )
385426 var stdout , stderr bytes.Buffer
386427 cmd .Stdout = & stdout
387428 cmd .Stderr = & stderr
0 commit comments