Merge branch 'main' into feature/nation-deception-boundary-parity
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const frontendPort = 15112;
|
||||
const apiPort = 15113;
|
||||
|
||||
export default defineConfig({
|
||||
testDir: '.',
|
||||
testMatch: ['main-front-status.spec.ts'],
|
||||
fullyParallel: false,
|
||||
workers: 1,
|
||||
timeout: 60_000,
|
||||
expect: { timeout: 10_000 },
|
||||
reporter: [['list']],
|
||||
outputDir: process.env.SAMMO_TEST_OUTPUT_DIR ?? resolve(repositoryRoot, 'test-results/main-front-status-live'),
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
baseURL: `http://127.0.0.1:${frontendPort}/che/`,
|
||||
colorScheme: 'dark',
|
||||
deviceScaleFactor: 1,
|
||||
locale: 'ko-KR',
|
||||
timezoneId: 'UTC',
|
||||
trace: 'retain-on-failure',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
webServer: [
|
||||
{
|
||||
command:
|
||||
`GAME_API_HOST=127.0.0.1 GAME_API_PORT=${apiPort} ` +
|
||||
'GAME_TRPC_PATH=/che/api/trpc GAME_API_EVENTS_PATH=/che/api/events ' +
|
||||
'PROFILE=che SCENARIO=default GAME_PROFILE_NAME=che:default node app/game-api/dist/index.js',
|
||||
cwd: repositoryRoot,
|
||||
url: `http://127.0.0.1:${apiPort}/che/api/trpc/health.ping?input=%7B%22json%22%3Anull%7D`,
|
||||
reuseExistingServer: false,
|
||||
timeout: 120_000,
|
||||
},
|
||||
{
|
||||
command:
|
||||
`VITE_APP_BASE_PATH=/che VITE_GAME_API_URL=http://127.0.0.1:${apiPort}/che/api/trpc ` +
|
||||
`VITE_GAME_SSE_URL=http://127.0.0.1:${apiPort}/che/api/events ` +
|
||||
'pnpm --filter @sammo-ts/game-frontend build && ' +
|
||||
`VITE_APP_BASE_PATH=/che VITE_GAME_API_URL=http://127.0.0.1:${apiPort}/che/api/trpc ` +
|
||||
`VITE_GAME_SSE_URL=http://127.0.0.1:${apiPort}/che/api/events ` +
|
||||
`pnpm --filter @sammo-ts/game-frontend preview --host 127.0.0.1 --port ${frontendPort}`,
|
||||
cwd: repositoryRoot,
|
||||
url: `http://127.0.0.1:${frontendPort}/che/`,
|
||||
reuseExistingServer: false,
|
||||
timeout: 120_000,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,341 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { expect, test, type Page, type Route } from '@playwright/test';
|
||||
import {
|
||||
createGamePostgresConnector,
|
||||
createRedisConnector,
|
||||
GamePrisma,
|
||||
resolvePostgresConfigFromEnv,
|
||||
resolveRedisConfigFromEnv,
|
||||
type GamePrismaClient,
|
||||
type RedisConnector,
|
||||
} from '../../packages/infra/src/index.js';
|
||||
|
||||
const marker = `main-front-status-live-${randomUUID()}`;
|
||||
const accessToken = `ga_${randomUUID()}`;
|
||||
let postgres: ReturnType<typeof createGamePostgresConnector>;
|
||||
let redis: RedisConnector;
|
||||
let prisma: GamePrismaClient;
|
||||
let fixture: { generalId: number; nationId: number; userId: string; voteId: number } | null = null;
|
||||
|
||||
const accessKey = (token: string) => `sammo:game:access:che:default:${token}`;
|
||||
const response = (data: unknown) => ({ result: { data } });
|
||||
const errorResponse = (path: string, message: string) => ({
|
||||
error: {
|
||||
message,
|
||||
code: -32000,
|
||||
data: { code: 'INTERNAL_SERVER_ERROR', httpStatus: 500, path },
|
||||
},
|
||||
});
|
||||
const operationNames = (route: Route): string[] => {
|
||||
const pathname = decodeURIComponent(new URL(route.request().url()).pathname);
|
||||
return pathname.slice(pathname.lastIndexOf('/trpc/') + 6).split(',');
|
||||
};
|
||||
|
||||
test.beforeAll(async () => {
|
||||
postgres = createGamePostgresConnector(resolvePostgresConfigFromEnv({ schema: 'che' }));
|
||||
redis = createRedisConnector(resolveRedisConfigFromEnv());
|
||||
await postgres.connect();
|
||||
await redis.connect();
|
||||
prisma = postgres.prisma;
|
||||
|
||||
const world = await prisma.worldState.findFirst({ orderBy: { id: 'asc' }, select: { id: true } });
|
||||
if (!world) {
|
||||
throw new Error('The live che profile needs a world state.');
|
||||
}
|
||||
const [generalMax, nationMax] = await Promise.all([
|
||||
prisma.general.aggregate({ _max: { id: true } }),
|
||||
prisma.nation.aggregate({ _max: { id: true } }),
|
||||
]);
|
||||
const nationId = (nationMax._max.id ?? 0) + 10_000;
|
||||
const generalId = (generalMax._max.id ?? 0) + 10_000;
|
||||
const userId = `main-front-status-${randomUUID()}`;
|
||||
await prisma.$executeRaw(
|
||||
GamePrisma.sql`
|
||||
INSERT INTO nation (id, name, color, meta)
|
||||
VALUES (
|
||||
${nationId},
|
||||
${'검증국'},
|
||||
${'#336699'},
|
||||
${JSON.stringify({ notice: `<p>${marker} 국가 방침</p>` })}::jsonb
|
||||
)
|
||||
`
|
||||
);
|
||||
await prisma.$executeRaw(
|
||||
GamePrisma.sql`
|
||||
INSERT INTO general (id, user_id, name, nation_id, city_id, turn_time)
|
||||
VALUES (${generalId}, ${userId}, ${'현황검증장수'}, ${nationId}, ${0}, ${new Date()})
|
||||
`
|
||||
);
|
||||
await prisma.generalAccessLog.create({
|
||||
data: {
|
||||
generalId,
|
||||
userId,
|
||||
lastRefresh: new Date(),
|
||||
refresh: 1,
|
||||
refreshTotal: 1,
|
||||
refreshScore: 1,
|
||||
refreshScoreTotal: 1,
|
||||
},
|
||||
});
|
||||
const poll = await prisma.votePoll.create({
|
||||
data: {
|
||||
title: '검증 설문',
|
||||
body: '',
|
||||
options: ['찬성', '반대'],
|
||||
multipleOptions: 1,
|
||||
revealMode: 'after_vote',
|
||||
openerGeneralId: generalId,
|
||||
openerName: '현황검증장수',
|
||||
startAt: new Date(Date.now() - 60_000),
|
||||
endAt: new Date(Date.now() + 3_600_000),
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
fixture = { generalId, nationId, userId, voteId: poll.id };
|
||||
|
||||
const issuedAt = new Date();
|
||||
await redis.client.set(
|
||||
accessKey(accessToken),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profile: 'che:default',
|
||||
issuedAt: issuedAt.toISOString(),
|
||||
expiresAt: new Date(issuedAt.getTime() + 30 * 60 * 1000).toISOString(),
|
||||
sessionId: `main-front-status-${randomUUID()}`,
|
||||
user: {
|
||||
id: userId,
|
||||
username: 'main-front-status-live',
|
||||
displayName: '현황검증장수',
|
||||
roles: [],
|
||||
},
|
||||
sanctions: {},
|
||||
}),
|
||||
{ EX: 1800 }
|
||||
);
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
if (fixture) {
|
||||
await prisma.votePoll.deleteMany({ where: { id: fixture.voteId } });
|
||||
await prisma.generalAccessLog.deleteMany({ where: { generalId: fixture.generalId } });
|
||||
await prisma.$executeRaw(GamePrisma.sql`DELETE FROM general WHERE id = ${fixture.generalId}`);
|
||||
await prisma.$executeRaw(GamePrisma.sql`DELETE FROM nation WHERE id = ${fixture.nationId}`);
|
||||
const [generalCount, nationCount, voteCount, accessCount] = await Promise.all([
|
||||
prisma.general.count({ where: { id: fixture.generalId } }),
|
||||
prisma.nation.count({ where: { id: fixture.nationId } }),
|
||||
prisma.votePoll.count({ where: { id: fixture.voteId } }),
|
||||
prisma.generalAccessLog.count({ where: { generalId: fixture.generalId } }),
|
||||
]);
|
||||
expect([generalCount, nationCount, voteCount, accessCount]).toEqual([0, 0, 0, 0]);
|
||||
}
|
||||
await redis.client.del(accessKey(accessToken));
|
||||
await redis.disconnect();
|
||||
await postgres.disconnect();
|
||||
});
|
||||
|
||||
const installMainFixture = async (
|
||||
page: Page,
|
||||
liveStatus: {
|
||||
onlineUserCount: number;
|
||||
onlineNations: string;
|
||||
onlineGenerals: string;
|
||||
nationNotice: string;
|
||||
lastExecuted: string | null;
|
||||
latestVote: { id: number; title: string; hasVoted: boolean } | null;
|
||||
},
|
||||
failStatus: () => boolean
|
||||
) => {
|
||||
await page.addInitScript(
|
||||
({ token }) => {
|
||||
window.localStorage.setItem('sammo-game-token', token);
|
||||
window.localStorage.setItem('sammo-game-profile', 'che:default');
|
||||
},
|
||||
{ token: accessToken }
|
||||
);
|
||||
await page.route('**/che/api/trpc/**', async (route) => {
|
||||
const results = operationNames(route).map((operation) => {
|
||||
if (operation === 'general.me') {
|
||||
return response({
|
||||
general: {
|
||||
id: fixture?.generalId ?? 1,
|
||||
name: '현황검증장수',
|
||||
npcState: 0,
|
||||
nationId: fixture?.nationId ?? 1,
|
||||
cityId: 1,
|
||||
troopId: 0,
|
||||
picture: null,
|
||||
imageServer: 0,
|
||||
officerLevel: 0,
|
||||
stats: { leadership: 55, strength: 55, intelligence: 55 },
|
||||
gold: 1000,
|
||||
rice: 1000,
|
||||
crew: 0,
|
||||
train: 0,
|
||||
atmos: 0,
|
||||
injury: 0,
|
||||
experience: 0,
|
||||
dedication: 0,
|
||||
items: { horse: null, weapon: null, book: null, item: null },
|
||||
},
|
||||
city: null,
|
||||
nation: null,
|
||||
settings: {},
|
||||
penalties: {},
|
||||
});
|
||||
}
|
||||
if (operation === 'general.getFrontStatus') {
|
||||
return failStatus()
|
||||
? errorResponse(operation, '상단 현황을 불러오지 못했습니다.')
|
||||
: response(liveStatus);
|
||||
}
|
||||
if (operation === 'general.getRecentRecords') return response({ global: [], general: [], history: [] });
|
||||
if (operation === 'lobby.info') {
|
||||
return response({
|
||||
year: 190,
|
||||
month: 1,
|
||||
userCnt: 1,
|
||||
npcCnt: 0,
|
||||
nationCnt: 1,
|
||||
maxUserCnt: 50,
|
||||
turnTerm: 60,
|
||||
fictionMode: '가상',
|
||||
otherTextInfo: '',
|
||||
starttime: '0190-01-01T00:00:00.000Z',
|
||||
myGeneral: { name: '현황검증장수', picture: null },
|
||||
});
|
||||
}
|
||||
if (operation === 'world.getMapLayout') {
|
||||
return response({
|
||||
mapName: 'che',
|
||||
cityList: [{ id: 1, name: '낙양', level: 7, region: 1, x: 350, y: 245, path: [] }],
|
||||
regionMap: { 1: '사예' },
|
||||
levelMap: { 7: '수도' },
|
||||
});
|
||||
}
|
||||
if (operation === 'world.getMap') {
|
||||
return response({
|
||||
year: 190,
|
||||
month: 1,
|
||||
startYear: 190,
|
||||
cityList: [[1, 7, 0, 0, 1, 1]],
|
||||
nationList: [],
|
||||
spyList: {},
|
||||
shownByGeneralList: [],
|
||||
myCity: 1,
|
||||
myNation: fixture?.nationId ?? 1,
|
||||
});
|
||||
}
|
||||
if (operation === 'turns.getCommandTable') return response({ general: [], nation: [] });
|
||||
if (operation === 'turns.reserved.getGeneral' || operation === 'turns.reserved.getNation') {
|
||||
return response([]);
|
||||
}
|
||||
if (operation === 'messages.getRecent') {
|
||||
return response({
|
||||
private: [],
|
||||
public: [],
|
||||
national: [],
|
||||
diplomacy: [],
|
||||
permission: 0,
|
||||
latestRead: { private: 0, diplomacy: 0 },
|
||||
canRespondDiplomacy: false,
|
||||
});
|
||||
}
|
||||
if (operation === 'messages.getContacts') return response([]);
|
||||
if (operation === 'board.getAccess') {
|
||||
return response({ canMeeting: false, canSecret: false, permission: 0 });
|
||||
}
|
||||
if (operation === 'tournament.getState') return response({ stage: 0 });
|
||||
if (operation === 'public.recordAccess') return response({ recorded: true });
|
||||
throw new Error(`Unhandled main front status operation: ${operation}`);
|
||||
});
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(results),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
test('renders actual online, nation policy, and survey data with ref geometry and preserves it on error', async ({
|
||||
page,
|
||||
}) => {
|
||||
const liveResponse = await page.request.get(
|
||||
'http://127.0.0.1:15113/che/api/trpc/general.getFrontStatus?input=%7B%22json%22%3Anull%7D',
|
||||
{ headers: { authorization: `Bearer ${accessToken}` } }
|
||||
);
|
||||
expect(liveResponse.ok()).toBe(true);
|
||||
const liveStatus = (
|
||||
(await liveResponse.json()) as {
|
||||
result: {
|
||||
data: {
|
||||
onlineUserCount: number;
|
||||
onlineNations: string;
|
||||
onlineGenerals: string;
|
||||
nationNotice: string;
|
||||
lastExecuted: string | null;
|
||||
latestVote: { id: number; title: string; hasVoted: boolean } | null;
|
||||
};
|
||||
};
|
||||
}
|
||||
).result.data;
|
||||
expect(liveStatus.onlineGenerals).toContain('현황검증장수');
|
||||
expect(liveStatus.nationNotice).toContain(marker);
|
||||
expect(liveStatus.latestVote).toMatchObject({ title: '검증 설문', hasVoted: false });
|
||||
|
||||
let failStatus = false;
|
||||
await installMainFixture(page, liveStatus, () => failStatus);
|
||||
await page.setViewportSize({ width: 1000, height: 900 });
|
||||
await page.goto('./', { waitUntil: 'networkidle' });
|
||||
|
||||
const status = page.locator('.front-status');
|
||||
await expect(status).toContainText(marker);
|
||||
await expect(page.locator('.online-users')).toContainText('현황검증장수');
|
||||
await expect(page.locator('.survey-notice')).toContainText('새로운 설문조사가 있습니다.');
|
||||
const desktop = await status.evaluate((element) => {
|
||||
const style = getComputedStyle(element);
|
||||
const onlineRow = element.querySelector<HTMLElement>('.online-nations');
|
||||
const voteRow = element.querySelector<HTMLElement>('.vote-status');
|
||||
if (!onlineRow || !voteRow) throw new Error('status row missing');
|
||||
return {
|
||||
rect: element.getBoundingClientRect().toJSON(),
|
||||
fontSize: style.fontSize,
|
||||
lineHeight: style.lineHeight,
|
||||
backgroundImage: style.backgroundImage,
|
||||
onlineRow: {
|
||||
rect: onlineRow.getBoundingClientRect().toJSON(),
|
||||
borderTop: getComputedStyle(onlineRow).borderTop,
|
||||
padding: getComputedStyle(onlineRow).padding,
|
||||
},
|
||||
voteRow: voteRow.getBoundingClientRect().toJSON(),
|
||||
};
|
||||
});
|
||||
expect(desktop.rect).toMatchObject({ x: 0, width: 1000 });
|
||||
expect(desktop).toMatchObject({
|
||||
fontSize: '14px',
|
||||
lineHeight: '21px',
|
||||
onlineRow: {
|
||||
borderTop: '1px solid rgb(128, 128, 128)',
|
||||
padding: '7px',
|
||||
},
|
||||
});
|
||||
expect(desktop.onlineRow.rect.height).toBeCloseTo(36, 0);
|
||||
expect(desktop.voteRow.x).toBeCloseTo(666.67, 0);
|
||||
expect(desktop.voteRow.width).toBeCloseTo(333.33, 0);
|
||||
expect(desktop.voteRow.height).toBeCloseTo(36, 0);
|
||||
expect(desktop.backgroundImage).toContain('/image/game/back_walnut.jpg');
|
||||
|
||||
await page.setViewportSize({ width: 500, height: 900 });
|
||||
await expect(status).toHaveCSS('width', '500px');
|
||||
await expect(page.locator('.vote-status')).toHaveCSS('width', '250px');
|
||||
|
||||
failStatus = true;
|
||||
await page.getByRole('button', { name: '새로고침', exact: true }).click();
|
||||
await expect(page.getByRole('alert').filter({ hasText: '상단 현황을 불러오지 못했습니다.' })).toBeVisible();
|
||||
await expect(status).toContainText(marker);
|
||||
|
||||
failStatus = false;
|
||||
await page.reload({ waitUntil: 'networkidle' });
|
||||
await expect(page.locator('.front-status')).toContainText(marker);
|
||||
await expect(page.locator('.survey-notice')).toHaveCount(0);
|
||||
});
|
||||
@@ -188,6 +188,16 @@ const installMainFixture = async (page: Page, failRecords = false) => {
|
||||
? errorResponse(operation, '동향 정보를 불러오지 못했습니다.')
|
||||
: response(frontRecords);
|
||||
}
|
||||
if (operation === 'general.getFrontStatus') {
|
||||
return response({
|
||||
onlineUserCount: 1,
|
||||
onlineNations: '【재야】',
|
||||
onlineGenerals: '지도 장수',
|
||||
nationNotice: '',
|
||||
lastExecuted: '2026-07-26T00:00:00.000Z',
|
||||
latestVote: null,
|
||||
});
|
||||
}
|
||||
if (operation === 'tournament.getState') return response({ stage: 0 });
|
||||
if (operation === 'public.recordAccess') return response({ recorded: true });
|
||||
return errorResponse(operation, `Unhandled main operation: ${operation}`);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
import { chromium } from '@playwright/test';
|
||||
|
||||
const baseUrl = process.env.REF_GATEWAY_URL ?? 'http://127.0.0.1:3400/sam/';
|
||||
const username = process.env.REF_USER_ID ?? 'refuser1';
|
||||
const passwordFile =
|
||||
process.env.REF_USER_PASSWORD_FILE ??
|
||||
'/home/letrhee/sam_rebuild/docker_compose_files/reference/secrets/user1_password';
|
||||
const password = (await readFile(passwordFile, 'utf8')).trim();
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
|
||||
try {
|
||||
const context = await browser.newContext({
|
||||
colorScheme: 'dark',
|
||||
deviceScaleFactor: 1,
|
||||
locale: 'ko-KR',
|
||||
timezoneId: 'UTC',
|
||||
viewport: { width: 1000, height: 900 },
|
||||
});
|
||||
const page = await context.newPage();
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle' });
|
||||
const globalSalt = await page.locator('#global_salt').inputValue();
|
||||
const passwordHash = createHash('sha512')
|
||||
.update(globalSalt + password + globalSalt)
|
||||
.digest('hex');
|
||||
const login = await context.request.post(new URL('api.php?path=Login/LoginByID', baseUrl).toString(), {
|
||||
data: { username, password: passwordHash },
|
||||
});
|
||||
if (!login.ok()) {
|
||||
throw new Error(`reference login failed: HTTP ${login.status()}`);
|
||||
}
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle' });
|
||||
const logout = page.locator('#btn_logout');
|
||||
await logout.waitFor({ state: 'visible' });
|
||||
const inspect = async () =>
|
||||
logout.evaluate((element) => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
rect: rect.toJSON(),
|
||||
backgroundColor: style.backgroundColor,
|
||||
border: style.border,
|
||||
borderRadius: style.borderRadius,
|
||||
color: style.color,
|
||||
cursor: style.cursor,
|
||||
fontFamily: style.fontFamily,
|
||||
fontSize: style.fontSize,
|
||||
fontWeight: style.fontWeight,
|
||||
lineHeight: style.lineHeight,
|
||||
padding: style.padding,
|
||||
};
|
||||
});
|
||||
const normal = await inspect();
|
||||
await logout.hover();
|
||||
const hover = await inspect();
|
||||
await logout.focus();
|
||||
const focus = await inspect();
|
||||
console.log(JSON.stringify({ viewport: page.viewportSize(), normal, hover, focus }));
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
import { chromium } from '@playwright/test';
|
||||
|
||||
const baseUrl = process.env.REF_MAIN_URL ?? 'http://127.0.0.1:3400/sam/';
|
||||
const username = process.env.REF_USER_ID ?? 'refuser1';
|
||||
const passwordFile =
|
||||
process.env.REF_USER_PASSWORD_FILE ??
|
||||
'/home/letrhee/sam_rebuild/docker_compose_files/reference/secrets/user1_password';
|
||||
const password = (await readFile(passwordFile, 'utf8')).trim();
|
||||
const browser = await chromium.launch({ headless: true });
|
||||
|
||||
try {
|
||||
const context = await browser.newContext({
|
||||
colorScheme: 'dark',
|
||||
deviceScaleFactor: 1,
|
||||
locale: 'ko-KR',
|
||||
timezoneId: 'UTC',
|
||||
});
|
||||
const page = await context.newPage();
|
||||
await page.goto(baseUrl, { waitUntil: 'networkidle' });
|
||||
const globalSalt = await page.locator('#global_salt').inputValue();
|
||||
const passwordHash = createHash('sha512')
|
||||
.update(globalSalt + password + globalSalt)
|
||||
.digest('hex');
|
||||
const login = await context.request.post(new URL('api.php?path=Login/LoginByID', baseUrl).toString(), {
|
||||
data: { username, password: passwordHash },
|
||||
});
|
||||
if (!login.ok()) {
|
||||
throw new Error(`reference login failed: HTTP ${login.status()}`);
|
||||
}
|
||||
|
||||
for (const viewport of [
|
||||
{ name: 'desktop', width: 1000, height: 900 },
|
||||
{ name: 'mobile', width: 500, height: 900 },
|
||||
]) {
|
||||
await page.setViewportSize(viewport);
|
||||
await page.goto(new URL('hwe/', baseUrl).toString(), { waitUntil: 'networkidle' });
|
||||
await page.locator('.onlineNations').waitFor({ state: 'visible' });
|
||||
const measurement = await page.evaluate(() => {
|
||||
const inspect = (selector) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (!(element instanceof HTMLElement)) {
|
||||
throw new Error(`missing ${selector}`);
|
||||
}
|
||||
const rect = element.getBoundingClientRect();
|
||||
const style = getComputedStyle(element);
|
||||
return {
|
||||
rect: rect.toJSON(),
|
||||
backgroundColor: style.backgroundColor,
|
||||
backgroundImage: style.backgroundImage,
|
||||
borderTop: style.borderTop,
|
||||
color: style.color,
|
||||
fontFamily: style.fontFamily,
|
||||
fontSize: style.fontSize,
|
||||
fontWeight: style.fontWeight,
|
||||
lineHeight: style.lineHeight,
|
||||
padding: style.padding,
|
||||
};
|
||||
};
|
||||
return {
|
||||
container: inspect('#container'),
|
||||
onlineNations: inspect('.onlineNations'),
|
||||
onlineUsers: inspect('.onlineUsers'),
|
||||
nationNotice: inspect('.nationNotice'),
|
||||
voteStatus: inspect('.subVoteState'),
|
||||
};
|
||||
});
|
||||
console.log(JSON.stringify({ viewport, measurement }));
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { execFileSync, spawnSync } from 'node:child_process';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const pm2Candidates = [
|
||||
'/home/letrhee/.nvm/versions/node/v22.15.1/bin/pm2',
|
||||
'/home/letrhee/.nvm/versions/node/v24.13.0/bin/pm2',
|
||||
];
|
||||
|
||||
let processes;
|
||||
for (const candidate of pm2Candidates) {
|
||||
try {
|
||||
const output = execFileSync(candidate, ['jlist'], {
|
||||
encoding: 'utf8',
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
processes = JSON.parse(output.slice(output.indexOf('[')));
|
||||
break;
|
||||
} catch {
|
||||
// Try the next locally installed PM2 client.
|
||||
}
|
||||
}
|
||||
if (!processes) {
|
||||
throw new Error('Unable to read the local PM2 process list.');
|
||||
}
|
||||
|
||||
const source = processes.find((process) => process.name === 'sammo-verify-che-api')?.pm2_env;
|
||||
if (!source) {
|
||||
throw new Error('sammo-verify-che-api is required as the live environment source.');
|
||||
}
|
||||
|
||||
const allowed = /^(DATABASE_URL|POSTGRES_|REDIS_|GAME_|GATEWAY_|PROFILE$|SCENARIO$)/;
|
||||
const liveEnvironment = Object.fromEntries(
|
||||
Object.entries(source).filter(([key, value]) => allowed.test(key) && typeof value === 'string')
|
||||
);
|
||||
const result = spawnSync(
|
||||
'pnpm',
|
||||
[
|
||||
'exec',
|
||||
'playwright',
|
||||
'test',
|
||||
'main-front-status.spec.ts',
|
||||
'--config',
|
||||
'tools/frontend-legacy-parity/main-front-status.playwright.config.mjs',
|
||||
],
|
||||
{
|
||||
cwd: repositoryRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
...liveEnvironment,
|
||||
SAMMO_TEST_OUTPUT_DIR: '/dev/shm/sammo-main-front-status-live',
|
||||
},
|
||||
stdio: 'inherit',
|
||||
}
|
||||
);
|
||||
process.exitCode = result.status ?? 1;
|
||||
Reference in New Issue
Block a user