Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding E2E tests for client hydration and HMR #3374

Merged
merged 67 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5b506b1
adding Tailwind E2E tests with Playwright
May 11, 2022
4199c8a
package.json updates
May 11, 2022
29cc61c
adding e2e tests to CI workflow
May 11, 2022
e105bac
using e2e for dev tests, mocha for build tests
May 11, 2022
c854dff
refactor: sharing test-utils helpers
May 11, 2022
400d1b8
chore: update lockfile
May 11, 2022
4512765
Adding contributing docs
May 12, 2022
85172f7
Revert "refactor: sharing test-utils helpers"
May 12, 2022
4ae372e
refactor: simpler solution to resolving e2e test fixtures
May 12, 2022
aa29100
chore: updating lockfile
May 12, 2022
b7db93c
refactor: cleaning up how URLs are resolved in e2e tests
May 12, 2022
ee16c14
install playwright deps in CI
May 12, 2022
0b3c6c2
ensure playwright deps are installed during CI
May 15, 2022
c0bd9da
adding a basic HMR test for tailwind styles
May 15, 2022
fe5bb8c
using @e2e for playwright test packages
May 15, 2022
8e5f0d2
adding react hydration and HMR tests
May 15, 2022
91d802e
adding hydration and HMR tests for preact
May 15, 2022
08ae1c9
adding svelte hydration and HMR tests
May 15, 2022
2481a5a
adding solid-js hydration and HMR tests
May 15, 2022
54e4ee2
adding solid hydration and HMR tests
May 15, 2022
a934059
adding vue hydration and HMR tests
May 15, 2022
c8aedf7
adding client:media tests
May 15, 2022
23a93bd
Merge branch 'main' into test/e2e-hydration
May 15, 2022
e6f3dd5
fixing Lit hydration and HMR tests
May 16, 2022
7b85d40
fixing up the Vue e2e tests
May 16, 2022
8326cfd
fixing up svelte tests
May 16, 2022
31bcd81
chore: test cleanup
May 16, 2022
03e0318
chore: cleaning up test element IDs
May 16, 2022
59cfcdd
chore: updating lock file
May 16, 2022
262a21d
Merge branch 'main' into test/e2e-hydration
May 16, 2022
a84b5f4
chore: update lockfile after merge
May 16, 2022
ed1bad9
TEMP: disabling React e2e tests
May 16, 2022
fa5ff21
Revert "TEMP: disabling React e2e tests"
May 16, 2022
0094fc3
Merge branch 'main' into test/e2e-hydration
May 17, 2022
254cf94
Merge branch 'main' into test/e2e-hydration
May 17, 2022
a2bc065
updating to use the new editFiles helper
May 17, 2022
621a6e9
Merge branch 'main' into test/e2e-hydration
May 18, 2022
6a629f7
chore: updating lock file
May 18, 2022
22ba760
Merge branch 'main' into test/e2e-hydration
May 19, 2022
2d833ce
Merge branch 'main' into test/e2e-hydration
May 19, 2022
2880101
Merge branch 'main' into test/e2e-hydration
May 20, 2022
1380520
Merge branch 'main' into test/e2e-hydration
May 21, 2022
6e62533
updating lock file
May 21, 2022
b122cea
Merge branch 'main' into test/e2e-hydration
May 21, 2022
1086118
updating lockfile
May 21, 2022
3e8db19
TEMP: watching for console logs
May 21, 2022
603fa28
TEMP: testing typescript tests
May 21, 2022
7a54471
updating test:e2e scripts for config file
May 21, 2022
8dd5b23
seems like it didn't find the config file?
May 21, 2022
afd1b07
use a fresh dev server for each test
May 21, 2022
4970a80
removing Lit tests for now
May 21, 2022
69a78ae
Revert "removing Lit tests for now"
May 21, 2022
2505e63
updating test config for CI
May 21, 2022
71dc3e9
WIP: disabling HMR tests to track down why they're unreliable
May 21, 2022
82920db
Merge branch 'main' into test/e2e-hydration
May 21, 2022
6a856bf
TEMP: logging to debug HMR test
May 21, 2022
21b9156
afterEach isn't a global in Playwright
May 21, 2022
dca9ba8
fix: the test's file reset helper was using a URL not filepath
May 21, 2022
3b3c2d5
one last try, why is the HMR test hanging at cleanup?
May 21, 2022
55f3f34
resetting files after tailwind HMR test
May 21, 2022
9d57c11
create the onNextChange watcher before editFile is called
May 22, 2022
c71b267
moving the file changed sync into editFile()
May 22, 2022
7f9d4d7
code refactor + Astro Component HMR test
May 22, 2022
c93691b
chore: lint fixes
May 22, 2022
a0c9cb5
adding a test suite for the framework-multiple example app
May 22, 2022
c805f93
Merge branch 'main' into test/e2e-hydration
May 22, 2022
d305dbc
Merge branch 'main' into test/e2e-hydration
May 23, 2022
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
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": ["@example/*", "@test/*"]
"ignore": ["@example/*", "@test/*", "@e2e/*"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:smoke": "node scripts/smoke/index.js",
"test:vite-ci": "turbo run test --no-deps --scope=astro --concurrency=1",
"test:e2e": "cd packages/astro && pnpm playwright install && pnpm run test:e2e",
"test:e2e:match": "cd packages/astro && pnpm playwright install && pnpm run test:e2e:match",
"benchmark": "turbo run benchmark --scope=astro",
"lint": "eslint \"packages/**/*.ts\"",
"format": "prettier -w .",
Expand Down
42 changes: 42 additions & 0 deletions packages/astro/e2e/astro-component.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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/astro-component/' });
await use(fixture);
},
});

let devServer;

test.beforeEach(async ({ astro }) => {
devServer = await astro.startDevServer();
});

test.afterEach(async () => {
await devServer.stop();
});

test.describe('Astro components', () => {
test('HMR', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));

const hero = page.locator('section');
await expect(hero, 'hero has background: white').toHaveCSS(
'background-color',
'rgb(255, 255, 255)'
);
await expect(hero, 'hero has color: black').toHaveCSS('color', 'rgb(0, 0, 0)');

// Edit the Hero component with a new background color
await astro.editFile('./src/components/Hero.astro', (content) =>
content.replace('background: white', 'background: rgb(230, 230, 230)')
);

await expect(hero, 'background color updated').toHaveCSS(
'background-color',
'rgb(230, 230, 230)'
);
});
});
4 changes: 4 additions & 0 deletions packages/astro/e2e/fixtures/astro-component/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({});
8 changes: 8 additions & 0 deletions packages/astro/e2e/fixtures/astro-component/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@e2e/astro-component",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.counter {
display: grid;
font-size: 2em;
grid-template-columns: repeat(3, minmax(0, 1fr));
margin-top: 2em;
place-items: center;
}

.counter-message {
text-align: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { h, Fragment } from 'preact';
import { useState } from 'preact/hooks';
import './Counter.css';

export default function Counter({ children, count: initialCount, id }) {
const [count, setCount] = useState(initialCount);
const add = () => setCount((i) => i + 1);
const subtract = () => setCount((i) => i - 1);

return (
<>
<div id={id} className="counter">
<button className="decrement" onClick={subtract}>-</button>
<pre>{count}</pre>
<button className="increment" onClick={add}>+</button>
</div>
<div className="counter-message">{children}</div>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
export interface Props {
title: string;
}

const { title } = Astro.props as Props;
---

<section>
<h1>{title}</h1>
<slot />
</section>

<style>
section {
width: 100%;
height: 80vh;
background: white;
color: black;
}

h1 {
text-align: center;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { h } from 'preact';

export default function({ id }) {
return <div id={id}>Preact client:only component</div>
}
16 changes: 16 additions & 0 deletions packages/astro/e2e/fixtures/astro-component/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
import Hero from '../components/Hero.astro';
---

<html>
<head>
<!-- Head Stuff -->
</head>
<body>
<main>
<Hero title="Astro Components">
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
</Hero>
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions packages/astro/e2e/fixtures/lit-component/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'astro/config';
import lit from '@astrojs/lit';

// https://astro.build/config
export default defineConfig({
integrations: [lit()],
});
11 changes: 11 additions & 0 deletions packages/astro/e2e/fixtures/lit-component/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@e2e/lit-component",
"version": "0.0.0",
"private": true,
"dependencies": {
"@astrojs/lit": "workspace:*",
"astro": "workspace:*",
"@webcomponents/template-shadowroot": "^0.1.0",
"lit": "^2.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { LitElement, html } from 'lit';

export const tagName = 'my-counter';

class Counter extends LitElement {
static get properties() {
return {
count: {
type: Number,
},
};
}

constructor() {
super();
this.count = 0;
}

increment() {
this.count++;
}

render() {
return html`
<div>
<p>Count: ${this.count}</p>

<button type="button" @click=${this.increment}>Increment</button>

<slot />
</div>
`;
}
}

customElements.define(tagName, Counter);
26 changes: 26 additions & 0 deletions packages/astro/e2e/fixtures/lit-component/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
import '../components/Counter.js';

const someProps = {
count: 0,
};
---

<html>
<head>
<!-- Head Stuff -->
</head>
<body>
<my-counter id="client-idle" {...someProps} client:idle>
<h1>Hello, client:idle!</h1>
</my-counter>

<my-counter id="client-load" {...someProps} client:load>
<h1>Hello, client:load!</h1>
</my-counter>

<my-counter id="client-visible" {...someProps} client:visible>
<h1>Hello, client:visible!</h1>
</my-counter>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/astro/e2e/fixtures/lit-component/src/pages/media.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
import '../components/Counter.js';

const someProps = {
count: 0,
};
---

<html>
<head>
<!-- Head Stuff -->
</head>
<body>
<my-counter id="client-media" {...someProps} client:media="(max-width: 50em)">
<h1>Hello, client:media!</h1>
</my-counter>
</body>
</html>
12 changes: 12 additions & 0 deletions packages/astro/e2e/fixtures/multiple-frameworks/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -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()],
});
24 changes: 24 additions & 0 deletions packages/astro/e2e/fixtures/multiple-frameworks/package.json
Original file line number Diff line number Diff line change
@@ -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.31"
},
"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.34"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
const { id } = Astro.props
---

<div id={id} class="children">
<h1>Hello Astro (A)</h1>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
const { id } = Astro.props
---

<div id={id} class="children">
<h1>Hello Astro (B)</h1>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { LitElement, html } from 'lit';

export const tagName = 'my-counter';

class Counter extends LitElement {
static get properties() {
return {
count: {
type: Number,
},
};
}

constructor() {
super();
this.count = 0;
}

increment() {
this.count++;
}

render() {
return html`
<div>
<p>Count: ${this.count}</p>
<button type="button" @click=${this.increment}>Increment</button>
</div>
`;
}
}

customElements.define(tagName, Counter);
Original file line number Diff line number Diff line change
@@ -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 (
<>
<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>
</>
);
}
Original file line number Diff line number Diff line change
@@ -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 (
<>
<div id={id} className="counter">
<button className="decrement" onClick={subtract}>-</button>
<pre>{count}</pre>
<button className="increment" onClick={add}>+</button>
</div>
<div className="counter-message">{children}</div>
</>
);
}
Loading