Skip to content

Commit 78e7329

Browse files
committed
add sse --show-render-error support
1 parent 21665da commit 78e7329

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/lib/processSnapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Snapshot, Context, DiscoveryErrors } from "../types.js";
2-
import { scrollToBottomAndBackToTop, getRenderViewports, getRenderViewportsForOptions, validateCoordinates, resolveCustomCSS, parseCSSFile, validateCSSSelectors, generateCSSInjectionReport } from "./utils.js"
2+
import { scrollToBottomAndBackToTop, getRenderViewports, getRenderViewportsForOptions, validateCoordinates, resolveCustomCSS, parseCSS, validateCSSSelectors, generateCSSInjectionReport } from "./utils.js"
33
import { chromium, Locator } from "@playwright/test"
44
import constants from "./constants.js";
55
import { updateLogContext } from '../lib/logger.js'
@@ -922,7 +922,7 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
922922
// Validate and report CSS injection after selector processing
923923
if (processedOptions.customCSS) {
924924
try {
925-
const cssRules = parseCSSFile(processedOptions.customCSS);
925+
const cssRules = parseCSS(processedOptions.customCSS);
926926
const validationResult = await validateCSSSelectors(page, cssRules, ctx.log);
927927
const report = generateCSSInjectionReport(validationResult, ctx.log, snapshot.name);
928928

src/lib/utils.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,22 @@ export async function startSSEListener(ctx: Context) {
880880
ctx.log.info(chalk.yellow.bold(`Warning: ${data.message}`));
881881
}
882882
break;
883+
case 'CSSReport':
884+
if (data.buildId == ctx.build.id) {
885+
const lines = data.message.split('\n');
886+
if (lines.length < 1 ) {
887+
return;
888+
}
889+
ctx.log.info(chalk.green(lines[0]));
890+
891+
if(lines[1].includes('Success')) {
892+
lines.slice(1).forEach(line => ctx.log.info(chalk.green(line)));
893+
}
894+
else {
895+
lines.slice(1).forEach(line => ctx.log.info(chalk.yellow(line)));
896+
}
897+
break;
898+
}
883899
case 'error':
884900
ctx.log.debug('SSE Error occurred:', data);
885901
currentConnection?.abort();
@@ -964,7 +980,7 @@ export function resolveCustomCSS(cssValue: string, configPath: string, logger: a
964980
}
965981

966982

967-
export function parseCSSFile(cssContent: string): Array<{
983+
export function parseCSS(cssContent: string): Array<{
968984
selector: string;
969985
declarations: Array<{ property: string; value: string; important: boolean }>;
970986
source?: { start?: any; end?: any };
@@ -1012,13 +1028,6 @@ export function parseCSSFile(cssContent: string): Array<{
10121028
return rules;
10131029
}
10141030

1015-
/**
1016-
* Validate CSS selectors in the page context
1017-
* @param page - Playwright page object
1018-
* @param cssRules - Parsed CSS rules
1019-
* @param logger - Logger instance
1020-
* @returns Validation results with success and failed selectors
1021-
*/
10221031
export async function validateCSSSelectors(
10231032
page: any,
10241033
cssRules: Array<{ selector: string; declarations: any[] }>,
@@ -1040,12 +1049,12 @@ export async function validateCSSSelectors(
10401049
selector.includes('@') ||
10411050
selector.includes('::')
10421051
) {
1043-
successCount++; // Count as success since they're valid CSS
1052+
successCount++;
10441053
continue;
10451054
}
10461055

10471056
try {
1048-
// Validate if selector finds at least one element
1057+
10491058
const elementExists = await page.evaluate(({ selectorValue }: { selectorValue: string }) => {
10501059
try {
10511060
const elements = document.querySelectorAll(selectorValue);
@@ -1075,12 +1084,6 @@ export async function validateCSSSelectors(
10751084
};
10761085
}
10771086

1078-
/**
1079-
* Generate CSS injection report
1080-
* @param validationResult - Results from CSS selector validation
1081-
* @param logger - Logger instance
1082-
* @returns Formatted report string
1083-
*/
10841087
export function generateCSSInjectionReport(
10851088
validationResult: {
10861089
successCount: number;

0 commit comments

Comments
 (0)