Skip to content

Commit 9629e94

Browse files
authored
Merge pull request codediodeio#107 from mxschmitt/test--minor-e2e-test-nit-enhancements
test: minor e2e test enhancements
2 parents fc380cd + 6e71f58 commit 9629e94

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
node-version: 18
1818
- run: npm ci
19-
- run: npx playwright install --with-deps
19+
- run: npx playwright install --with-deps chromium
2020
- run: npx playwright test
2121
- uses: actions/upload-artifact@v3
2222
if: always()

playwright.config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import type { PlaywrightTestConfig } from '@playwright/test';
1+
import { defineConfig } from '@playwright/test';
22

3-
const config: PlaywrightTestConfig = {
3+
export default defineConfig({
44
webServer: {
55
command: 'npm run build && npm run preview',
66
port: 4173
77
},
88
testDir: 'tests',
99
testMatch: /(.+\.)?(test|spec)\.[jt]s/
10-
};
11-
12-
export default config;
10+
});

tests/auth.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import { expect, test, type Page } from "@playwright/test";
22

3-
test.describe("Auth", () => {
3+
test.describe.serial("Auth", () => {
44
let page: Page;
55
test.beforeAll(async ({ browser }) => {
66
page = await browser.newPage();
77
await page.goto("/auth-test");
88
});
9+
test.afterAll(async () => {
10+
await page.close();
11+
});
912

1013
test("Renders UI conditionally based on auth state", async () => {
11-
expect(page.getByText("Signed In")).not.toBeVisible();
12-
expect(page.getByText("Signed Out")).toBeVisible();
14+
await expect(page.getByText("Signed Out")).toBeVisible();
15+
await expect(page.getByText("Signed In")).toBeHidden();
1316
});
1417

1518
test("User can sign in and out", async () => {
16-
await page.click("text=Sign In");
17-
await page.waitForSelector("text=Sign Out");
19+
await page.getByRole("button", { name: "Sign In" }).click();
20+
await expect(page.getByRole("button", { name: "Sign Out" })).toBeVisible();
1821
await expect(page.getByText("Signed In")).toBeVisible();
1922

20-
await page.click("text=Sign Out");
21-
await page.waitForSelector("text=Sign In");
22-
await expect(page.getByText("Signed In")).not.toBeVisible();
23+
await page.getByRole("button", { name: "Sign Out" }).click();
24+
await expect(page.getByRole("button", { name: "Sign In" })).toBeVisible();
25+
await expect(page.getByText("Signed In")).toBeHidden();
2326
});
2427
});

tests/firestore.test.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import { expect, test } from '@playwright/test';
22

3-
43
test('Renders a single document', async ({ page }) => {
54
await page.goto('/firestore-test');
6-
await expect( page.getByTestId('doc-data') ).toContainText('Hi Mom');
7-
5+
await expect(page.getByTestId('doc-data')).toContainText('Hi Mom');
86
});
97

108
test('Renders a collection of items for an authenticated user in realtime', async ({ page }) => {
119
await page.goto('/firestore-test');
12-
13-
await page.click('text=Sign In');
14-
await expect( page.getByTestId('count') ).toContainText('0 posts');
15-
(await page.waitForSelector('text=Add Post')).click();
16-
await expect( page.getByTestId('count') ).toContainText('1 posts');
17-
(await page.waitForSelector('text=Add Post')).click();
18-
await expect( page.getByTestId('count') ).toContainText('2 posts');
19-
expect( (await page.$$('li')).length ).toBe(2);
20-
expect(await page.textContent('li')).toContain('firestore item');
21-
10+
await page.getByRole('button', { 'name': 'Sign In'}).click();
11+
await expect(page.getByTestId('count')).toContainText('0 posts');
12+
await page.getByRole('button', { name: 'Add Post' }).click();
13+
await expect(page.getByTestId('count')).toContainText('1 posts');
14+
await page.getByRole('button', { name: 'Add Post' }).click();
15+
await expect(page.getByTestId('count')).toContainText('2 posts');
16+
await expect(page.locator('li')).toHaveCount(2);
17+
await expect(page.locator('li')).toContainText([
18+
'firestore item',
19+
'firestore item'
20+
]);
2221
});
23-

tests/main.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect, test } from '@playwright/test';
22

33
test('SvelteFire app initializes properly', async ({ page }) => {
44
await page.goto('/');
5-
expect(await page.textContent('h1')).toBe('Welcome to SvelteFire');
5+
await expect(page.locator('h1')).toHaveText('Welcome to SvelteFire');
66
});
77

88
test('Firebase SDK context is defined via FirebaseApp component', async ({ page }) => {
99
await page.goto('/');
10-
await expect( page.getByTestId('auth')).toContainText('true');
11-
await expect( page.getByTestId('firestore')).toContainText('true');
12-
});
10+
await expect(page.getByTestId('auth')).toContainText('true');
11+
await expect(page.getByTestId('firestore')).toContainText('true');
12+
});

0 commit comments

Comments
 (0)