From 71992086edf689b1b8eea0156eb020dbccbccdf8 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Thu, 26 May 2022 15:11:57 -0500 Subject: [PATCH] test: add client-only e2e test --- packages/astro/e2e/client-only.test.js | 111 ++++++++++++++++++ .../e2e/fixtures/client-only/astro.config.mjs | 12 ++ .../e2e/fixtures/client-only/package.json | 24 ++++ .../src/components/PreactCounter.tsx | 19 +++ .../src/components/ReactCounter.jsx | 19 +++ .../src/components/SolidCounter.tsx | 19 +++ .../src/components/SvelteCounter.svelte | 29 +++++ .../client-only/src/components/VueCounter.vue | 34 ++++++ .../client-only/src/pages/index.astro | 41 +++++++ 9 files changed, 308 insertions(+) create mode 100644 packages/astro/e2e/client-only.test.js create mode 100644 packages/astro/e2e/fixtures/client-only/astro.config.mjs create mode 100644 packages/astro/e2e/fixtures/client-only/package.json create mode 100644 packages/astro/e2e/fixtures/client-only/src/components/PreactCounter.tsx create mode 100644 packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx create mode 100644 packages/astro/e2e/fixtures/client-only/src/components/SolidCounter.tsx create mode 100644 packages/astro/e2e/fixtures/client-only/src/components/SvelteCounter.svelte create mode 100644 packages/astro/e2e/fixtures/client-only/src/components/VueCounter.vue create mode 100644 packages/astro/e2e/fixtures/client-only/src/pages/index.astro diff --git a/packages/astro/e2e/client-only.test.js b/packages/astro/e2e/client-only.test.js new file mode 100644 index 0000000000000..a4ec8a9c8cc37 --- /dev/null +++ b/packages/astro/e2e/client-only.test.js @@ -0,0 +1,111 @@ +import { test as base, expect } from '@playwright/test'; +import { loadFixture } from './test-utils.js'; + +const test = base.extend({ + astro: async ({}, use) => { + const fixture = await loadFixture({ root: './fixtures/client-only/' }); + await use(fixture); + }, +}); + +let devServer; + +test.beforeEach(async ({ astro }) => { + devServer = await astro.startDevServer(); +}); + +test.afterEach(async () => { + await devServer.stop(); +}); + +test.describe('Client only', () => { + test('React counter', async ({ astro, page }) => { + await page.goto('/'); + + const counter = await page.locator('#react-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('pre'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const children = await counter.locator('h1'); + 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('/'); + + const counter = await page.locator('#preact-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('pre'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const children = await counter.locator('h1'); + 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('/'); + + const counter = await page.locator('#solid-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('pre'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const children = await counter.locator('h1'); + 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('/'); + + const counter = await page.locator('#vue-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('pre'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const children = await counter.locator('h1'); + 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('/'); + + const counter = await page.locator('#svelte-counter'); + await expect(counter, 'component is visible').toBeVisible(); + + const count = await counter.locator('pre'); + await expect(count, 'initial count is 0').toHaveText('0'); + + const children = await counter.locator('h1'); + 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'); + }); +}); diff --git a/packages/astro/e2e/fixtures/client-only/astro.config.mjs b/packages/astro/e2e/fixtures/client-only/astro.config.mjs new file mode 100644 index 0000000000000..4b50887cd70c0 --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/astro.config.mjs @@ -0,0 +1,12 @@ +import { defineConfig } from 'astro/config'; +import preact from '@astrojs/preact'; +import react from '@astrojs/react'; +import svelte from '@astrojs/svelte'; +import vue from '@astrojs/vue'; +import solid from '@astrojs/solid-js'; + +// https://astro.build/config +export default defineConfig({ + // Enable many frameworks to support all different kinds of components. + integrations: [preact(), react(), svelte(), vue(), solid()], +}); diff --git a/packages/astro/e2e/fixtures/client-only/package.json b/packages/astro/e2e/fixtures/client-only/package.json new file mode 100644 index 0000000000000..a0a8ce22968dc --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/package.json @@ -0,0 +1,24 @@ +{ + "name": "@e2e/multiple-frameworks", + "version": "0.0.0", + "private": true, + "devDependencies": { + "@astrojs/lit": "^0.1.3", + "@astrojs/preact": "^0.1.2", + "@astrojs/react": "^0.1.2", + "@astrojs/solid-js": "^0.1.2", + "@astrojs/svelte": "^0.1.3", + "@astrojs/vue": "^0.1.4", + "astro": "^1.0.0-beta.32" + }, + "dependencies": { + "@webcomponents/template-shadowroot": "^0.1.0", + "lit": "^2.2.4", + "preact": "^10.7.2", + "react": "^18.1.0", + "react-dom": "^18.1.0", + "solid-js": "^1.4.2", + "svelte": "^3.48.0", + "vue": "^3.2.36" + } +} diff --git a/packages/astro/e2e/fixtures/client-only/src/components/PreactCounter.tsx b/packages/astro/e2e/fixtures/client-only/src/components/PreactCounter.tsx new file mode 100644 index 0000000000000..af2258fdfe8fc --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/components/PreactCounter.tsx @@ -0,0 +1,19 @@ +import { useState } from 'preact/hooks'; + +/** a counter written in Preact */ +export function PreactCounter({ children, id }) { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( + <> +
+ +
{count}
+ +
+
{children}
+ + ); +} diff --git a/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx b/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx new file mode 100644 index 0000000000000..02eb1953907dc --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx @@ -0,0 +1,19 @@ +import { useState } from 'react'; + +/** a counter written in React */ +export function Counter({ children, id }) { + const [count, setCount] = useState(0); + const add = () => setCount((i) => i + 1); + const subtract = () => setCount((i) => i - 1); + + return ( + <> +
+ +
{count}
+ +
+
{children}
+ + ); +} diff --git a/packages/astro/e2e/fixtures/client-only/src/components/SolidCounter.tsx b/packages/astro/e2e/fixtures/client-only/src/components/SolidCounter.tsx new file mode 100644 index 0000000000000..689c5222ce97c --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/components/SolidCounter.tsx @@ -0,0 +1,19 @@ +import { createSignal } from 'solid-js'; + +/** a counter written with Solid */ +export default function SolidCounter({ children, id }) { + const [count, setCount] = createSignal(0); + const add = () => setCount(count() + 1); + const subtract = () => setCount(count() - 1); + + return ( + <> +
+ +
{count()}
+ +
+
{children}
+ + ); +} diff --git a/packages/astro/e2e/fixtures/client-only/src/components/SvelteCounter.svelte b/packages/astro/e2e/fixtures/client-only/src/components/SvelteCounter.svelte new file mode 100644 index 0000000000000..ab13b9c71f6bc --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/components/SvelteCounter.svelte @@ -0,0 +1,29 @@ + + + +
+ +
{ count }
+ +
+
+ +
+ + diff --git a/packages/astro/e2e/fixtures/client-only/src/components/VueCounter.vue b/packages/astro/e2e/fixtures/client-only/src/components/VueCounter.vue new file mode 100644 index 0000000000000..4861511c8c8a7 --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/components/VueCounter.vue @@ -0,0 +1,34 @@ + + + diff --git a/packages/astro/e2e/fixtures/client-only/src/pages/index.astro b/packages/astro/e2e/fixtures/client-only/src/pages/index.astro new file mode 100644 index 0000000000000..708ba1582dc99 --- /dev/null +++ b/packages/astro/e2e/fixtures/client-only/src/pages/index.astro @@ -0,0 +1,41 @@ +--- +import * as react from '../components/ReactCounter.jsx'; +import { PreactCounter } from '../components/PreactCounter.tsx'; +import SolidCounter from '../components/SolidCounter.tsx'; +import VueCounter from '../components/VueCounter.vue'; +import SvelteCounter from '../components/SvelteCounter.svelte'; + +// Full Astro Component Syntax: +// https://docs.astro.build/core-concepts/astro-components/ +--- + + + + + + + + +
+ +

react

+
+ + +

preact

+
+ + +

solid

+
+ + +

vue

+
+ + +

svelte

+
+
+ +