diff --git a/e2e/examples-smoke.spec.ts b/e2e/examples-smoke.spec.ts index 7beab4fb4..cc5756448 100644 --- a/e2e/examples-smoke.spec.ts +++ b/e2e/examples-smoke.spec.ts @@ -10,7 +10,7 @@ import { fileURLToPath } from 'node:url'; import waitPort from 'wait-port'; import { readdir, rm } from 'node:fs/promises'; import { basename } from 'node:path'; -import { debugChildProcess, getFreePort, terminate, test } from './utils.js'; +import { getFreePort, terminate, test } from './utils.js'; import { error, info } from '@actions/core'; const examplesDir = fileURLToPath(new URL('../examples', import.meta.url)); @@ -29,21 +29,6 @@ const commands = [ }, ]; -const specialExamples = [ - { - name: '08_cookies', - commands: [ - { - command: 'node dev.js', - }, - { - build: 'waku build', - command: 'node start.js', - }, - ], - }, -].slice(Infinity); // FIXME: remove, as no longer needed - const examples = [ ...(await readdir(examplesDir)).map((example) => fileURLToPath(new URL(`../examples/${example}`, import.meta.url)), @@ -51,93 +36,51 @@ const examples = [ ]; for (const cwd of examples) { - const specialExample = specialExamples.find(({ name }) => cwd.includes(name)); - if (specialExample) { - for (const { build, command } of specialExample.commands) { - test.describe(`smoke test on ${basename(cwd)}: ${command}`, () => { - let cp: ChildProcess; - let port: number; - test.beforeAll('remove cache', async () => { - await rm(`${cwd}/dist`, { - recursive: true, - force: true, - }); - }); - - test.beforeAll(async () => { - if (build) { - execSync(build, { - cwd, - env: process.env, - }); - } - port = await getFreePort(); - cp = exec(`${command} --port ${port}`, { cwd }); - debugChildProcess(cp, fileURLToPath(import.meta.url), [ - /ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time/, - ]); - await waitPort({ port }); - }); - - test.afterAll(async () => { - await terminate(cp.pid!); - }); - - test('check title', async ({ page }) => { - await page.goto(`http://localhost:${port}/`); - // title maybe doesn't ready yet - await page.waitForLoadState('load'); - await expect.poll(() => page.title()).toMatch(/^Waku/); + for (const { build, command } of commands) { + test.describe(`smoke test on ${basename(cwd)}: ${command}`, () => { + let cp: ChildProcess; + let port: number; + test.beforeAll('remove cache', async () => { + await rm(`${cwd}/dist`, { + recursive: true, + force: true, }); }); - } - } else { - for (const { build, command } of commands) { - test.describe(`smoke test on ${basename(cwd)}: ${command}`, () => { - let cp: ChildProcess; - let port: number; - test.beforeAll('remove cache', async () => { - await rm(`${cwd}/dist`, { - recursive: true, - force: true, - }); - }); - test.beforeAll(async () => { - if (build) { - execSync(`node ${waku} ${build}`, { cwd }); + test.beforeAll(async () => { + if (build) { + execSync(`node ${waku} ${build}`, { cwd }); + } + port = await getFreePort(); + cp = exec(`node ${waku} ${command} --port ${port}`, { cwd }); + cp.stdout?.on('data', (data) => { + info(`${port} stdout: ${data}`); + console.log(`${port} stdout: `, `${data}`); + }); + cp.stderr?.on('data', (data) => { + if ( + command === 'dev' && + /WebSocket server error: Port is already in use/.test(`${data}`) + ) { + // ignore this error + return; } - port = await getFreePort(); - cp = exec(`node ${waku} ${command} --port ${port}`, { cwd }); - cp.stdout?.on('data', (data) => { - info(`${port} stdout: ${data}`); - console.log(`${port} stdout: `, `${data}`); - }); - cp.stderr?.on('data', (data) => { - if ( - command === 'dev' && - /WebSocket server error: Port is already in use/.test(`${data}`) - ) { - // ignore this error - return; - } - error(`${port} stderr: ${data}`); - console.error(`${port} stderr: `, `${data}`); - }); - await waitPort({ port }); + error(`${port} stderr: ${data}`); + console.error(`${port} stderr: `, `${data}`); }); + await waitPort({ port }); + }); - test.afterAll(async () => { - await terminate(cp.pid!); - }); + test.afterAll(async () => { + await terminate(cp.pid!); + }); - test('check title', async ({ page }) => { - await page.goto(`http://localhost:${port}/`); - // title maybe doesn't ready yet - await page.waitForLoadState('load'); - await expect.poll(() => page.title()).toMatch(/^Waku/); - }); + test('check title', async ({ page }) => { + await page.goto(`http://localhost:${port}/`); + // title maybe doesn't ready yet + await page.waitForLoadState('load'); + await expect.poll(() => page.title()).toMatch(/^Waku/); }); - } + }); } } diff --git a/examples/08_cookies/waku.config.ts b/examples/08_cookies/waku.config.ts index 7992bae25..d8719c8e4 100644 --- a/examples/08_cookies/waku.config.ts +++ b/examples/08_cookies/waku.config.ts @@ -11,6 +11,7 @@ export default { ), ] : []), + import('waku/middleware/headers'), import('waku/middleware/ssr'), import('waku/middleware/rsc'), ], diff --git a/examples/09_api/package.json b/examples/09_api/package.json new file mode 100644 index 000000000..4aa75138e --- /dev/null +++ b/examples/09_api/package.json @@ -0,0 +1,22 @@ +{ + "name": "waku-example", + "version": "0.1.0", + "type": "module", + "private": true, + "scripts": { + "dev": "waku dev", + "build": "waku build", + "start": "waku start" + }, + "dependencies": { + "react": "19.0.0-rc.0", + "react-dom": "19.0.0-rc.0", + "react-server-dom-webpack": "19.0.0-rc.0", + "waku": "0.21.0-alpha.2" + }, + "devDependencies": { + "@types/react": "18.3.3", + "@types/react-dom": "18.3.0", + "typescript": "5.4.5" + } +} diff --git a/examples/09_api/src/components/App.tsx b/examples/09_api/src/components/App.tsx new file mode 100644 index 000000000..20f8fb649 --- /dev/null +++ b/examples/09_api/src/components/App.tsx @@ -0,0 +1,14 @@ +import { Counter } from './Counter'; + +const App = ({ name }: { name: string }) => { + return ( +
Count: {count}
+ +Hello, {message}
+