|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { testFactory } from './test-utils.js'; |
| 3 | + |
| 4 | +const test = testFactory(import.meta.url, { |
| 5 | + root: './fixtures/client-only/', |
| 6 | + experimental: { |
| 7 | + csp: true, |
| 8 | + }, |
| 9 | +}); |
| 10 | + |
| 11 | +let previewServer; |
| 12 | + |
| 13 | +test.beforeAll(async ({ astro }) => { |
| 14 | + await astro.build(); |
| 15 | + previewServer = await astro.preview(); |
| 16 | +}); |
| 17 | + |
| 18 | +test.afterAll(async () => { |
| 19 | + await previewServer.stop(); |
| 20 | +}); |
| 21 | +test.describe('CSP Client only', () => { |
| 22 | + test('React counter', async ({ astro, page }) => { |
| 23 | + await page.goto(astro.resolveUrl('/')); |
| 24 | + |
| 25 | + const counter = await page.locator('#react-counter'); |
| 26 | + await expect(counter, 'component is visible').toBeVisible(); |
| 27 | + |
| 28 | + const fallback = await page.locator('[data-fallback=react]'); |
| 29 | + await expect(fallback, 'fallback content is hidden').not.toBeVisible(); |
| 30 | + |
| 31 | + const count = await counter.locator('pre'); |
| 32 | + await expect(count, 'initial count is 0').toHaveText('0'); |
| 33 | + |
| 34 | + const children = await counter.locator('.children'); |
| 35 | + await expect(children, 'children exist').toHaveText('react'); |
| 36 | + |
| 37 | + const increment = await counter.locator('.increment'); |
| 38 | + await increment.click(); |
| 39 | + |
| 40 | + await expect(count, 'count incremented by 1').toHaveText('1'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('Preact counter', async ({ astro, page }) => { |
| 44 | + await page.goto(astro.resolveUrl('/')); |
| 45 | + |
| 46 | + const counter = await page.locator('#preact-counter'); |
| 47 | + await expect(counter, 'component is visible').toBeVisible(); |
| 48 | + |
| 49 | + const fallback = await page.locator('[data-fallback=preact]'); |
| 50 | + await expect(fallback, 'fallback content is hidden').not.toBeVisible(); |
| 51 | + |
| 52 | + const count = await counter.locator('pre'); |
| 53 | + await expect(count, 'initial count is 0').toHaveText('0'); |
| 54 | + |
| 55 | + const children = await counter.locator('.children'); |
| 56 | + await expect(children, 'children exist').toHaveText('preact'); |
| 57 | + |
| 58 | + const increment = await counter.locator('.increment'); |
| 59 | + await increment.click(); |
| 60 | + |
| 61 | + await expect(count, 'count incremented by 1').toHaveText('1'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('Solid counter', async ({ astro, page }) => { |
| 65 | + await page.goto(astro.resolveUrl('/')); |
| 66 | + |
| 67 | + const counter = await page.locator('#solid-counter'); |
| 68 | + await expect(counter, 'component is visible').toBeVisible(); |
| 69 | + |
| 70 | + const fallback = await page.locator('[data-fallback=solid]'); |
| 71 | + await expect(fallback, 'fallback content is hidden').not.toBeVisible(); |
| 72 | + |
| 73 | + const count = await counter.locator('pre'); |
| 74 | + await expect(count, 'initial count is 0').toHaveText('0'); |
| 75 | + |
| 76 | + const children = await counter.locator('.children'); |
| 77 | + await expect(children, 'children exist').toHaveText('solid'); |
| 78 | + |
| 79 | + const increment = await counter.locator('.increment'); |
| 80 | + await increment.click(); |
| 81 | + |
| 82 | + await expect(count, 'count incremented by 1').toHaveText('1'); |
| 83 | + }); |
| 84 | + |
| 85 | + test('Vue counter', async ({ astro, page }) => { |
| 86 | + await page.goto(astro.resolveUrl('/')); |
| 87 | + |
| 88 | + const counter = await page.locator('#vue-counter'); |
| 89 | + await expect(counter, 'component is visible').toBeVisible(); |
| 90 | + |
| 91 | + const fallback = await page.locator('[data-fallback=vue]'); |
| 92 | + await expect(fallback, 'fallback content is hidden').not.toBeVisible(); |
| 93 | + |
| 94 | + const count = await counter.locator('pre'); |
| 95 | + await expect(count, 'initial count is 0').toHaveText('0'); |
| 96 | + |
| 97 | + const children = await counter.locator('.children'); |
| 98 | + await expect(children, 'children exist').toHaveText('vue'); |
| 99 | + |
| 100 | + const increment = await counter.locator('.increment'); |
| 101 | + await increment.click(); |
| 102 | + |
| 103 | + await expect(count, 'count incremented by 1').toHaveText('1'); |
| 104 | + }); |
| 105 | + |
| 106 | + test('Svelte counter', async ({ astro, page }) => { |
| 107 | + await page.goto(astro.resolveUrl('/')); |
| 108 | + |
| 109 | + const counter = await page.locator('#svelte-counter'); |
| 110 | + await expect(counter, 'component is visible').toBeVisible(); |
| 111 | + |
| 112 | + const fallback = await page.locator('[data-fallback=svelte]'); |
| 113 | + await expect(fallback, 'fallback content is hidden').not.toBeVisible(); |
| 114 | + |
| 115 | + const count = await counter.locator('pre'); |
| 116 | + await expect(count, 'initial count is 0').toHaveText('0'); |
| 117 | + |
| 118 | + const children = await counter.locator('.children'); |
| 119 | + await expect(children, 'children exist').toHaveText('svelte'); |
| 120 | + |
| 121 | + const increment = await counter.locator('.increment'); |
| 122 | + await increment.click(); |
| 123 | + |
| 124 | + await expect(count, 'count incremented by 1').toHaveText('1'); |
| 125 | + }); |
| 126 | +}); |
0 commit comments