Skip to content

Commit d86abd1

Browse files
committed
chore(e2e): some small typing improvements
1 parent aaee3c0 commit d86abd1

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');
@@ -108,10 +106,7 @@ test.describe('WebHelp page appearance', async () => {
108106
test(`Should render layout of the article properly on ${resolutionName}`, async ({ page }) => {
109107
await page.setViewportSize(resolution);
110108
const screenshot = await page.screenshot({ fullPage: true });
111-
expect(screenshot).toMatchSnapshot({
112-
name: `layout_${resolutionName}.png`,
113-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
114-
});
109+
expect(screenshot).toMatchSnapshot(`layout_${resolutionName}.png`);
115110
});
116111

117112
test(`Should render micro format properly on ${resolutionName}`, async ({ page }) => {
@@ -168,32 +163,23 @@ test.describe('WebHelp page appearance', async () => {
168163
await page.setViewportSize(resolution);
169164
const codeBlock = page.locator(testSelector('code-block')).filter({ hasText: 'MessageService' }).first();
170165
const screenshot = await codeBlock.screenshot();
171-
expect(screenshot).toMatchSnapshot({
172-
name: `code-block_${resolutionName}.png`,
173-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
174-
});
166+
expect(screenshot).toMatchSnapshot(`code-block_${resolutionName}.png`);
175167
});
176168

177169
test(`Should render hovered codeblock properly on ${resolutionName}`, async ({ page }) => {
178170
await page.setViewportSize(resolution);
179171
const codeBlock = page.locator(testSelector('code-block')).filter({ hasText: 'MessageService' }).first();
180172
await codeBlock.hover();
181173
const screenshot = await codeBlock.screenshot();
182-
expect(screenshot).toMatchSnapshot({
183-
name: `code-block_hovered_${resolutionName}.png`,
184-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
185-
});
174+
expect(screenshot).toMatchSnapshot(`code-block_hovered_${resolutionName}.png`);
186175
});
187176

188177
test(`Should render expandable codeblock properly on ${resolutionName}`, async ({ page }) => {
189178
await page.setViewportSize(resolution);
190179
const codeBlock = page.locator(testSelector('code-collapse')).filter({ hasText: 'package' }).first();
191180
const codeBlockElement = await codeBlock.elementHandle();
192181
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
193-
expect(screenshot).toMatchSnapshot({
194-
name: `code-block_expandable_${resolutionName}.png`,
195-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
196-
});
182+
expect(screenshot).toMatchSnapshot(`code-block_expandable_${resolutionName}.png`);
197183
});
198184

199185
test(`Should render expandable codeblock when expanded properly on ${resolutionName}`, async ({ page }) => {
@@ -203,10 +189,7 @@ test.describe('WebHelp page appearance', async () => {
203189
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT_LONG);
204190
const codeBlockElement = await codeBlock.elementHandle();
205191
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
206-
expect(screenshot).toMatchSnapshot({
207-
name: `code-block_expandable_expanded_${resolutionName}.png`,
208-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
209-
});
192+
expect(screenshot).toMatchSnapshot(`code-block_expandable_expanded_${resolutionName}.png`);
210193
});
211194

212195
test(`Should render collapsed codeblock properly on ${resolutionName}`, async ({ page }) => {
@@ -219,10 +202,7 @@ test.describe('WebHelp page appearance', async () => {
219202
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT_LONG);
220203
const codeBlockElement = await codeBlock.elementHandle();
221204
const screenshot = await getElementScreenshotWithPadding(page, codeBlockElement, ELEMENT_PADDING_OFFSET);
222-
expect(screenshot).toMatchSnapshot({
223-
name: `code-block_expandable_${resolutionName}.png`,
224-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
225-
});
205+
expect(screenshot).toMatchSnapshot(`code-block_expandable_${resolutionName}.png`);
226206
});
227207

228208
test(`Should render playground properly on ${resolutionName}`, async ({ page }) => {
@@ -277,10 +257,7 @@ test.describe('WebHelp page appearance', async () => {
277257
await page.setViewportSize(resolution);
278258
const element = page.locator('div.table').filter({ hasText: 'Dependencies' }).first();
279259
const screenshot = await element.screenshot();
280-
expect(screenshot).toMatchSnapshot({
281-
name: `table_complex_codeblocks_${resolutionName}.png`,
282-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
283-
});
260+
expect(screenshot).toMatchSnapshot(`table_complex_codeblocks_${resolutionName}.png`);
284261
});
285262

286263
test(`Should render ordered list properly on ${resolutionName}`, async ({ page }) => {
@@ -345,10 +322,7 @@ test.describe('WebHelp page appearance', async () => {
345322
await page.locator('dt').first().click();
346323
await page.waitForTimeout(MICRO_ANIMATION_TIMEOUT);
347324
const screenshot = await getElementScreenshotWithPadding(page, element, ELEMENT_PADDING_OFFSET);
348-
expect(screenshot).toMatchSnapshot({
349-
name: `definition-list_expanded_${resolutionName}.png`,
350-
maxDiffPixelRatio: MAX_DIFF_PIXEL_RATIO
351-
});
325+
expect(screenshot).toMatchSnapshot(`definition-list_expanded_${resolutionName}.png`);
352326
});
353327

354328
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)