Skip to content

Commit 379d44a

Browse files
committed
chore(e2e): some small typing improvements
1 parent 321c0c0 commit 379d44a

File tree

7 files changed

+46
-70
lines changed

7 files changed

+46
-70
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ generated
5050

5151
/reports*
5252
/data/page_views_map.json
53+
test-results

playwright.config.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

playwright.config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig, devices } from '@playwright/test';
2+
3+
const MAX_DIFF_PIXEL_RATIO = 0.025 as const;
4+
5+
export default defineConfig({
6+
forbidOnly: !!process.env.CI,
7+
retries: process.env.CI ? 2 : 0,
8+
reporter: process.env.CI ? 'dot' : 'list',
9+
snapshotDir: 'test/snapshots',
10+
expect: {
11+
toMatchSnapshot: { maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO },
12+
toHaveScreenshot: { maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO }
13+
},
14+
use: {
15+
baseURL: process.env.BASE_URL || 'http://localhost:9000',
16+
trace: 'off'
17+
},
18+
projects: [
19+
{
20+
name: 'chromium',
21+
use: { ...devices['Desktop Chrome'] }
22+
}
23+
]
24+
});

test/e2e/api-references-template-customization.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { expect, test } from '@playwright/test';
1+
import { expect, Page, test } from '@playwright/test';
22
import { ApiReferencePage } from '../page/api-reference-page';
33

44
const pagesWithCustomizedTemplates = [
55
{
66
name: 'kotlinx.coroutines index',
7-
getInstance: (page) => new ApiReferencePage(page, '/api/kotlinx.coroutines/'),
7+
getInstance: (page: Page) => new ApiReferencePage(page, '/api/kotlinx.coroutines/'),
88
},
99
{
1010
name: 'kotlinx-coroutines-core module',
11-
getInstance: (page) => new ApiReferencePage(page, '/api/kotlinx.coroutines/kotlinx-coroutines-core/'),
11+
getInstance: (page: Page) => new ApiReferencePage(page, '/api/kotlinx.coroutines/kotlinx-coroutines-core/'),
1212
},
1313
{
1414
name: 'kotlinx-serialization index',
15-
getInstance: (page) => new ApiReferencePage(page, '/api/kotlinx.serialization/'),
15+
getInstance: (page: Page) => new ApiReferencePage(page, '/api/kotlinx.serialization/'),
1616
},
1717
{
1818
name: 'kotlinx-serialization-core module',
19-
getInstance: (page) => new ApiReferencePage(page, '/api/kotlinx.serialization/kotlinx-serialization-core/'),
19+
getInstance: (page: Page) => new ApiReferencePage(page, '/api/kotlinx.serialization/kotlinx-serialization-core/'),
2020
},
2121
];
2222

test/e2e/webhelp.spec.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
import { getElementScreenshotWithPadding } from './utils';
1111
import os from 'os';
1212

13-
const MAX_DIFF_PIXEL_RATIO = 0.011;
14-
1513
test.describe('WebHelp page appearance', async () => {
1614
test.beforeEach(async ({ page }) => {
1715
const webHelpPage = new WebHelpPage(page, '/docs/test-page.html');
@@ -102,10 +100,7 @@ test.describe('WebHelp page appearance', async () => {
102100
test(`Should render layout of the article properly on ${resolutionName}`, async ({ page }) => {
103101
await page.setViewportSize(resolution);
104102
const screenshot = await page.screenshot({ fullPage: true });
105-
expect(screenshot).toMatchSnapshot({
106-
name: `layout_${resolutionName}.png`,
107-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
108-
});
103+
expect(screenshot).toMatchSnapshot(`layout_${resolutionName}.png`);
109104
});
110105

111106
test(`Should render micro format properly on ${resolutionName}`, async ({ page }) => {
@@ -162,32 +157,23 @@ test.describe('WebHelp page appearance', async () => {
162157
await page.setViewportSize(resolution);
163158
const codeBlock = page.locator(testSelector('code-block')).filter({ hasText: 'MessageService' }).first();
164159
const screenshot = await codeBlock.screenshot();
165-
expect(screenshot).toMatchSnapshot({
166-
name: `code-block_${resolutionName}.png`,
167-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
168-
});
160+
expect(screenshot).toMatchSnapshot(`code-block_${resolutionName}.png`);
169161
});
170162

171163
test(`Should render hovered codeblock properly on ${resolutionName}`, async ({ page }) => {
172164
await page.setViewportSize(resolution);
173165
const codeBlock = page.locator(testSelector('code-block')).filter({ hasText: 'MessageService' }).first();
174166
await codeBlock.hover();
175167
const screenshot = await codeBlock.screenshot();
176-
expect(screenshot).toMatchSnapshot({
177-
name: `code-block_hovered_${resolutionName}.png`,
178-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
179-
});
168+
expect(screenshot).toMatchSnapshot(`code-block_hovered_${resolutionName}.png`);
180169
});
181170

182171
test(`Should render expandable codeblock properly on ${resolutionName}`, async ({ page }) => {
183172
await page.setViewportSize(resolution);
184173
const codeBlock = page.locator(testSelector('code-collapse')).filter({ hasText: 'package' }).first();
185174
const codeBlockElement = await codeBlock.elementHandle();
186175
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
187-
expect(screenshot).toMatchSnapshot({
188-
name: `code-block_expandable_${resolutionName}.png`,
189-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
190-
});
176+
expect(screenshot).toMatchSnapshot(`code-block_expandable_${resolutionName}.png`);
191177
});
192178

193179
test(`Should render expandable codeblock when expanded properly on ${resolutionName}`, async ({ page }) => {
@@ -197,10 +183,7 @@ test.describe('WebHelp page appearance', async () => {
197183
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT_LONG);
198184
const codeBlockElement = await codeBlock.elementHandle();
199185
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
200-
expect(screenshot).toMatchSnapshot({
201-
name: `code-block_expandable_expanded_${resolutionName}.png`,
202-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
203-
});
186+
expect(screenshot).toMatchSnapshot(`code-block_expandable_expanded_${resolutionName}.png`);
204187
});
205188

206189
test(`Should render collapsed codeblock properly on ${resolutionName}`, async ({ page }) => {
@@ -213,10 +196,7 @@ test.describe('WebHelp page appearance', async () => {
213196
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT_LONG);
214197
const codeBlockElement = await codeBlock.elementHandle();
215198
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
216-
expect(screenshot).toMatchSnapshot({
217-
name: `code-block_expandable_${resolutionName}.png`,
218-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
219-
});
199+
expect(screenshot).toMatchSnapshot(`code-block_expandable_${resolutionName}.png`);
220200
});
221201

222202
test(`Should render playground properly on ${resolutionName}`, async ({ page }) => {
@@ -271,10 +251,7 @@ test.describe('WebHelp page appearance', async () => {
271251
await page.setViewportSize(resolution);
272252
const element = page.locator('div.table').filter({ hasText: 'Dependencies' }).first();
273253
const screenshot = await element.screenshot();
274-
expect(screenshot).toMatchSnapshot({
275-
name: `table_complex_codeblocks_${resolutionName}.png`,
276-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
277-
});
254+
expect(screenshot).toMatchSnapshot(`table_complex_codeblocks_${resolutionName}.png`);
278255
});
279256

280257
test(`Should render ordered list properly on ${resolutionName}`, async ({ page }) => {
@@ -339,10 +316,7 @@ test.describe('WebHelp page appearance', async () => {
339316
await page.locator('dt').first().click();
340317
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT);
341318
const screenshot = await getElementScreenshotWithPadding(page, element, ELEMENT_PADDING_OFFSET);
342-
expect(screenshot).toMatchSnapshot({
343-
name: `definition-list_expanded_${resolutionName}.png`,
344-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
345-
});
319+
expect(screenshot).toMatchSnapshot(`definition-list_expanded_${resolutionName}.png`);
346320
});
347321

348322
test(`Should render markdown image properly on ${resolutionName}`, async ({ page }) => {

test/production/global-search.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import { test } from '@playwright/test';
1+
import { Page, test } from '@playwright/test';
22

33
import { IndexPage } from '../page/index-page';
44
import { CommunityPage } from '../page/community-page';
5-
import { TeachPage } from '../page/teach-page';
5+
import { TeachPage } from '../page/teach/education';
66
import { closeCookiesConsentBanner } from '../utils';
77

88
const SEARCH_STRING = 'Community';
99

1010
const pagesWithGlobalSearch = [
1111
{
1212
name: 'Index',
13-
getInstance: (page) => new IndexPage(page),
13+
getInstance: (page: Page) => new IndexPage(page)
1414
},
1515
{
1616
name: 'Community',
17-
getInstance: (page) => new CommunityPage(page),
17+
getInstance: (page: Page) => new CommunityPage(page)
1818
},
1919
// {
2020
// name: 'Teach',
21-
// getInstance: (page) => new TeachPage(page),
22-
// },
21+
// getInstance: (page: Page) => new TeachPage(page)
22+
// }
2323
];
2424

2525
test.describe.configure({ mode: 'parallel' });
2626

2727
test.describe('Global Search Component', async () => {
28-
test.beforeEach(async ({ context , baseURL}) => {
28+
test.beforeEach(async ({ context, baseURL }) => {
2929
await closeCookiesConsentBanner(context, baseURL);
3030
});
3131

test/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BrowserContext } from '@playwright/test';
22

3-
export const testSelector = (name) => `[data-test="${name}"]`;
3+
export const testSelector = (name: string) => `[data-test="${name}"]`;
44

55
export function isStaging(baseURL: string): boolean {
66
const { hostname } = new URL(baseURL);

0 commit comments

Comments
 (0)