Skip to content

Commit 672b5a7

Browse files
committed
add e2e test
1 parent 78e4659 commit 672b5a7

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

examples/node/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
node_modules
22

3+
test-results
4+
35
/.cache
46
/build
57
.env
8+
.dev.vars
9+
10+
.wrangler

examples/node/e2e.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('Should return 200 response - /', async ({ page }) => {
4+
const response = await page.goto('/')
5+
expect(response?.status()).toBe(200)
6+
7+
const headers = response?.headers() ?? {}
8+
expect(headers['x-powered-by']).toBe('Remix and Hono')
9+
10+
const contentH1 = await page.textContent('h1')
11+
expect(contentH1).toBe('Remix and Hono')
12+
13+
const contentH2 = await page.textContent('h2')
14+
expect(contentH2).toMatch(/URL is http:\/\/localhost:\d+/)
15+
16+
const contentH3 = await page.textContent('h3')
17+
expect(contentH3).toBe('Extra is stuff')
18+
})
19+
20+
test('Should return 200 response - /api', async ({ page }) => {
21+
const response = await page.goto('/api')
22+
expect(response?.status()).toBe(200)
23+
expect(await response?.json()).toEqual({ message: 'Hello' })
24+
})

examples/node/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"dev": "remix vite:dev",
99
"start": "remix-serve ./build/server/index.js",
1010
"start-with-adapter": "tsx main.ts",
11+
"test:e2e:vite": "playwright test -c playwright-vite.config.ts e2e.test.ts",
12+
"test:e2e:node": "npm run build && playwright test -c playwright-node.config.ts e2e.test.ts",
1113
"typecheck": "tsc"
1214
},
1315
"dependencies": {
@@ -21,10 +23,12 @@
2123
"react-dom": "^18.2.0"
2224
},
2325
"devDependencies": {
26+
"@playwright/test": "^1.48.2",
2427
"@remix-run/dev": "^2.14.0",
2528
"@types/react": "^18.2.20",
2629
"@types/react-dom": "^18.2.7",
2730
"autoprefixer": "^10.4.19",
31+
"playwright": "^1.47.0",
2832
"tsx": "^4.19.2",
2933
"typescript": "^5.1.6",
3034
"vite": "^5.1.0",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
const port = 3010
4+
5+
export default defineConfig({
6+
fullyParallel: true,
7+
forbidOnly: !!process.env.CI,
8+
retries: process.env.CI ? 2 : 0,
9+
workers: process.env.CI ? 1 : undefined,
10+
use: {
11+
baseURL: `http://localhost:${port.toString()}`,
12+
},
13+
projects: [
14+
{
15+
name: 'chromium',
16+
use: { ...devices['Desktop Chrome'] },
17+
timeout: 5000,
18+
retries: 2,
19+
},
20+
],
21+
webServer: {
22+
command: 'npm exec tsx ./main.ts',
23+
port,
24+
reuseExistingServer: !process.env.CI,
25+
},
26+
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
const port = 6173
4+
5+
export default defineConfig({
6+
fullyParallel: true,
7+
forbidOnly: !!process.env.CI,
8+
retries: process.env.CI ? 2 : 0,
9+
workers: process.env.CI ? 1 : undefined,
10+
use: {
11+
baseURL: `http://localhost:${port.toString()}`,
12+
},
13+
projects: [
14+
{
15+
name: 'chromium',
16+
use: { ...devices['Desktop Chrome'] },
17+
timeout: 5000,
18+
retries: 2,
19+
},
20+
],
21+
webServer: {
22+
command: `npm exec vite -- --port ${port.toString()} -c ./vite.config.ts`,
23+
port,
24+
reuseExistingServer: !process.env.CI,
25+
},
26+
})

examples/node/vite.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { vitePlugin as remix } from '@remix-run/dev'
2+
import serverAdapter from 'hono-remix-adapter/vite'
23
import { defineConfig } from 'vite'
34
import tsconfigPaths from 'vite-tsconfig-paths'
5+
import { getLoadContext } from './load-context'
46

57
declare module '@remix-run/node' {
68
interface Future {
@@ -19,6 +21,10 @@ export default defineConfig({
1921
v3_lazyRouteDiscovery: true,
2022
},
2123
}),
24+
serverAdapter({
25+
getLoadContext,
26+
entry: './server/index.ts',
27+
}),
2228
tsconfigPaths(),
2329
],
2430
})

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"test:e2e:vite": "npm run test:e2e:vite -w example-cloudflare-pages",
99
"test:e2e:cloudflare-pages": "npm run test:e2e:pages -w example-cloudflare-pages",
1010
"test:e2e:cloudflare-workers": "npm run test:e2e:workers -w example-cloudflare-workers",
11+
"test:e2e:node": "npm run test:e2e:node -w example-node",
1112
"build": "tsup",
1213
"watch": "tsup --watch",
1314
"lint": "eslint src examples/cloudflare-pages/app examples/cloudflare-pages/server examples/cloudflare-workers/app examples/cloudflare-workers/server",

0 commit comments

Comments
 (0)