Skip to content

Commit

Permalink
add tests for rsc
Browse files Browse the repository at this point in the history
  • Loading branch information
nksaraf committed Sep 25, 2023
1 parent 0f4b3ee commit 88a8069
Show file tree
Hide file tree
Showing 24 changed files with 917 additions and 14 deletions.
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"@tanstack/[email protected]": "patches/@[email protected]"
},
"overrides": {
"h3": "npm:@vinxi/[email protected]",
"listhen": "npm:@vinxi/listhen"
}
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ async function createRouterBuild(app, router) {
ssrManifest: true,
rollupOptions: {
input: { handler: router.handler },
external: ["h3"],
},
target: "esnext",
outDir: join(router.outDir + "_entry"),
Expand Down
110 changes: 101 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions test/rsc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, test } from "@playwright/test";

import type { AppFixture, Fixture } from "./helpers/create-fixture.js";
import { createFixture, js } from "./helpers/create-fixture.js";
import {
PlaywrightFixture,
prettyHtml,
selectHtml,
} from "./helpers/playwright-fixture.js";

test.describe("rsc", () => {
let fixture: Fixture;
let appFixture: AppFixture;

test.beforeAll(async () => {
fixture = await createFixture({
files: {},
template: "react-rsc",
});

appFixture = await fixture.createServer();
});

test.afterAll(async () => {
await appFixture.close();
});

let logs: string[] = [];

test.beforeEach(({ page }) => {
page.on("console", (msg) => {
logs.push(msg.text());
});
});

test("spa", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);
await app.goto("/", true);

expect(await app.getHtml("[data-test-id=title]")).toBe(
prettyHtml(`<h1 data-test-id="title">Hello from Vinxi</h1>`),
);
expect(await app.getHtml("[data-test-id=counter]")).toBe(
prettyHtml(`<button data-test-id="counter">Count: 0</button>`),
);
expect(await app.getHtml("[data-test-id=server-count]")).toBe(
prettyHtml(`<span data-test-id="server-count">0</span>`),
);

await app.clickElement("[data-test-id=counter]");

expect(await app.getHtml("[data-test-id=counter]")).toBe(
prettyHtml(`<button data-test-id="counter">Count: 1</button>`),
);
expect(await app.getHtml("[data-test-id=server-count]")).toBe(
prettyHtml(`<span data-test-id="server-count">1</span>`),
);
});
});
1 change: 1 addition & 0 deletions test/templates/react-rsc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
72 changes: 72 additions & 0 deletions test/templates/react-rsc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# app

## null

### Patch Changes

- Updated dependencies [fd06048]
- Updated dependencies [0f14555]
- Updated dependencies [82267c5]
- [email protected]
- @vinxi/plugin-references@0.0.20
- @vinxi/react@0.0.10

## null

### Patch Changes

- Updated dependencies [8058084]
- [email protected]
- @vinxi/plugin-references@0.0.19

## null

### Patch Changes

- Updated dependencies [b934e84]
- Updated dependencies [17693dc]
- Updated dependencies [d6305b8]
- Updated dependencies [cb91c48]
- Updated dependencies [085116d]
- Updated dependencies [f1ee5b8]
- [email protected]
- @vinxi/plugin-references@0.0.18

## null

### Patch Changes

- Updated dependencies [7803042]
- [email protected]
- @vinxi/plugin-references@0.0.17

## null

### Patch Changes

- Updated dependencies [2b17e0d]
- [email protected]
- @vinxi/plugin-references@0.0.16

## null

### Patch Changes

- Updated dependencies [552d8ca]
- [email protected]
- @vinxi/plugin-references@0.0.15

## null

### Patch Changes

- Updated dependencies [47abc3c]
- @vinxi/plugin-references@0.0.14
- [email protected]

## null

### Patch Changes

- Updated dependencies [ec37a2e]
- @vinxi/react@0.0.9
59 changes: 59 additions & 0 deletions test/templates/react-rsc/app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { references } from "@vinxi/plugin-references";
import reactRefresh from "@vitejs/plugin-react";
import { createApp } from "vinxi";

export default createApp({
server: {
plugins: [references.serverPlugin],
virtual: {
[references.serverPlugin]: references.serverPluginModule({
routers: ["server", "rsc"],
}),
},
},
routers: [
{
name: "public",
mode: "static",
dir: "./public",
},
{
name: "rsc",
worker: true,
mode: "handler",
base: "/_rsc",
handler: "./app/react-server.tsx",
target: "server",
plugins: () => [references.serverComponents(), reactRefresh()],
},
{
name: "client",
mode: "spa",
handler: "./index.ts",
target: "browser",
plugins: () => [
references.clientRouterPlugin({
runtime: "@vinxi/react-server-dom/runtime",
}),
reactRefresh(),
references.clientComponents(),
],
base: "/",
},
{
name: "server",
worker: true,
mode: "handler",
base: "/_server",
handler: "./app/server-action.tsx",
target: "server",
plugins: () => [
references.serverRouterPlugin({
resolve: {
conditions: ["react-server"],
},
}),
],
},
],
});
18 changes: 18 additions & 0 deletions test/templates/react-rsc/app/Counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

import { useState } from "react";

export function Counter({ onChange }) {
const [count, setCount] = useState(0);
return (
<button
data-test-id="counter"
onClick={() => {
setCount((c) => c + 1);
onChange();
}}
>
Count: {count}
</button>
);
}
Loading

0 comments on commit 88a8069

Please sign in to comment.