Skip to content

Commit 7fcdf70

Browse files
committed
fix: change how render width, height and scale works for html_template expectedPackages
1 parent 0e589bf commit 7fcdf70

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

shared/packages/api/src/expectationApi.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,12 @@ export namespace Expectation {
354354
renderer?: {
355355
width?: number
356356
height?: number
357-
zoom?: number
357+
/**
358+
* Scale the rendered width and height with this value, and also zoom the content accordingly.
359+
* For example, if the width is 1920 and scale is 0.5, the width will be scaled to 960.
360+
* (Defaults to 1)
361+
*/
362+
scale?: number
358363
/** Background color, #RRGGBB, CSS-string, "transparent" or "default" (defaults to "default") */
359364
background?: string
360365
userAgent?: string

shared/packages/worker/src/worker/workers/genericWorker/expectationHandlers/renderHTML.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,24 @@ class HTMLRenderer {
679679
}
680680

681681
private spawnHTMLRendererProcess() {
682+
let width = this.exp.endRequirement.version.renderer?.width
683+
let height = this.exp.endRequirement.version.renderer?.height
684+
const scale = this.exp.endRequirement.version.renderer?.scale
685+
if (width !== undefined && height !== undefined && scale !== undefined) {
686+
width = Math.floor(width * scale)
687+
height = Math.floor(height * scale)
688+
}
689+
682690
const args = compact<string>([
683691
`--`,
684692
`--url=${this.url}`,
685-
this.exp.endRequirement.version.renderer?.width !== undefined &&
686-
`--width=${this.exp.endRequirement.version.renderer?.width}`,
687-
this.exp.endRequirement.version.renderer?.height !== undefined &&
688-
`--height=${this.exp.endRequirement.version.renderer?.height}`,
689-
this.exp.endRequirement.version.renderer?.zoom !== undefined &&
690-
`--zoom=${this.exp.endRequirement.version.renderer?.zoom}`,
693+
width !== undefined && `--width=${width}`,
694+
height !== undefined && `--height=${height}`,
695+
scale !== undefined && `--zoom=${scale}`,
691696
`--outputPath=${this.outputPath}`,
692697
`--background=${this.exp.endRequirement.version.renderer?.background ?? 'default'}`,
693698
`--interactive=true`,
694699
])
695-
this.worker.logger.info('AAAA ' + JSON.stringify(args))
696700
this.htmlRendererProcess = spawn(getHtmlRendererExecutable(), args, {
697701
windowsVerbatimArguments: true, // To fix an issue with arguments on Windows
698702
})

0 commit comments

Comments
 (0)