mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-07-25 20:14:55 +02:00
refactor
This commit is contained in:
56
.github/scripts/chrome.mts
vendored
56
.github/scripts/chrome.mts
vendored
@@ -5,15 +5,9 @@
|
||||
|
||||
import { createRequire } from 'node:module';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import * as util from './utility.mts';
|
||||
import type { Locator, Browser, BrowserContext, CDPSession, Page } from 'playwright';
|
||||
import type { Browser, BrowserContext, CDPSession, Page } from 'playwright';
|
||||
import type { HeapSnapshotData } from './heap-snapshot-util.mts';
|
||||
|
||||
type LocatorEntry = {
|
||||
name: string;
|
||||
locator: Locator;
|
||||
};
|
||||
|
||||
export type NetworkRequest = {
|
||||
requestId: string;
|
||||
url: string;
|
||||
@@ -449,16 +443,6 @@ export class HeadlessChromeController {
|
||||
return JSON.parse(content);
|
||||
}
|
||||
|
||||
public mkInput(testId: string) {
|
||||
return this.page.locator(`[data-testid="${testId}"] input`);
|
||||
}
|
||||
|
||||
public waitApiResponse(path: string) {
|
||||
return this.page.waitForResponse((response) => {
|
||||
return response.url().endsWith(path) && response.request().method() === 'POST';
|
||||
});
|
||||
}
|
||||
|
||||
public async close() {
|
||||
await this.cdp.detach().catch(() => undefined);
|
||||
await this.context.close().catch(() => undefined);
|
||||
@@ -537,41 +521,3 @@ export function summarizeNetwork(requestRows: NetworkRequest[], baseUrl: string,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export async function isReady(locator: Locator, options: { visible?: boolean; enabled?: boolean }) {
|
||||
const first = locator.first();
|
||||
try {
|
||||
if (await locator.count() === 0) return false;
|
||||
if (options.visible === true && !await first.isVisible()) return false;
|
||||
if (options.enabled === true && !await first.isEnabled()) return false;
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function waitForReady(locator: Locator, options: { timeoutMs: number; visible?: boolean; enabled?: boolean }) {
|
||||
const startedAt = Date.now();
|
||||
while (Date.now() - startedAt < options.timeoutMs) {
|
||||
if (await isReady(locator, options)) return true;
|
||||
await util.sleep(250);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function waitForAnyLocator(entries: LocatorEntry[], options: { timeoutMs: number; visible?: boolean; enabled?: boolean }) {
|
||||
const startedAt = Date.now();
|
||||
while (Date.now() - startedAt < options.timeoutMs) {
|
||||
for (const entry of entries) {
|
||||
if (await isReady(entry.locator, options)) return entry.name;
|
||||
}
|
||||
await util.sleep(250);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function maybeClick(locator: Locator, timeoutMs = 3_000) {
|
||||
if (!await waitForReady(locator, { visible: true, enabled: true, timeoutMs })) return false;
|
||||
await locator.click({ timeout: timeoutMs });
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as util from './utility.mts';
|
||||
import * as heapSnapshotUtil from './heap-snapshot-util.mts';
|
||||
import { HeadlessChromeController, summarizeNetwork } from './chrome.mts';
|
||||
import type { BrowserMeasurement, NetworkRequest, NetworkSummary } from './chrome.mts';
|
||||
import { closeUserSetupDialog, postNote, signupThroughUi, visitHome } from '../../packages/frontend/test/e2e/shared.ts';
|
||||
|
||||
const [baseDirArg, headDirArg, baseOutputArg, headOutputArg, headHeapSnapshotOutputArg] = process.argv.slice(2);
|
||||
|
||||
@@ -37,31 +38,10 @@ async function runSignupAndPostScenario(chrome: HeadlessChromeController) {
|
||||
const page = chrome.page;
|
||||
const noteText = `Frontend browser metrics ${Date.now()}`;
|
||||
|
||||
await page.goto(`${baseUrl}/`, { waitUntil: 'domcontentloaded' });
|
||||
|
||||
await page.getByTestId('signup').click();
|
||||
await page.getByTestId('signup-rules-continue').waitFor({ state: 'visible' });
|
||||
await chrome.page.locator('[data-testid="signup-rules-notes-agree"] [data-testid="switch-toggle"]').click();
|
||||
await page.getByTestId('modal-dialog-ok').click();
|
||||
await page.getByTestId('signup-rules-continue').click();
|
||||
|
||||
await chrome.mkInput('signup-username').fill('alice');
|
||||
await chrome.mkInput('signup-password').fill('password');
|
||||
await chrome.mkInput('signup-password-retype').fill('password');
|
||||
await chrome.mkInput('signup-invitation-code').fill('test-invitation-code');
|
||||
|
||||
const signupResponse = chrome.waitApiResponse('/api/signup');
|
||||
await page.getByTestId('signup-submit').click();
|
||||
await signupResponse;
|
||||
|
||||
await page.locator('[data-testid="user-setup-dialog"] [data-testid="modal-window-close"]').click({ timeout: 30000 });
|
||||
await page.getByTestId('modal-dialog-ok').click();
|
||||
|
||||
await page.getByTestId('open-post-form').waitFor({ state: 'visible' });
|
||||
await page.getByTestId('open-post-form').click();
|
||||
await page.getByTestId('post-form-text').fill(noteText);
|
||||
await page.getByTestId('post-form-submit').click();
|
||||
await page.getByText(noteText).waitFor({ timeout: 10000 });
|
||||
await visitHome(page, baseUrl);
|
||||
await signupThroughUi(page, { username: 'alice', password: 'password' });
|
||||
await closeUserSetupDialog(page);
|
||||
await postNote(page, noteText, 10_000);
|
||||
|
||||
await util.sleep(1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user