-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbe0e14
commit 454c29c
Showing
13 changed files
with
185 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import { type PlaywrightTestConfig, devices } from '@playwright/test'; | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
const config: PlaywrightTestConfig = { | ||
const PORT = process.env.PORT || '5173'; | ||
|
||
export default defineConfig({ | ||
testDir: './tests/e2e', | ||
timeout: 15 * 1000, | ||
expect: { | ||
timeout: 5 * 1000, | ||
}, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 0, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: 'html', | ||
use: { | ||
baseURL: `http://localhost:${PORT}`, | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
}; | ||
export default config; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
module.exports = { | ||
import typeography from '@tailwindcss/typography'; | ||
|
||
export default { | ||
content: ['./app/**/*.tsx', './app/**/*.ts'], | ||
theme: {}, | ||
plugins: [require('@tailwindcss/typography')], | ||
plugins: [typeography], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { http } from 'msw'; | ||
import { test, expect } from '../playwright'; | ||
|
||
/** | ||
* You can interact with browser through the page instance | ||
*/ | ||
test('shows the package name', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const title = page.getByRole('heading', { | ||
name: 'remix-cloudflare-template', | ||
level: 2, | ||
}); | ||
|
||
await expect(title).toBeVisible(); | ||
}); | ||
|
||
/** | ||
* You can interact with the wrangler binding similar to the remix app | ||
*/ | ||
test('cache the README in KV', async ({ page, wrangler }) => { | ||
await wrangler.bindings.cache.put('github/README.md', '# cached-readme'); | ||
await page.goto('/'); | ||
|
||
const title = page.getByRole('heading', { | ||
name: 'cached-readme', | ||
level: 1, | ||
}); | ||
|
||
await expect(title).toBeVisible(); | ||
}); | ||
|
||
/** | ||
* You can also mock the requests with MSW | ||
*/ | ||
test('fetch README from GitHub if not cached', async ({ | ||
page, | ||
wrangler, | ||
msw, | ||
}) => { | ||
// Mock request | ||
msw.use( | ||
http.get( | ||
'https://api.github.com/repos/edmundhung/remix-cloudflare-template/contents/README.md', | ||
() => { | ||
return Response.json({ | ||
type: 'file', | ||
content: btoa('# testing'), | ||
}); | ||
}, | ||
), | ||
); | ||
|
||
// Clear cache | ||
await wrangler.bindings.cache.delete('github/README.md'); | ||
|
||
await page.goto('/'); | ||
|
||
const title = page.getByRole('heading', { | ||
name: 'testing', | ||
level: 1, | ||
}); | ||
|
||
await expect(title).toBeVisible(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { test as baseTest, expect as baseExpect } from '@playwright/test'; | ||
import type { Env } from 'env'; | ||
import { type ViteDevServer, createServer } from 'vite'; | ||
import { type SetupServer, setupServer } from 'msw/node'; | ||
import { type BindingsProxy, getBindingsProxy } from 'wrangler'; | ||
|
||
interface TestFixtures {} | ||
|
||
interface WorkerFixtures { | ||
port: number; | ||
wrangler: BindingsProxy<Env>; | ||
server: ViteDevServer; | ||
msw: SetupServer; | ||
} | ||
|
||
export const expect = baseExpect.extend({}); | ||
|
||
export const test = baseTest.extend<TestFixtures, WorkerFixtures>({ | ||
// Assign a unique "port" for each worker process | ||
port: [ | ||
// eslint-disable-next-line no-empty-pattern | ||
async ({}, use, workerInfo) => { | ||
await use(3515 + workerInfo.workerIndex); | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
|
||
// Ensure visits works with relative path | ||
baseURL: ({ port }, use) => { | ||
use(`http://localhost:${port}`); | ||
}, | ||
|
||
// Start a Vite dev server for each worker | ||
// This allows MSW to intercept requests properly | ||
server: [ | ||
async ({ port }, use) => { | ||
const server = await createServer({ | ||
configFile: './vite.config.ts', | ||
}); | ||
|
||
await server.listen(port); | ||
|
||
await use(server); | ||
|
||
await server.close(); | ||
}, | ||
{ scope: 'worker', auto: true }, | ||
], | ||
|
||
msw: [ | ||
// eslint-disable-next-line no-empty-pattern | ||
async ({}, use) => { | ||
const server = setupServer(); | ||
|
||
server.listen(); | ||
|
||
await use(server); | ||
|
||
server.close(); | ||
}, | ||
{ scope: 'worker', auto: true }, | ||
], | ||
|
||
// To access wrangler bindings similar to Remix / Vite | ||
wrangler: [ | ||
// eslint-disable-next-line no-empty-pattern | ||
async ({}, use) => { | ||
const bindings = await getBindingsProxy<Env>(); | ||
|
||
// To access bindings in the tests. | ||
await use(bindings); | ||
|
||
await bindings.dispose(); | ||
}, | ||
{ scope: 'worker', auto: true }, | ||
], | ||
}); | ||
|
||
test.beforeEach(({ msw }) => { | ||
msw.resetHandlers(); | ||
}); |
Oops, something went wrong.