adding solid-js hydration and HMR tests

This commit is contained in:
Tony Sullivan 2022-05-15 13:21:23 -06:00
parent 08ae1c90db
commit 2481a5a389
8 changed files with 173 additions and 1 deletions

View file

@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import solid from '@astrojs/solid-js';
// https://astro.build/config
export default defineConfig({
integrations: [solid()],
});

View file

@ -0,0 +1,10 @@
{
"name": "@e2e/solid",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/solid-js": "workspace:*",
"astro": "workspace:*",
"solid-js": "^1.3.17"
}
}

View file

@ -0,0 +1,11 @@
.counter {
display: grid;
font-size: 2em;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-top: 3em;
place-items: center;
}
.counter-message {
text-align: center;
}

View file

@ -0,0 +1,19 @@
import { createSignal } from 'solid-js';
import './Counter.css';
export default function Counter({ children, id, count: initialCount = 0 }) {
const [count, setCount] = createSignal(initialCount);
const add = () => setCount(count() + 1);
const subtract = () => setCount(count() - 1);
return (
<>
<div id={id} class="counter">
<button class="decrement" onClick={subtract}>-</button>
<pre>{count()}</pre>
<button class="increment" onClick={add}>+</button>
</div>
<div class="counter-message">{children}</div>
</>
);
}

View file

@ -0,0 +1,26 @@
---
import Counter from '../components/Counter.jsx';
const someProps = {
count: 0,
};
---
<html>
<head>
<!-- Head Stuff -->
</head>
<body>
<Counter id="counter-idle" {...someProps} client:idle>
<h1>Hello, client:idle!</h1>
</Counter>
<Counter id="counter-load" {...someProps} client:load>
<h1>Hello, client:load!</h1>
</Counter>
<Counter id="counter-visible" {...someProps} client:visible>
<h1>Hello, client:visible!</h1>
</Counter>
</body>
</html>

View file

@ -1,5 +1,5 @@
{ {
"name": "@e2e/react", "name": "@e2e/svelte",
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {

View file

@ -0,0 +1,89 @@
import { test as base, expect } from '@playwright/test';
import { loadFixture, onAfterHMR } from './test-utils.js';
const test = base.extend({
astro: async ({}, use) => {
const fixture = await loadFixture({ root: './fixtures/solid/' });
await use(fixture);
},
});
let devServer;
test.beforeAll(async ({ astro }) => {
devServer = await astro.startDevServer();
});
test.afterAll(async ({ astro }) => {
await devServer.stop();
});
test.afterEach(async ({ astro }) => {
astro.clean();
});
test.only('Solid', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));
await test.step('client:idle', async () => {
const counter = page.locator('#counter-idle');
await expect(counter).toBeVisible();
const count = counter.locator('pre');
await expect(count).toHaveText('0');
const inc = counter.locator('.increment');
await inc.click();
await expect(count).toHaveText('1');
});
await test.step('client:load', async () => {
const counter = page.locator('#counter-load');
await expect(counter).toBeVisible();
const count = counter.locator('pre');
await expect(count).toHaveText('0');
const inc = counter.locator('.increment');
await inc.click();
await expect(count).toHaveText('1');
});
await test.step('client:visible', async () => {
const counter = page.locator('#counter-visible');
await expect(counter).toBeVisible();
const count = counter.locator('pre');
await expect(count).toHaveText('0');
const inc = counter.locator('.increment');
await inc.click();
await expect(count).toHaveText('1');
});
await test.step('HMR', async () => {
const afterHMR = onAfterHMR(page);
// test 1: updating the page component
await astro.writeFile(
'src/pages/index.astro',
(original) => original.replace('id="counter-idle" {...someProps}', 'id="counter-idle" count={5}')
);
await afterHMR;
const count = page.locator('#counter-idle pre');
await expect(count).toHaveText('5');
// test 2: updating imported CSS
await astro.writeFile(
'src/components/Counter.css',
(original) => original.replace('font-size: 2em;', 'font-size: 24px;')
);
await expect(count).toHaveCSS('font-size', '24px');
});
});

View file

@ -683,6 +683,16 @@ importers:
react: 18.1.0 react: 18.1.0
react-dom: 18.1.0_react@18.1.0 react-dom: 18.1.0_react@18.1.0
packages/astro/e2e/fixtures/solid:
specifiers:
'@astrojs/solid-js': workspace:*
astro: workspace:*
solid-js: ^1.3.17
dependencies:
'@astrojs/solid-js': link:../../../../integrations/solid
astro: link:../../..
solid-js: 1.3.17
packages/astro/e2e/fixtures/svelte: packages/astro/e2e/fixtures/svelte:
specifiers: specifiers:
'@astrojs/svelte': workspace:* '@astrojs/svelte': workspace:*