Skip to content

Commit

Permalink
Improve e2e setup (#11850)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 27, 2024
1 parent b601e47 commit ccce6d2
Show file tree
Hide file tree
Showing 45 changed files with 97 additions and 106 deletions.
16 changes: 7 additions & 9 deletions packages/astro/e2e/actions-blog.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

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

let devServer;

Expand All @@ -23,11 +23,10 @@ test.describe('Astro Actions - Blog', () => {
await page.goto(astro.resolveUrl('/blog/first-post/'));

const likeButton = page.getByLabel('Like');
await waitForHydrate(page, likeButton);
await expect(likeButton, 'like button starts with 10 likes').toContainText('10');
await likeButton.click();
await expect(likeButton, 'like button should increment likes').toContainText('11', {
timeout: 6_000,
});
await expect(likeButton, 'like button should increment likes').toContainText('11');
});

test('Like action - server-side', async ({ page, astro }) => {
Expand All @@ -38,9 +37,7 @@ test.describe('Astro Actions - Blog', () => {

await expect(likeCount, 'like button starts with 10 likes').toContainText('10');
await likeButton.click();
await expect(likeCount, 'like button should increment likes').toContainText('11', {
timeout: 6_000,
});
await expect(likeCount, 'like button should increment likes').toContainText('11');
});

test('Comment action - validation error', async ({ page, astro }) => {
Expand Down Expand Up @@ -134,7 +131,8 @@ test.describe('Astro Actions - Blog', () => {
await page.goto(astro.resolveUrl('/blog/first-post/'));

const logoutButton = page.getByTestId('logout-button');
await waitForHydrate(page, logoutButton);
await logoutButton.click();
await expect(page).toHaveURL(astro.resolveUrl('/blog/'), { timeout: 6_000 });
await expect(page).toHaveURL(astro.resolveUrl('/blog/'));
});
});
10 changes: 7 additions & 3 deletions packages/astro/e2e/actions-react-19.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/actions-react-19/' });
const test = testFactory(import.meta.url, { root: './fixtures/actions-react-19/' });

let devServer;

Expand All @@ -23,10 +23,12 @@ test.describe('Astro Actions - React 19', () => {
await page.goto(astro.resolveUrl('/blog/first-post/'));

const likeButton = page.getByLabel('likes-client');
await waitForHydrate(page, likeButton);

await expect(likeButton).toBeVisible();
await likeButton.click();
await expect(likeButton, 'like button should be disabled when pending').toBeDisabled();
await expect(likeButton).not.toBeDisabled({ timeout: 5000 });
await expect(likeButton).not.toBeDisabled();
});

test('Like action - server progressive enhancement', async ({ page, astro }) => {
Expand All @@ -43,6 +45,8 @@ test.describe('Astro Actions - React 19', () => {
await page.goto(astro.resolveUrl('/blog/first-post/'));

const likeButton = page.getByLabel('likes-action-client');
await waitForHydrate(page, likeButton);

await expect(likeButton).toBeVisible();
await likeButton.click();

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/astro-component.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/astro-envs.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/astro-envs/',
devToolbar: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/client-only.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/content-collections.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/css.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/css/',
devToolbar: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/custom-client-directives.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from '@playwright/test';
import testAdapter from '../test/test-adapter.js';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/custom-client-directives/',
});

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/dev-toolbar-audits.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/dev-toolbar.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/error-cyclic.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { getErrorOverlayContent, testFactory } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/error-sass.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { getErrorOverlayContent, testFactory } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { getErrorOverlayContent, testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/errors/',
// Only test the error overlay, don't print to console
vite: {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/hmr.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/hmr/',
devToolbar: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/hydration-race.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/i18n.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/i18n/',
devToolbar: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/lit-component.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/multiple-frameworks.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/namespaced-component.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

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

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-in-preact.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-in-react.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

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

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-in-solid.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/nested-in-solid/' });
const test = testFactory(import.meta.url, { root: './fixtures/nested-in-solid/' });

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-in-svelte.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/nested-in-svelte/' });
const test = testFactory(import.meta.url, { root: './fixtures/nested-in-svelte/' });

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-in-vue.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory, waitForHydrate } from './test-utils.js';

const test = testFactory({ root: './fixtures/nested-in-vue/' });
const test = testFactory(import.meta.url, { root: './fixtures/nested-in-vue/' });

let devServer;

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-recursive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { loadFixture, waitForHydrate } from './test-utils.js';

const test = base.extend({
astro: async ({}, use) => {
const fixture = await loadFixture({ root: './fixtures/nested-recursive/' });
const fixture = await loadFixture(import.meta.url, { root: './fixtures/nested-recursive/' });
await use(fixture);
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/nested-styles.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/nested-styles/',
devToolbar: {
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/pass-js.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/e2e/preact-compat-component.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-compat-component/' });
const { test, createTests } = prepareTestFactory(import.meta.url, {
root: './fixtures/preact-compat-component/',
});

const config = {
counterComponentFilePath: './src/components/Counter.jsx',
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/e2e/preact-component.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-component/' });
const { test, createTests } = prepareTestFactory(import.meta.url, {
root: './fixtures/preact-component/',
});

const config = {
counterComponentFilePath: './src/components/Counter.jsx',
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/e2e/preact-lazy-component.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory({ root: './fixtures/preact-lazy-component/' });
const { test, createTests } = prepareTestFactory(import.meta.url, {
root: './fixtures/preact-lazy-component/',
});

const config = {
counterComponentFilePath: './src/components/Counter.jsx',
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/prefetch.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

const test = testFactory({
const test = testFactory(import.meta.url, {
root: './fixtures/prefetch/',
});

Expand Down
4 changes: 3 additions & 1 deletion packages/astro/e2e/react-component.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { expect } from '@playwright/test';
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory({ root: './fixtures/react-component/' });
const { test, createTests } = prepareTestFactory(import.meta.url, {
root: './fixtures/react-component/',
});

const config = {
counterComponentFilePath: './src/components/Counter.jsx',
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/server-islands.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

test.describe('Server islands', () => {
test.describe('Development', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/astro/e2e/shared-component-tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from '@playwright/test';
import { scrollToElement, testFactory, waitForHydrate } from './test-utils.js';

export function prepareTestFactory(opts, { canReplayClicks = false } = {}) {
const test = testFactory(opts);
export function prepareTestFactory(testFile, opts, { canReplayClicks = false } = {}) {
const test = testFactory(testFile, opts);

let devServer;

Expand Down Expand Up @@ -120,6 +120,7 @@ export function prepareTestFactory(opts, { canReplayClicks = false } = {}) {
await page.goto(astro.resolveUrl(pageUrl));

const label = page.locator('#client-only');
await waitForHydrate(page, label);
await expect(label, 'component is visible').toBeVisible();

await expect(label, 'slot text is visible').toHaveText('Framework client:only component');
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/solid-circular.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';

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

let devServer;

Expand Down
1 change: 1 addition & 0 deletions packages/astro/e2e/solid-component.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prepareTestFactory } from './shared-component-tests.js';

const { test, createTests } = prepareTestFactory(
import.meta.url,
{ root: './fixtures/solid-component/' },
{
canReplayClicks: true,
Expand Down
Loading

0 comments on commit ccce6d2

Please sign in to comment.