isaacharrisholt / supawright Goto Github PK
View Code? Open in Web Editor NEWA Playwright test harness for E2E testing with Supabase
License: MIT License
A Playwright test harness for E2E testing with Supabase
License: MIT License
Our database uses quite a large number of USER-DEFINED
data types in postgres such as enum
and citext
. This forces all of them to be handled by one USER-DEFINED
generator function.
Consider using the udt_name
when building the tree and using that as the key for the generator function. Reference..)
https://github.com/isaacharrisholt/supawright/blob/main/src/tree.ts#L42
That will also allow you to join on the possible enum values.
select table_name, column_name, data_type, udt_name
from information_schema.columns
where table_schema in (${schemasString});
-- pull all enum values in a schema
select n.nspname as enum_schema,
t.typname as enum_name,
e.enumlabel as enum_value
from pg_type t
join pg_enum e on t.oid = e.enumtypid
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
where n.nspname in (${schemasString});
Hi,
In my user_details table, the id is one to one relation with auth.users.id.
when i try to run the test
test('can create table with no dependencies', async ({ supawright }) => {
await supawright.create('user_details')
})
i get Error: Error inserting data into user_details: insert or update on table "user_details" violates foreign key constraint "user_details_id_fkey"
How do i fix this?
Hey Supawright is working great, but thought I'd bring up a workaround that I'm facing in the hopes that there is an easy way to implement this with supawright. A lot of our tables have auth.users
as a foreign key constraint so it forces us to create one before calling supawright.create
. See below as an example of what I'm talking about or here in the repo.
import { mergeTests } from '@playwright/test'
import { test as sendAccountTest, expect } from '@my/playwright/fixtures/send-accounts'
import { test as supawrightTest } from '@my/playwright/fixtures/supawright'
import { debug, Debugger } from 'debug'
import { supabaseAdmin } from 'app/utils/supabase/admin'
import { countries } from 'app/utils/country'
const randomCountry = () =>
countries[Math.floor(Math.random() * countries.length)] as (typeof countries)[number]
const test = mergeTests(sendAccountTest, supawrightTest)
let log: Debugger
let otherUserId: string
test.beforeEach(async ({ page }) => {
log = debug(`test:profile:${test.info().parallelIndex}`)
const randomNumber = Math.floor(Math.random() * 1e9)
const country = randomCountry()
const { data, error } = await supabaseAdmin.auth.signUp({
phone: `+${country.dialCode}${randomNumber}`,
password: 'changeme',
})
if (error) {
log('error creating user', error)
throw error
}
if (!data?.user) {
throw new Error('user not created')
}
if (!data?.session) {
throw new Error('session not created')
}
log('created user', data)
otherUserId = data.user.id
})
test.afterEach(async () => {
const { parallelIndex } = test.info()
await supabaseAdmin.auth.admin.deleteUser(otherUserId).then(({ error }) => {
if (error) {
log('error deleting user', `id=${parallelIndex}`, `user=${otherUserId}`, error)
throw error
}
})
})
test('should work', async ({ page, supawright }) => {
expect(otherUserId).toBeDefined()
const result = await supawright.create('tags', {
name: 'tag1',
status: 'confirmed',
user_id: otherUserId,
})
log('created tag1', result)
expect(result).toBeDefined()
await page.goto('/profile/tag1')
const title = await page.title()
expect(title).toBe('Send | Profile')
})
Hey,
pretty new to testing but I don't find what is wrong with my code or if it could be a bug?
This is the piece of code that is throwing an error:
import { withSupawright } from "supawright";
import type { Database } from "~/types/supabase";
const test = withSupawright<Database, "public">(["public"]);
// test.use({ storageState: { cookies: [], origins: [] } });
test("can create transaction", async ({ supawright }) => {
console.log("context", supawright);
});
The only text I get is this:
1) [firefox] › e2e/transactions.spec.ts:9:1 › can create transaction ─────────────────────────────
AggregateError:
1 failed
[firefox] › e2e/transactions.spec.ts:9:1 › can create transaction ──────────────────────────────
I have no idea what I'm doing wrong.
Any help would be appreciated thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.