8a48765a46
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
import { readFileSync } from 'node:fs';
|
|
import { createHash } from 'node:crypto';
|
|
import { devices } from '@playwright/test';
|
|
import { browserStabilityArgs } from './playwright-runtime.mjs';
|
|
|
|
// The review JSON is also read by Python; keep dimensions and device choices there.
|
|
const config = JSON.parse(
|
|
readFileSync(new URL('./ui-review/config.json', import.meta.url), 'utf8'),
|
|
);
|
|
const aliases = {
|
|
'desktop-boundary': 'laptop',
|
|
'laptop-hd': 'hd',
|
|
'laptop-wxga': 'wxga',
|
|
};
|
|
export const browserChannel = config.browser.channel;
|
|
export const projectViewports = [
|
|
'desktop',
|
|
'mobile',
|
|
'tablet',
|
|
'desktop-boundary',
|
|
'laptop-hd',
|
|
'laptop-wxga',
|
|
'qhd',
|
|
'uhd',
|
|
];
|
|
|
|
export function deviceOptions(name) {
|
|
const key = aliases[name] || name;
|
|
const size = config.viewports[key];
|
|
if (!size) throw new Error(`Unknown viewport: ${name}`);
|
|
const descriptor =
|
|
devices[
|
|
config.browser[key === 'mobile' ? 'mobileDevice' : 'desktopDevice']
|
|
];
|
|
if (!descriptor) throw new Error(`Unknown device profile for ${name}`);
|
|
const { defaultBrowserType, ...context } = descriptor;
|
|
return { ...context, viewport: { width: size[0], height: size[1] } };
|
|
}
|
|
|
|
export function contextOptions(name, reducedMotion = 'reduce') {
|
|
return {
|
|
...deviceOptions(name),
|
|
locale: config.browser.locale,
|
|
timezoneId: config.browser.timezone,
|
|
colorScheme: 'light',
|
|
reducedMotion,
|
|
};
|
|
}
|
|
|
|
export function environmentFingerprint(name, reducedMotion = 'reduce') {
|
|
return createHash('sha256')
|
|
.update(
|
|
JSON.stringify({
|
|
version: 2,
|
|
channel: browserChannel,
|
|
options: contextOptions(name, reducedMotion),
|
|
launchArgs: browserStabilityArgs,
|
|
screenshotScale: 'css',
|
|
}),
|
|
)
|
|
.digest('hex');
|
|
}
|