From 7c4ce62a58b8372472c5a623a9de296f0c2d2a43 Mon Sep 17 00:00:00 2001 From: Marcin Tojek Date: Thu, 31 Aug 2023 14:44:44 +0200 Subject: [PATCH] test(site): print agent logs (#9464) --- site/e2e/helpers.ts | 24 +++++++++++++++--------- site/e2e/playwright.config.ts | 2 +- site/e2e/reporter.ts | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index f655b14c19..3a6fb56a62 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -314,18 +314,24 @@ export const startAgentWithCommand = async ( ...process.env, CODER_AGENT_URL: "http://localhost:" + port, CODER_AGENT_TOKEN: token, + CODER_AGENT_PPROF_ADDRESS: "127.0.0.1:2114", + CODER_AGENT_PROMETHEUS_ADDRESS: "127.0.0.1:6061", }, }) - let buffer = Buffer.of() - cp.stderr.on("data", (data: Buffer) => { - buffer = Buffer.concat([buffer, data]) + cp.stdout.on("data", (data: Buffer) => { + // eslint-disable-next-line no-console -- Log agent activity + console.log( + `[agent] [stdout] [onData] ${data.toString().replace(/\n$/g, "")}`, + ) }) - try { - await page.getByTestId("agent-status-ready").waitFor({ state: "visible" }) - // eslint-disable-next-line @typescript-eslint/no-explicit-any -- The error is a string - } catch (ex: any) { - throw new Error(ex.toString() + "\n" + buffer.toString()) - } + cp.stderr.on("data", (data: Buffer) => { + // eslint-disable-next-line no-console -- Log agent activity + console.log( + `[agent] [stderr] [onData] ${data.toString().replace(/\n$/g, "")}`, + ) + }) + + await page.getByTestId("agent-status-ready").waitFor({ state: "visible" }) } const coderMainPath = (): string => { diff --git a/site/e2e/playwright.config.ts b/site/e2e/playwright.config.ts index 87c8b9facd..cdebce9f45 100644 --- a/site/e2e/playwright.config.ts +++ b/site/e2e/playwright.config.ts @@ -36,6 +36,7 @@ export default defineConfig({ video: "retain-on-failure", }, webServer: { + url: `http://localhost:${port}/api/v2/deployment/config`, command: `go run -tags embed ${coderMain} server ` + `--global-config $(mktemp -d -t e2e-XXXXXXXXXX) ` + @@ -88,7 +89,6 @@ export default defineConfig({ gitAuth.validatePath, ), }, - port, reuseExistingServer: false, }, }) diff --git a/site/e2e/reporter.ts b/site/e2e/reporter.ts index 80fb16f88f..c21b0989d1 100644 --- a/site/e2e/reporter.ts +++ b/site/e2e/reporter.ts @@ -41,6 +41,10 @@ class CoderReporter implements Reporter { onTestEnd(test: TestCase, result: TestResult) { // eslint-disable-next-line no-console -- Helpful for debugging console.log(`Finished test ${test.title}: ${result.status}`) + if (result.status !== "passed") { + // eslint-disable-next-line no-console -- Helpful for debugging + console.log("errors", result.errors, "attachments", result.attachments) + } } onEnd(result: FullResult) {