Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/vite-plugin-tapi-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/test-results
27 changes: 27 additions & 0 deletions examples/vite-plugin-tapi-demo/e2e/dev/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test, expect } from "@playwright/test";

test("page renders with title", async ({ page }) => {
await page.goto("/");
await expect(
page.getByRole("heading", { name: "vite-plugin-tapi demo" }),
).toBeVisible();
});

test("greets the default name", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "Greet" }).click();
await expect(page.getByTestId("output")).toHaveText("hello, world");
});

test("greets a custom name", async ({ page }) => {
await page.goto("/");
await page.getByLabel("Name:").fill("claude");
await page.getByRole("button", { name: "Greet" }).click();
await expect(page.getByTestId("output")).toHaveText("hello, claude");
});

test("api returns json", async ({ request }) => {
const res = await request.get("/greet?name=api");
expect(res.status()).toBe(200);
expect(await res.json()).toEqual({ greeting: "hello, api" });
});
27 changes: 27 additions & 0 deletions examples/vite-plugin-tapi-demo/e2e/prod/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test, expect } from "@playwright/test";

test("page renders with title", async ({ page }) => {
await page.goto("/");
await expect(
page.getByRole("heading", { name: "vite-plugin-tapi demo" }),
).toBeVisible();
});

test("greets the default name", async ({ page }) => {
await page.goto("/");
await page.getByRole("button", { name: "Greet" }).click();
await expect(page.getByTestId("output")).toHaveText("hello, world");
});

test("greets a custom name", async ({ page }) => {
await page.goto("/");
await page.getByLabel("Name:").fill("claude");
await page.getByRole("button", { name: "Greet" }).click();
await expect(page.getByTestId("output")).toHaveText("hello, claude");
});

test("api returns json", async ({ request }) => {
const res = await request.get("/greet?name=api");
expect(res.status()).toBe(200);
expect(await res.json()).toEqual({ greeting: "hello, api" });
});
29 changes: 29 additions & 0 deletions examples/vite-plugin-tapi-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@farbenmeer/vite-plugin-tapi-example-demo",
"version": "0.0.0",
"type": "module",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "node dist/server.mjs",
"test": "playwright test",
"test:dev": "playwright test --project=dev",
"test:prod": "playwright test --project=prod",
"ci-setup": "playwright install --with-deps"
},
"dependencies": {
"@farbenmeer/tapi": "workspace:^",
"@farbenmeer/vite-plugin-tapi": "workspace:^",
"srvx": "^0.11.15",
"vite": "^8.0.9",
"zod": "^4.0.17"
},
"devDependencies": {
"@playwright/test": "^1.58.1",
"@types/node": "^25.0.3"
},
"peerDependencies": {
"typescript": "^5 || ^6.0.0"
}
}
41 changes: 41 additions & 0 deletions examples/vite-plugin-tapi-demo/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
testDir: "./e2e",
fullyParallel: false,
workers: 1,
retries: 2,
reporter: "list",
use: {
...devices["Desktop Chrome"],
trace: "on-first-retry",
},
projects: [
{
name: "dev",
testDir: "./e2e/dev",
use: { baseURL: "http://localhost:3200" },
},
{
name: "prod",
testDir: "./e2e/prod",
use: { baseURL: "http://localhost:3201" },
},
],
webServer: [
{
command: "pnpm dev",
env: { PORT: "3200" },
port: 3200,
reuseExistingServer: !process.env.CI,
stdout: "pipe",
},
{
command: "pnpm build && pnpm start",
env: { PORT: "3201" },
port: 3201,
reuseExistingServer: !process.env.CI,
stdout: "pipe",
},
],
});
56 changes: 56 additions & 0 deletions examples/vite-plugin-tapi-demo/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
defineApi,
defineHandler,
TResponse,
} from "@farbenmeer/tapi/server";
import { z } from "zod";

const html = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>vite-plugin-tapi demo</title>
</head>
<body>
<h1>vite-plugin-tapi demo</h1>
<form id="greet-form">
<label>
Name: <input id="name" name="name" value="world" />
</label>
<button type="submit">Greet</button>
</form>
<p id="output" data-testid="output"></p>
<script>
const form = document.getElementById("greet-form");
const out = document.getElementById("output");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const name = document.getElementById("name").value;
const res = await fetch("/greet?name=" + encodeURIComponent(name));
const data = await res.json();
out.textContent = data.greeting;
});
</script>
</body>
</html>`;

export const api = defineApi()
.route("/", {
GET: defineHandler({ authorize: () => true }, async () => {
return new TResponse(html, {
headers: { "content-type": "text/html; charset=utf-8" },
});
}),
})
.route("/greet", {
GET: defineHandler(
{
authorize: () => true,
query: { name: z.string().optional() },
},
async (req) => {
const { name = "world" } = req.query();
return TResponse.json({ greeting: `hello, ${name}` });
},
),
});
21 changes: 21 additions & 0 deletions examples/vite-plugin-tapi-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "Preserve",
"moduleDetection": "force",
"allowJs": true,

"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true
},
"include": ["./src", "./e2e", "./vite.config.ts", "./playwright.config.ts"]
}
6 changes: 6 additions & 0 deletions examples/vite-plugin-tapi-demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "vite";
import tapi from "@farbenmeer/vite-plugin-tapi";

export default defineConfig({
plugins: [tapi({ basePath: "" })],
});
43 changes: 43 additions & 0 deletions packages/3-vite-plugin-tapi/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@farbenmeer/vite-plugin-tapi",
"version": "0.1.0",
"author": {
"name": "Michel Smola",
"email": "michel.smola@farbenmeer.de"
},
"type": "module",
"module": "dist/index.js",
"main": "dist/index.js",
"private": false,
"license": "MIT",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsc --noEmit false",
"release": "pnpm build && pnpm publish --no-git-checks"
},
"dependencies": {
"srvx": "^0.11.15"
},
"peerDependencies": {
"@farbenmeer/tapi": "workspace:^",
"typescript": "^5 || ^6.0.0",
"vite": "^8.0.0"
},
"devDependencies": {
"@farbenmeer/tapi": "workspace:^",
"@types/node": "^25.0.3",
"vite": "^8.0.9"
},
"repository": {
"type": "git",
"url": "git+https://github.com/farbenmeer/tapi.git"
}
}
Loading
Loading