4
4
downloadDomScript ,
5
5
getApi as getVisualApi ,
6
6
getDomScript ,
7
+ getVisualResults ,
7
8
RegionIn ,
8
9
removeDomScriptFile ,
9
10
VisualEnvOpts ,
@@ -16,6 +17,7 @@ const clientVersion = 'PKG_VERSION';
16
17
17
18
export class VisualPlaywright {
18
19
constructor ( public client : string = `visual-playwright/${ clientVersion } ` ) { }
20
+ uploadedDiffIds : Record < string , string [ ] > = { } ;
19
21
20
22
public get api ( ) {
21
23
let api = globalThis . visualApi ;
@@ -135,11 +137,12 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
135
137
testName : string | undefined ;
136
138
suiteName : string | undefined ;
137
139
deviceName : string | undefined ;
140
+ testId : string ;
138
141
} ,
139
142
name : string ,
140
143
options ?: Partial < SauceVisualParams > ,
141
144
) {
142
- const { testName, suiteName, deviceName } = info ;
145
+ const { testName, suiteName, deviceName, testId } = info ;
143
146
const { buildId } = getOpts ( ) ;
144
147
145
148
if ( ! buildId ) {
@@ -156,7 +159,13 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
156
159
ignoreRegions : userIgnoreRegions ,
157
160
diffingMethod,
158
161
} = options ?? { } ;
159
- const { animations = 'disabled' , caret } = screenshotOptions ;
162
+ const {
163
+ animations = 'disabled' ,
164
+ caret,
165
+ fullPage = true ,
166
+ style,
167
+ timeout,
168
+ } = screenshotOptions ;
160
169
let ignoreRegions : RegionIn [ ] = [ ] ;
161
170
162
171
const promises : Promise < unknown > [ ] = [
@@ -270,7 +279,9 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
270
279
const devicePixelRatio = await page . evaluate ( ( ) => window . devicePixelRatio ) ;
271
280
272
281
const screenshotBuffer = await page . screenshot ( {
273
- fullPage : true ,
282
+ fullPage,
283
+ style,
284
+ timeout,
274
285
animations,
275
286
caret,
276
287
clip,
@@ -318,12 +329,24 @@ ${e instanceof Error ? e.message : JSON.stringify(e)}
318
329
diffingMethod,
319
330
} ) ;
320
331
321
- await this . api . createSnapshot ( {
332
+ const { diffs } = await this . api . createSnapshot ( {
322
333
...meta ,
323
334
testName,
324
335
suiteName,
325
336
uploadUuid : uploadId ,
326
337
} ) ;
338
+
339
+ if ( ! this . uploadedDiffIds [ testId ] ) this . uploadedDiffIds [ testId ] = [ ] ;
340
+
341
+ this . uploadedDiffIds [ testId ] . push ( ...diffs . nodes . map ( ( diff ) => diff . id ) ) ;
342
+ }
343
+
344
+ public async visualResults ( { testId } : { testId : string } ) {
345
+ const { buildId } = getOpts ( ) ;
346
+ return await getVisualResults ( this . api , {
347
+ buildId,
348
+ diffIds : this . uploadedDiffIds [ testId ] ?? [ ] ,
349
+ } ) ;
327
350
}
328
351
329
352
/**
0 commit comments