-
Notifications
You must be signed in to change notification settings - Fork 16
test: enable testing with Wrangler for Pages and Workers #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
|
|
||
| const port = 6173 | ||
|
|
||
| export default defineConfig({ | ||
| fullyParallel: true, | ||
| forbidOnly: !!process.env.CI, | ||
| retries: process.env.CI ? 2 : 0, | ||
| workers: process.env.CI ? 1 : undefined, | ||
| use: { | ||
| baseURL: `http://localhost:${port.toString()}`, | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| timeout: 5000, | ||
| retries: 2, | ||
| }, | ||
| ], | ||
| webServer: { | ||
| command: `npm exec vite -- --port ${port.toString()} -c ./vite.config.ts`, | ||
| port, | ||
| reuseExistingServer: !process.env.CI, | ||
| }, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| node_modules | ||
|
|
||
| test-results | ||
|
|
||
| /.cache | ||
| /build | ||
| .env | ||
| .dev.vars | ||
|
|
||
| .wrangler |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { expect, test } from '@playwright/test' | ||
|
|
||
| test('Should return 200 response - /', async ({ page }) => { | ||
| const response = await page.goto('/') | ||
| expect(response?.status()).toBe(200) | ||
|
|
||
| const headers = response?.headers() ?? {} | ||
| expect(headers['x-powered-by']).toBe('Remix and Hono') | ||
|
|
||
| const contentH1 = await page.textContent('h1') | ||
| expect(contentH1).toBe('Remix and Hono') | ||
|
|
||
| const contentH2 = await page.textContent('h2') | ||
| expect(contentH2).toBe('Var is My Value') | ||
|
|
||
| const contentH3 = await page.textContent('h3') | ||
| expect(contentH3).toBe('cf,ctx,caches are available') | ||
|
|
||
| const contentH4 = await page.textContent('h4') | ||
| expect(contentH4).toBe('Extra is stuff') | ||
| }) | ||
|
|
||
| test('Should return 200 response - /api', async ({ page }) => { | ||
| const response = await page.goto('/api') | ||
| expect(response?.status()).toBe(200) | ||
| expect(await response?.json()).toEqual({ message: 'Hello', var: 'My Value' }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,8 @@ | |
| "dev": "remix vite:dev", | ||
| "start": "wrangler dev", | ||
| "typecheck": "tsc", | ||
| "preview": "npm run build && wrangler dev" | ||
| "preview": "npm run build && wrangler dev", | ||
| "test:e2e:workers": "npm run build && playwright test -c playwright-workers.config.ts e2e.test.ts" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be kinder to add "test:e2e:vite:workers": "playwright test -c playwright-vite.config.ts e2e.test.ts",
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I added the test for vite, it will test the same things as the test in However, the naming of test is
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the test for Vite: d92c8c2 |
||
| }, | ||
| "dependencies": { | ||
| "@remix-run/cloudflare": "^2.14.0", | ||
|
|
@@ -22,9 +23,11 @@ | |
| }, | ||
| "devDependencies": { | ||
| "@hono/vite-dev-server": "^0.16.0", | ||
| "@playwright/test": "^1.48.2", | ||
| "@remix-run/dev": "^2.14.0", | ||
| "@types/react": "^18.2.20", | ||
| "@types/react-dom": "^18.2.7", | ||
| "playwright": "^1.47.0", | ||
| "typescript": "^5.1.6", | ||
| "vite": "^5.1.0", | ||
| "vite-tsconfig-paths": "^4.2.1", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { defineConfig, devices } from '@playwright/test' | ||
|
|
||
| const port = 8797 | ||
|
|
||
| export default defineConfig({ | ||
| fullyParallel: true, | ||
| forbidOnly: !!process.env.CI, | ||
| retries: process.env.CI ? 2 : 0, | ||
| workers: process.env.CI ? 1 : undefined, | ||
| use: { | ||
| baseURL: `http://localhost:${port.toString()}`, | ||
| }, | ||
| projects: [ | ||
| { | ||
| name: 'chromium', | ||
| use: { ...devices['Desktop Chrome'] }, | ||
| timeout: 5000, | ||
| retries: 2, | ||
| }, | ||
| ], | ||
| webServer: { | ||
| command: `npm exec wrangler dev -- --port ${port.toString()} ./worker.ts`, | ||
| port, | ||
| reuseExistingServer: !process.env.CI, | ||
| }, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add the
test:e2e:vite:workerscommand, you might need to change this line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the same reason above, the change is unnecessary because this name is used only the project.