Skip to content

Commit 1e50149

Browse files
authored
test: enable testing with Wrangler for Pages and Workers (#28)
* test: enable testing with Wrangler for Pages and Workers * build before tests * add the test for vite in `examples/cloudflare-workers`
1 parent 6c6196a commit 1e50149

File tree

10 files changed

+1274
-31
lines changed

10 files changed

+1274
-31
lines changed

examples/cloudflare-pages/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"start": "wrangler pages dev ./build/client",
1111
"typecheck": "tsc",
1212
"preview": "npm run build && wrangler pages dev",
13-
"test:e2e": "playwright test -- -c playwright.config.ts e2e.test.ts"
13+
"test:e2e:vite": "playwright test -c playwright-vite.config.ts e2e.test.ts",
14+
"test:e2e:pages": "npm run build && playwright test -c playwright-pages.config.ts e2e.test.ts"
1415
},
1516
"dependencies": {
1617
"@remix-run/cloudflare": "^2.14.0",
@@ -36,4 +37,4 @@
3637
"engines": {
3738
"node": ">=20.0.0"
3839
}
39-
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { defineConfig, devices } from '@playwright/test'
22

3+
const port = 8798
4+
35
export default defineConfig({
46
fullyParallel: true,
57
forbidOnly: !!process.env.CI,
68
retries: process.env.CI ? 2 : 0,
79
workers: process.env.CI ? 1 : undefined,
810
use: {
9-
baseURL: 'http://localhost:6173',
11+
baseURL: `http://localhost:${port.toString()}`,
1012
},
1113
projects: [
1214
{
@@ -17,8 +19,8 @@ export default defineConfig({
1719
},
1820
],
1921
webServer: {
20-
command: 'npm exec vite -- --port 6173 -c ./vite.config.ts',
21-
port: 6173,
22+
command: `npm exec wrangler pages dev -- --port ${port.toString()}`,
23+
port,
2224
reuseExistingServer: !process.env.CI,
2325
},
2426
})
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+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
node_modules
2+
3+
test-results
4+
5+
/.cache
16
/build
27
.env
38
.dev.vars
9+
10+
.wrangler
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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).toBe('Var is My Value')
15+
16+
const contentH3 = await page.textContent('h3')
17+
expect(contentH3).toBe('cf,ctx,caches are available')
18+
19+
const contentH4 = await page.textContent('h4')
20+
expect(contentH4).toBe('Extra is stuff')
21+
})
22+
23+
test('Should return 200 response - /api', async ({ page }) => {
24+
const response = await page.goto('/api')
25+
expect(response?.status()).toBe(200)
26+
expect(await response?.json()).toEqual({ message: 'Hello', var: 'My Value' })
27+
})

examples/cloudflare-workers/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"dev": "remix vite:dev",
1010
"start": "wrangler dev",
1111
"typecheck": "tsc",
12-
"preview": "npm run build && wrangler dev"
12+
"preview": "npm run build && wrangler dev",
13+
"test:e2e:vite": "playwright test -c playwright-vite.config.ts e2e.test.ts",
14+
"test:e2e:workers": "npm run build && playwright test -c playwright-workers.config.ts e2e.test.ts"
1315
},
1416
"dependencies": {
1517
"@remix-run/cloudflare": "^2.14.0",
@@ -22,9 +24,11 @@
2224
},
2325
"devDependencies": {
2426
"@hono/vite-dev-server": "^0.16.0",
27+
"@playwright/test": "^1.48.2",
2528
"@remix-run/dev": "^2.14.0",
2629
"@types/react": "^18.2.20",
2730
"@types/react-dom": "^18.2.7",
31+
"playwright": "^1.47.0",
2832
"typescript": "^5.1.6",
2933
"vite": "^5.1.0",
3034
"vite-tsconfig-paths": "^4.2.1",
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+
})
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 = 8797
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 wrangler dev -- --port ${port.toString()} ./worker.ts`,
23+
port,
24+
reuseExistingServer: !process.env.CI,
25+
},
26+
})

0 commit comments

Comments
 (0)