Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions packages/astro/e2e/csp-client-only.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory(import.meta.url, {
root: './fixtures/client-only/',
experimental: {
csp: true,
},
});

let previewServer;

test.beforeAll(async ({ astro }) => {
await astro.build();
previewServer = await astro.preview();
});

test.afterAll(async () => {
await previewServer.stop();
});
test.describe('CSP Client only', () => {
test('React counter', async ({ astro, page }) => {
await page.goto(astro.resolveUrl('/'));

const counter = await page.locator('#react-counter');
await expect(counter, 'component is visible').toBeVisible();

const fallback = await page.locator('[data-fallback=react]');
await expect(fallback, 'fallback content is hidden').not.toBeVisible();

const count = await counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');

const children = await counter.locator('.children');
await expect(children, 'children exist').toHaveText('react');

const increment = await counter.locator('.increment');
await increment.click();

await expect(count, 'count incremented by 1').toHaveText('1');
});

test('Preact counter', async ({ astro, page }) => {
await page.goto(astro.resolveUrl('/'));

const counter = await page.locator('#preact-counter');
await expect(counter, 'component is visible').toBeVisible();

const fallback = await page.locator('[data-fallback=preact]');
await expect(fallback, 'fallback content is hidden').not.toBeVisible();

const count = await counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');

const children = await counter.locator('.children');
await expect(children, 'children exist').toHaveText('preact');

const increment = await counter.locator('.increment');
await increment.click();

await expect(count, 'count incremented by 1').toHaveText('1');
});

test('Solid counter', async ({ astro, page }) => {
await page.goto(astro.resolveUrl('/'));

const counter = await page.locator('#solid-counter');
await expect(counter, 'component is visible').toBeVisible();

const fallback = await page.locator('[data-fallback=solid]');
await expect(fallback, 'fallback content is hidden').not.toBeVisible();

const count = await counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');

const children = await counter.locator('.children');
await expect(children, 'children exist').toHaveText('solid');

const increment = await counter.locator('.increment');
await increment.click();

await expect(count, 'count incremented by 1').toHaveText('1');
});

test('Vue counter', async ({ astro, page }) => {
await page.goto(astro.resolveUrl('/'));

const counter = await page.locator('#vue-counter');
await expect(counter, 'component is visible').toBeVisible();

const fallback = await page.locator('[data-fallback=vue]');
await expect(fallback, 'fallback content is hidden').not.toBeVisible();

const count = await counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');

const children = await counter.locator('.children');
await expect(children, 'children exist').toHaveText('vue');

const increment = await counter.locator('.increment');
await increment.click();

await expect(count, 'count incremented by 1').toHaveText('1');
});

test('Svelte counter', async ({ astro, page }) => {
await page.goto(astro.resolveUrl('/'));

const counter = await page.locator('#svelte-counter');
await expect(counter, 'component is visible').toBeVisible();

const fallback = await page.locator('[data-fallback=svelte]');
await expect(fallback, 'fallback content is hidden').not.toBeVisible();

const count = await counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');

const children = await counter.locator('.children');
await expect(children, 'children exist').toHaveText('svelte');

const increment = await counter.locator('.increment');
await increment.click();

await expect(count, 'count incremented by 1').toHaveText('1');
});
});
39 changes: 39 additions & 0 deletions packages/astro/e2e/csp-server-islands.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory(import.meta.url, {
root: './fixtures/csp-server-islands/',
});

test.describe('CSP Server islands', () => {
test.describe('Production', () => {
let previewServer;

test.beforeAll(async ({ astro }) => {
// Playwright's Node version doesn't have these functions, so stub them.
process.stdout.clearLine = () => {};
process.stdout.cursorTo = () => {};
await astro.build();
previewServer = await astro.preview();
});

test.afterAll(async () => {
await previewServer.stop();
});

test('Only one component in prod', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/base/'));

let el = page.locator('#basics .island');

await expect(el, 'element rendered').toBeVisible();
await expect(el, 'should have content').toHaveText('I am an island');
});

test('Props are encrypted', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
let el = page.locator('#basics .secret');
await expect(el).toHaveText('test');
});
});
});
Loading
Loading