Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
msw-postgrest
Advanced tools
Readme
Mock Postgrest/Supabase database server with Mock Service Worker (MSW)
Usage:
import { PostgrestClient } from "@supabase/postgrest-js";
import { setupServer } from "msw/node";
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "vitest";
import { mswPostgrest } from "msw-postgrest";
const POSTGREST_URL = "http://localhost";
const { mock, workers } = mswPostgrest({ postgrestUrl: POSTGREST_URL });
const server = setupServer(...workers);
// Ideally you'd move this to a setupTests file
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
describe("msw-postgrest", () => {
const postgrest = new PostgrestClient(POSTGREST_URL);
describe("insertions", () => {
it("insert single items", async () => {
mock
.from("shops")
.insert()
.select("id, address")
.reply(() => [{ id: 2, address: "foo" }]);
const res = await postgrest
.from("shops")
.insert({ address: "foo" })
.select("id, address");
expect(res.data).toEqual([{ id: 2, address: "foo" }]);
});
});
});
Usage (supabase):
import { createClient } from "@supabase/supabase-js";
import { setupServer } from "msw/node";
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
} from "vitest";
import { mswPostgrest } from "msw-postgrest";
const SUPABASE_URL = "http://localhost";
const { mock, workers } = mswPostgrest({
postgrestUrl: `${SUPABASE_URL}/rest/v1`,
});
const server = setupServer(...workers);
// Ideally you'd move this to a setupTests file
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
describe("msw-postgrest", () => {
const supa = createClient(SUPABASE_URL, "foobar");
describe("insertions", () => {
it("insert single items", async () => {
mock
.from("shops")
.insert()
.select("id, address")
.reply(() => [{ id: 2, address: "foo" }]);
const res = await supa
.from("shops")
.insert({ address: "foo" })
.select("id, address");
expect(res.data).toEqual([{ id: 2, address: "foo" }]);
});
});
});
FAQs
Mock Postgrest/Supabase database server with Mock Service Worker (MSW)
The npm package msw-postgrest receives a total of 105 weekly downloads. As such, msw-postgrest popularity was classified as not popular.
We found that msw-postgrest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.