Skip to content

Commit

Permalink
tests: Add playwright example with network mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed May 9, 2024
1 parent d5a0759 commit c769dda
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
29 changes: 29 additions & 0 deletions playwright-tests/tests/fixtures/projects.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"id": 25491,
"ref": "default",
"name": "Segment Production",
"status": "ACTIVE_HEALTHY",
"organization_id": 1,
"inserted_at": "2021-06-16T04:03:09.700217",
"subscription_id": "sub_subscription_id",
"cloud_provider": "AWS",
"region": "us-east-1",
"disk_volume_size_gb": 2373,
"size": "m6g.large",
"db_user_supabase": "db_user_supabase",
"db_pass_supabase": "db_pass_supabase",
"db_dns_name": "12.123.123.123",
"db_host": "db.projectref.supabase.co",
"db_port": 5432,
"db_name": "postgres",
"ssl_enforced": false,
"read_replicas_enabled": false,
"walg_enabled": true,
"infra_compute_size": "large",
"preview_branch_refs": [],
"is_branch_enabled": false,
"is_read_replicas_enabled": false,
"is_physical_backups_enabled": true
}
]
28 changes: 28 additions & 0 deletions playwright-tests/tests/fixtures/projects/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"cloud_provider": "AWS",
"db_host": "db.projectref.supabase.co",
"id": 2137,
"inserted_at": "2023-01-30T16:07:16.040884",
"name": "[LIVE] supabase-com",
"organization_id": 1,
"ref": "projectref",
"region": "us-east-1",
"status": "ACTIVE_HEALTHY",
"subscription_id": "sub_subscription_id",
"connectionString": "connectionString",
"restUrl": "https://projectref.supabase.co/rest/v1/",
"volumeSizeGb": 8,
"maxDatabasePreprovisionGb": null,
"lastDatabaseResizeAt": null,
"is_branch_enabled": true,
"is_read_replicas_enabled": true,
"is_physical_backups_enabled": false,
"infra_compute_size": "micro",
"kpsVersion": "supabase-postgres-15.1.0.33",
"dbVersion": "supabase-postgres-15.1.0.33",
"serviceVersions": {
"gotrue": "2.150.1",
"postgrest": "10.2.0",
"supabase-postgres": "15.1.0.33"
}
}
34 changes: 34 additions & 0 deletions playwright-tests/tests/snapshot/spec/overview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect, test } from '@playwright/test'
import * as path from 'path'
import * as fs from 'fs/promises'

test.describe('Project Overview', () => {
// Global mock
test.beforeEach(async ({ context }) => {
await context.route('**/api/projects', async (route) =>
route.fulfill({
status: 200,
body: await fs.readFile(path.resolve(__dirname, '../../fixtures/projects.json'), 'utf-8'),
})
)
})

test('should have a heading with project name', async ({ page }) => {
page.on('request', (request) => console.log('>>', request.method(), request.url()))
page.on('response', (response) => console.log('<<', response.status(), response.url()))

// Local mock
await page.route('**/api/projects/default', async (route) =>
route.fulfill({
status: 200,
body: await fs.readFile(
path.resolve(__dirname, '../../fixtures/projects/default.json'),
'utf-8'
),
})
)

await page.goto('/project/default')
await expect(page.getByText('[LIVE] supabase-com')).toBeVisible()
})
})

0 comments on commit c769dda

Please sign in to comment.