Skip to content

Commit

Permalink
Fix e2e flaky tests (#7084)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored May 16, 2023
1 parent cd410c5 commit d7007a1
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 120 deletions.
23 changes: 20 additions & 3 deletions packages/astro/e2e/lit-component.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({
root: './fixtures/lit-component/',
Expand Down Expand Up @@ -30,6 +30,8 @@ test.describe('Lit components', () => {
const count = counter.locator('p');
await expect(count, 'initial count is 10').toHaveText('Count: 10');

await waitForHydrate(page, counter);

const inc = counter.locator('button');
await inc.click();

Expand All @@ -43,6 +45,8 @@ test.describe('Lit components', () => {
const count = counter.locator('p');
await expect(count, 'initial count is 10').toHaveText('Count: 10');

await waitForHydrate(page, counter);

const inc = counter.locator('button');
await inc.click();

Expand All @@ -58,6 +62,8 @@ test.describe('Lit components', () => {
const count = counter.locator('p');
await expect(count, 'initial count is 10').toHaveText('Count: 10');

await waitForHydrate(page, counter);

const inc = counter.locator('button');
await inc.click();

Expand All @@ -75,6 +81,8 @@ test.describe('Lit components', () => {
const count = counter.locator('p');
await expect(count, 'initial count is 10').toHaveText('Count: 10');

await waitForHydrate(page, counter);

const inc = counter.locator('button');
await inc.click();

Expand All @@ -97,12 +105,13 @@ test.describe('Lit components', () => {

// Reset the viewport to hydrate the component (max-width: 50rem)
await page.setViewportSize({ width: 414, height: 1124 });
await waitForHydrate(page, counter);

await inc.click();
await expect(count, 'count incremented by 1').toHaveText('Count: 11');
});

test('client:only', async ({ page, astro }) => {
t('client:only', async ({ page, astro }) => {
await page.goto(astro.resolveUrl('/'));

const label = page.locator('#client-only');
Expand Down Expand Up @@ -157,7 +166,15 @@ test.describe('Lit components', () => {
// Playwright's Node version doesn't have these functions, so stub them.
process.stdout.clearLine = () => {};
process.stdout.cursorTo = () => {};
await astro.build();
try {
await astro.build();
} catch (err) {
// There's this strange error on build since the dev server already defined `my-counter`,
// however the tests still pass with this error, so swallow it.
if (!err.message.includes(`Failed to execute 'define' on 'CustomElementRegistry'`)) {
throw err;
}
}
});

t.beforeAll(async ({ astro }) => {
Expand Down
42 changes: 25 additions & 17 deletions packages/astro/e2e/namespaced-component.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({
root: './fixtures/namespaced-component/',
Expand All @@ -20,31 +20,35 @@ test.describe('Hydrating namespaced components', () => {
await page.goto('/');

// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
const namespacedCounter = await page.locator('#preact-counter-namespace');
const namespacedCounter = page.locator('#preact-counter-namespace');
await expect(namespacedCounter, 'component is visible').toBeVisible();

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

const namespacedChildren = await namespacedCounter.locator('.children');
const namespacedChildren = namespacedCounter.locator('.children');
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');

const namespacedIncrement = await namespacedCounter.locator('.increment');
await waitForHydrate(page, namespacedCounter);

const namespacedIncrement = namespacedCounter.locator('.increment');
await namespacedIncrement.click();

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

// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
const namedCounter = await page.locator('#preact-counter-named');
const namedCounter = page.locator('#preact-counter-named');
await expect(namedCounter, 'component is visible').toBeVisible();

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

const namedChildren = await namedCounter.locator('.children');
const namedChildren = namedCounter.locator('.children');
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');

const namedIncrement = await namedCounter.locator('.increment');
await waitForHydrate(page, namedCounter);

const namedIncrement = namedCounter.locator('.increment');
await namedIncrement.click();

await expect(namedCount, 'count incremented by 1').toHaveText('1');
Expand All @@ -54,31 +58,35 @@ test.describe('Hydrating namespaced components', () => {
await page.goto('/mdx');

// Counter declared with: <ns.components.PreactCounter id="preact-counter-namespace" client:load>
const namespacedCounter = await page.locator('#preact-counter-namespace');
const namespacedCounter = page.locator('#preact-counter-namespace');
await expect(namespacedCounter, 'component is visible').toBeVisible();

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

const namespacedChildren = await namespacedCounter.locator('.children');
const namespacedChildren = namespacedCounter.locator('.children');
await expect(namespacedChildren, 'children exist').toHaveText('preact (namespace import)');

const namespacedIncrement = await namespacedCounter.locator('.increment');
await waitForHydrate(page, namespacedCounter);

const namespacedIncrement = namespacedCounter.locator('.increment');
await namespacedIncrement.click();

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

// Counter declared with: <components.PreactCounterTwo id="preact-counter-named" client:load>
const namedCounter = await page.locator('#preact-counter-named');
const namedCounter = page.locator('#preact-counter-named');
await expect(namedCounter, 'component is visible').toBeVisible();

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

const namedChildren = await namedCounter.locator('.children');
const namedChildren = namedCounter.locator('.children');
await expect(namedChildren, 'children exist').toHaveText('preact (named import)');

const namedIncrement = await namedCounter.locator('.increment');
await waitForHydrate(page, namedCounter);

const namedIncrement = namedCounter.locator('.increment');
await namedIncrement.click();

await expect(namedCount, 'count incremented by 1').toHaveText('1');
Expand Down
42 changes: 26 additions & 16 deletions packages/astro/e2e/nested-in-preact.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/nested-in-preact/' });

Expand All @@ -17,13 +17,15 @@ test.describe('Nested Frameworks in Preact', () => {
test('React counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#react-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -32,13 +34,15 @@ test.describe('Nested Frameworks in Preact', () => {
test('Preact counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#preact-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -47,13 +51,15 @@ test.describe('Nested Frameworks in Preact', () => {
test('Solid counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#solid-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -62,13 +68,15 @@ test.describe('Nested Frameworks in Preact', () => {
test('Vue counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#vue-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -77,13 +85,15 @@ test.describe('Nested Frameworks in Preact', () => {
test('Svelte counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#svelte-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand Down
42 changes: 26 additions & 16 deletions packages/astro/e2e/nested-in-react.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/nested-in-react/' });

Expand All @@ -17,13 +17,15 @@ test.describe('Nested Frameworks in React', () => {
test('React counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#react-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -32,13 +34,15 @@ test.describe('Nested Frameworks in React', () => {
test('Preact counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#preact-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -47,13 +51,15 @@ test.describe('Nested Frameworks in React', () => {
test('Solid counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#solid-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -62,13 +68,15 @@ test.describe('Nested Frameworks in React', () => {
test('Vue counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#vue-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand All @@ -77,13 +85,15 @@ test.describe('Nested Frameworks in React', () => {
test('Svelte counter', async ({ astro, page }) => {
await page.goto('/');

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

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

const increment = await counter.locator('#svelte-counter-increment');
await waitForHydrate(page, counter);

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

await expect(count, 'count incremented by 1').toHaveText('1');
Expand Down
Loading

0 comments on commit d7007a1

Please sign in to comment.