From 6baecbf58b7d8275046bdf10c079c261066f9e47 Mon Sep 17 00:00:00 2001 From: dvddvd300 <21372070+dvddvd300@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:28:00 -0600 Subject: [PATCH] g --- tests/e2e/index.test.ts | 65 ----------------------------- tests/playwright.ts | 90 ----------------------------------------- 2 files changed, 155 deletions(-) delete mode 100644 tests/e2e/index.test.ts delete mode 100644 tests/playwright.ts diff --git a/tests/e2e/index.test.ts b/tests/e2e/index.test.ts deleted file mode 100644 index 420c0b6..0000000 --- a/tests/e2e/index.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -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(); -}); diff --git a/tests/playwright.ts b/tests/playwright.ts deleted file mode 100644 index 21899b4..0000000 --- a/tests/playwright.ts +++ /dev/null @@ -1,90 +0,0 @@ -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; - server: ViteDevServer; - msw: SetupServer; -} - -export async function clearKV(namespace: KVNamespace): Promise { - const result = await namespace.list(); - - await Promise.all(result.keys.map(key => namespace.delete(key.name))); -} - -export const expect = baseExpect.extend({}); - -export const test = baseTest.extend({ - // 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 wrangler = await getBindingsProxy(); - - // To access bindings in the tests. - await use(wrangler); - - // Ensure all cachees are cleaned up - await clearKV(wrangler.bindings.cache); - - await wrangler.dispose(); - }, - { scope: 'worker', auto: true }, - ], -}); - -test.beforeEach(({ msw }) => { - msw.resetHandlers(); -});