Skip to content

Commit 37181f5

Browse files
committed
Run playwright test on CMX node
1 parent cb6403c commit 37181f5

File tree

8 files changed

+354
-110
lines changed

8 files changed

+354
-110
lines changed

e2e/cluster/cmx/cluster.go

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
235280
func 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

e2e/cluster/docker/cluster.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,16 @@ func (c *Cluster) RunCommandOnNode(node int, line []string, envs ...map[string]s
105105
return c.Nodes[node].Exec(line, envs...)
106106
}
107107

108-
func (c *Cluster) SetupPlaywrightAndRunTest(testName string, args ...string) (string, string, error) {
109-
if err := c.SetupPlaywright(); err != nil {
110-
return "", "", fmt.Errorf("failed to setup playwright: %w", err)
111-
}
112-
return c.RunPlaywrightTest(testName, args...)
113-
}
114-
115-
func (c *Cluster) SetupPlaywright(envs ...map[string]string) error {
108+
func (c *Cluster) BypassKurlProxy(envs ...map[string]string) error {
116109
c.t.Logf("%s: bypassing kurl-proxy", time.Now().Format(time.RFC3339))
117110
_, stderr, err := c.RunCommandOnNode(0, []string{"bypass-kurl-proxy.sh"}, envs...)
118111
if err != nil {
119112
return fmt.Errorf("fail to bypass kurl-proxy: %v: %s", err, string(stderr))
120113
}
114+
return nil
115+
}
116+
117+
func (c *Cluster) SetupPlaywright(envs ...map[string]string) error {
121118
c.t.Logf("%s: installing playwright", time.Now().Format(time.RFC3339))
122119
cmd := exec.Command("sh", "-c", "cd playwright && npm ci && npx playwright install --with-deps")
123120
out, err := cmd.CombinedOutput()

e2e/cluster/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Cluster interface {
1717

1818
RunCommandOnNode(node int, line []string, envs ...map[string]string) (string, string, error)
1919

20-
SetupPlaywrightAndRunTest(testName string, args ...string) (string, string, error)
20+
BypassKurlProxy(envs ...map[string]string) error
2121
SetupPlaywright(envs ...map[string]string) error
2222
RunPlaywrightTest(testName string, args ...string) (string, string, error)
2323
}

e2e/cluster/lxd/cluster.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,20 +1136,17 @@ func (c *Cluster) Cleanup(envs ...map[string]string) {
11361136
c.copyPlaywrightReport()
11371137
}
11381138

1139-
func (c *Cluster) SetupPlaywrightAndRunTest(testName string, args ...string) (string, string, error) {
1140-
if err := c.SetupPlaywright(); err != nil {
1141-
return "", "", fmt.Errorf("failed to setup playwright: %w", err)
1142-
}
1143-
return c.RunPlaywrightTest(testName, args...)
1144-
}
1145-
1146-
func (c *Cluster) SetupPlaywright(envs ...map[string]string) error {
1139+
func (c *Cluster) BypassKurlProxy(envs ...map[string]string) error {
11471140
c.T.Logf("%s: bypassing kurl-proxy on node 0", time.Now().Format(time.RFC3339))
11481141
line := []string{"bypass-kurl-proxy.sh"}
11491142
if _, stderr, err := c.RunCommandOnNode(0, line, envs...); err != nil {
11501143
return fmt.Errorf("fail to bypass kurl-proxy on node %s: %v: %s", c.Nodes[0], err, string(stderr))
11511144
}
1152-
line = []string{"install-playwright.sh"}
1145+
return nil
1146+
}
1147+
1148+
func (c *Cluster) SetupPlaywright(envs ...map[string]string) error {
1149+
line := []string{"install-playwright.sh"}
11531150
c.T.Logf("%s: installing playwright on proxy node", time.Now().Format(time.RFC3339))
11541151
if _, stderr, err := c.RunCommandOnProxyNode(c.T, line); err != nil {
11551152
return fmt.Errorf("fail to install playwright on node %s: %v: %s", c.Proxy, err, string(stderr))

0 commit comments

Comments
 (0)