Skip to content

Commit 88f9df6

Browse files
authored
Merge pull request #42 from pinanks/DOT-2299
Add warnings during snapshot processing
2 parents 524437f + eb0557c commit 88f9df6

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/lib/processSnapshot.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { chromium, Locator } from "@playwright/test"
33

44
const MIN_VIEWPORT_HEIGHT = 1080;
55

6-
export default async (snapshot: Snapshot, ctx: Context): Promise<ProcessedSnapshot> => {
6+
export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string, any>> => {
77
// Process snapshot options
88
let options = snapshot.options;
9+
let warnings: Array<string> = [];
910
let processedOptions: Record<string, any> = {};
1011
if (options && Object.keys(options).length !== 0) {
1112
ctx.log.debug(`Processing options: ${JSON.stringify(options)}`);
@@ -55,8 +56,8 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<ProcessedSnapsh
5556
for (const selector of selectors) {
5657
let l = await page.locator(selector).all()
5758
if (l.length === 0) {
58-
await page.close();
59-
throw new Error(`no element found for selector ${selector}`);
59+
warnings.push(`For snapshot ${snapshot.name}, no element found for selector ${selector}`);
60+
continue;
6061
}
6162
locators.push(...l);
6263
}
@@ -76,10 +77,14 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<ProcessedSnapsh
7677
}
7778
}
7879

80+
warnings.push(...snapshot.dom.warnings);
7981
return {
80-
name: snapshot.name,
81-
url: snapshot.url,
82-
dom: Buffer.from(snapshot.dom.html).toString('base64'),
83-
options: processedOptions
82+
processedSnapshot: {
83+
name: snapshot.name,
84+
url: snapshot.url,
85+
dom: Buffer.from(snapshot.dom.html).toString('base64'),
86+
options: processedOptions
87+
},
88+
warnings
8489
}
8590
}

src/lib/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
2727
try {
2828
let { snapshot, testType } = request.body;
2929
if (!validateSnapshot(snapshot)) throw new Error(validateSnapshot.errors[0].message);
30-
let processedSnapshot = await processSnapshot(snapshot, ctx);
31-
await ctx.client.uploadSnapshot(ctx.build.id, processedSnapshot, testType, ctx.log)
30+
let { processedSnapshot, warnings } = await processSnapshot(snapshot, ctx);
31+
await ctx.client.uploadSnapshot(ctx.build.id, processedSnapshot, testType, ctx.log);
32+
33+
ctx.totalSnapshots++
34+
reply.code(200).send({data: { message: "success", warnings }});
3235
} catch (error: any) {
3336
return reply.code(500).send({ error: { message: error.message}});
3437
}
35-
36-
ctx.totalSnapshots++
37-
reply.code(200).send({data: { message: "success" }});
3838
});
3939

4040

0 commit comments

Comments
 (0)