diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index f2617bd4be..f8f779027b 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -82,6 +82,8 @@ trait ProjectCustom 'sites.write', 'execution.read', 'execution.write', + 'log.read', + 'log.write', 'locale.read', 'avatars.read', 'health.read', diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index 031716b24b..cdb7b3e2ad 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -208,12 +208,14 @@ trait SitesBase return $deployments; } - protected function listLogs(string $siteId, mixed $params = []): mixed + protected function listLogs(string $siteId, array $queries = []): mixed { $logs = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/logs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), $params); + ], $this->getHeaders()), [ + 'queries' => $queries + ]); return $logs; } diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index 43d9fc173b..ff624862b4 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1675,4 +1675,74 @@ class SitesCustomServerTest extends Scope $this->cleanupSite($siteId); } + + public function testSSRLogs(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'SSR site', + 'framework' => 'astro', + 'adapter' => 'ssr', + 'buildRuntime' => 'ssr-22', + 'outputDirectory' => './dist', + 'buildCommand' => 'npm run build', + 'installCommand' => 'npm install', + 'fallbackFile' => '', + ]); + + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + + $deploymentId = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('astro'), + 'activate' => 'true' + ]); + + $this->assertNotEmpty($deploymentId); + + $domain = $this->getSiteDomain($siteId); + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/logs-inline'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Inline logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-inline", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); + $log1Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log1Id); + + $response = $proxyClient->call(Client::METHOD_GET, '/logs-action'); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Action logs printed.", $response['body']); + + $logs = $this->listLogs($siteId, [ + Query::orderDesc('$createdAt')->toString(), + Query::limit(1)->toString(), + ]); + $this->assertEquals(200, $logs['headers']['status-code']); + $this->assertStringContainsString("GET", $logs['body']['executions'][0]['requestMethod']); + $this->assertStringContainsString("/logs-action", $logs['body']['executions'][0]['requestPath']); + $this->assertStringContainsString("Log1", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Log2", $logs['body']['executions'][0]['logs']); + $this->assertStringContainsString("Error1", $logs['body']['executions'][0]['errors']); + $this->assertStringContainsString("Error2", $logs['body']['executions'][0]['errors']); + $log2Id = $logs['body']['executions'][0]['$id']; + $this->assertNotEmpty($log2Id); + + $this->assertNotEquals($log1Id, $log2Id); + + $this->cleanupSite($siteId); + } } diff --git a/tests/resources/sites/astro/astro.config.mjs b/tests/resources/sites/astro/astro.config.mjs index 54bee6ca84..a87942461e 100644 --- a/tests/resources/sites/astro/astro.config.mjs +++ b/tests/resources/sites/astro/astro.config.mjs @@ -1,9 +1,8 @@ import { defineConfig } from 'astro/config'; import node from '@astrojs/node'; -import 'dotenv/config'; export default defineConfig({ - output: 'server', + output: 'server', adapter: node({ mode: 'standalone' }), diff --git a/tests/resources/sites/astro/package.json b/tests/resources/sites/astro/package.json index a87c37d014..8cbcb910f5 100644 --- a/tests/resources/sites/astro/package.json +++ b/tests/resources/sites/astro/package.json @@ -10,7 +10,6 @@ }, "dependencies": { "@astrojs/node": "^9.0.2", - "astro": "^5.2.5", - "dotenv": "^16.4.7" + "astro": "^5.2.5" } } diff --git a/tests/resources/sites/astro/src/pages/logs-action.js b/tests/resources/sites/astro/src/pages/logs-action.js new file mode 100644 index 0000000000..348297a616 --- /dev/null +++ b/tests/resources/sites/astro/src/pages/logs-action.js @@ -0,0 +1,7 @@ +export async function GET(context) { + console.log("Log1"); + console.error("Error1"); + console.log("Log2"); + console.error("Error2"); + return new Response('Action logs printed.'); +} diff --git a/tests/resources/sites/astro/src/pages/logs-inline.astro b/tests/resources/sites/astro/src/pages/logs-inline.astro new file mode 100644 index 0000000000..c539142d83 --- /dev/null +++ b/tests/resources/sites/astro/src/pages/logs-inline.astro @@ -0,0 +1,18 @@ +--- +console.log("Log1"); +console.error("Error1"); +console.log("Log2"); +console.error("Error2"); +--- + + + +
+ + +Inline logs printed.
+ + diff --git a/tests/resources/sites/astro/tsconfig.json b/tests/resources/sites/astro/tsconfig.json deleted file mode 100644 index 8bf91d3bb9..0000000000 --- a/tests/resources/sites/astro/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "astro/tsconfigs/strict", - "include": [".astro/types.d.ts", "**/*"], - "exclude": ["dist"] -}