From 54be464c607026b2bdc1689d6b188f4dd84dec4e Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 12 Dec 2024 12:12:14 -0500 Subject: [PATCH 01/12] chore: convert screenshots.js to screenshots.ts --- .../lib/{screenshots.js => screenshots.ts} | 65 ++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) rename packages/server/lib/{screenshots.js => screenshots.ts} (91%) diff --git a/packages/server/lib/screenshots.js b/packages/server/lib/screenshots.ts similarity index 91% rename from packages/server/lib/screenshots.js rename to packages/server/lib/screenshots.ts index 79730f952a3f..5c9de86de115 100644 --- a/packages/server/lib/screenshots.js +++ b/packages/server/lib/screenshots.ts @@ -1,21 +1,22 @@ -const _ = require('lodash') -const mime = require('mime') -const path = require('path') -const Promise = require('bluebird') -const dataUriToBuffer = require('data-uri-to-buffer') -const Jimp = require('jimp') -const sizeOf = require('image-size') -const colorString = require('color-string') -const sanitize = require('sanitize-filename') -let debug = require('debug')('cypress:server:screenshot') -const plugins = require('./plugins') -const { fs } = require('./util/fs') - +import _ from 'lodash' +import Debug from 'debug' +import mime from 'mime' +import path from 'path' +import Promise from 'bluebird' +import dataUriToBuffer from 'data-uri-to-buffer' +import Jimp from 'jimp' +import sizeOf from 'image-size' +import colorString from 'color-string' +import sanitize from 'sanitize-filename' +import * as plugins from './plugins' +import { fs } from './util/fs' + +let debug = Debug('cypress:server:screenshot') const RUNNABLE_SEPARATOR = ' -- ' const pathSeparatorRe = /[\\\/]/g // internal id incrementor -let __ID__ = null +let __ID__: string | null = null // many filesystems limit filename length to 255 bytes/characters, so truncate the filename to // the smallest common denominator of safe filenames, which is 255 bytes. when ENAMETOOLONG @@ -32,20 +33,35 @@ const MIN_PREFIX_BYTES = 64 // when debugging logs automatically prefix the // screenshot id to the debug logs for easier association +// @ts-ignore debug = _.wrap(debug, (fn, str, ...args) => { return fn(`(${__ID__}) ${str}`, ...args) }) -const isBlack = (rgba) => { +interface RGBA { + r: number + g: number + b: number + a: number +} + +const isBlack = (rgba: RGBA): boolean => { return `${rgba.r}${rgba.g}${rgba.b}` === '000' } -const isWhite = (rgba) => { +const isWhite = (rgba: RGBA): boolean => { return `${rgba.r}${rgba.g}${rgba.b}` === '255255255' } -const intToRGBA = function (int) { - const obj = Jimp.intToRGBA(int) +interface RGBAWithName extends RGBA { + name?: string + isNotWhite?: boolean + isWhite?: boolean + isBlack?: boolean +} + +const intToRGBA = function (int: number): RGBAWithName { + const obj: RGBAWithName = Jimp.intToRGBA(int) as RGBAWithName if (debug.enabled) { obj.name = colorString.to.keyword([ @@ -115,7 +131,7 @@ const captureAndCheck = function (data, automate, conditionFn) { return (attempt = function () { tries++ - const totalDuration = new Date() - start + const totalDuration = new Date().getTime() - start.getTime() debug('capture and check %o', { tries, totalDuration }) @@ -187,7 +203,7 @@ const pixelConditionFn = function (data, image) { return passes } -let multipartImages = [] +let multipartImages: { data, image, takenAt, __ID__ }[] = [] const clearMultipartState = function () { debug('clearing %d cached multipart images', multipartImages.length) @@ -246,7 +262,7 @@ const stitchScreenshots = function (pixelRatio) { debug(`stitch ${multipartImages.length} images together`) - const takenAts = [] + const takenAts: string[] = [] let heightMarker = 0 const fullImage = new Jimp(fullWidth, fullHeight) @@ -278,6 +294,7 @@ const getBuffer = function (details) { return Promise .promisify(details.image.getBuffer) + // @ts-ignore .call(details.image, Jimp.AUTO) } @@ -316,6 +333,7 @@ const ensureSafePath = function (withoutExt, extension, overwrite, num = 0) { } // path does not exist, attempt to create it to check for an ENAMETOOLONG error + // @ts-ignore return fs.outputFileAsync(fullPath, '') .then(() => fullPath) .catch((err) => { @@ -350,6 +368,7 @@ const getPath = function (data, ext, screenshotsFolder, overwrite) { .chain(data.titles) .map(sanitizeToString) .join(RUNNABLE_SEPARATOR) + // @ts-ignore .concat([]) .value() } @@ -468,8 +487,10 @@ module.exports = { return getBuffer(details) .then((buffer) => { + // @ts-ignore return fs.outputFileAsync(pathToScreenshot, buffer) }).then(() => { + // @ts-ignore return fs.statAsync(pathToScreenshot).get('size') }).then((size) => { const dimensions = getDimensions(details) @@ -492,7 +513,7 @@ module.exports = { }, afterScreenshot (data, details) { - const duration = new Date() - new Date(data.startTime) + const duration = new Date().getTime() - new Date(data.startTime).getTime() details = _.extend({}, data, details, { duration }) details = _.pick(details, 'testAttemptIndex', 'size', 'takenAt', 'dimensions', 'multipart', 'pixelRatio', 'name', 'specName', 'testFailure', 'path', 'scaled', 'blackout', 'duration') From 70652e5aacc08c27880bcb4e62562c9e37707ec3 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 12 Dec 2024 12:52:34 -0500 Subject: [PATCH 02/12] Fix export --- packages/server/lib/screenshots.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 5c9de86de115..5d9a4fd6c4ec 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -395,7 +395,7 @@ const getPathToScreenshot = function (data, details, screenshotsFolder) { return getPath(data, ext, screenshotsFolder, data.overwrite) } -module.exports = { +export = { crop, getPath, From 7d6e3a0b960a487f596937ecb85371a3e39534eb Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Fri, 13 Dec 2024 12:41:27 -0500 Subject: [PATCH 03/12] Try to clean up types --- packages/server/lib/screenshots.ts | 34 +++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 5d9a4fd6c4ec..c69351c02402 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -10,6 +10,7 @@ import colorString from 'color-string' import sanitize from 'sanitize-filename' import * as plugins from './plugins' import { fs } from './util/fs' +import { stat } from 'fs/promises' let debug = Debug('cypress:server:screenshot') const RUNNABLE_SEPARATOR = ' -- ' @@ -33,10 +34,9 @@ const MIN_PREFIX_BYTES = 64 // when debugging logs automatically prefix the // screenshot id to the debug logs for easier association -// @ts-ignore debug = _.wrap(debug, (fn, str, ...args) => { return fn(`(${__ID__}) ${str}`, ...args) -}) +}) as Debug.Debugger interface RGBA { r: number @@ -292,10 +292,15 @@ const getBuffer = function (details) { return Promise.resolve(details.buffer) } - return Promise - .promisify(details.image.getBuffer) - // @ts-ignore - .call(details.image, Jimp.AUTO) + return new Promise((resolve, reject) => { + details.image.getBuffer(Jimp.AUTO, (err, val) => { + if (err) { + reject(err) + } else { + resolve(val) + } + }) + }) } const getDimensions = function (details) { @@ -333,8 +338,7 @@ const ensureSafePath = function (withoutExt, extension, overwrite, num = 0) { } // path does not exist, attempt to create it to check for an ENAMETOOLONG error - // @ts-ignore - return fs.outputFileAsync(fullPath, '') + return fs.outputFile(fullPath, '') .then(() => fullPath) .catch((err) => { debug('received error when testing path %o', { err, fullPath, maxSafePrefixBytes, maxSafeBytes }) @@ -364,13 +368,11 @@ const getPath = function (data, ext, screenshotsFolder, overwrite) { if (data.name) { names = data.name.split(pathSeparatorRe).map(sanitize) } else { - names = _ + names = [_ .chain(data.titles) .map(sanitizeToString) .join(RUNNABLE_SEPARATOR) - // @ts-ignore - .concat([]) - .value() + .value()] } const index = names.length - 1 @@ -487,12 +489,10 @@ export = { return getBuffer(details) .then((buffer) => { - // @ts-ignore - return fs.outputFileAsync(pathToScreenshot, buffer) + return fs.outputFile(pathToScreenshot, buffer) }).then(() => { - // @ts-ignore - return fs.statAsync(pathToScreenshot).get('size') - }).then((size) => { + return stat(pathToScreenshot) + }).then(({ size }) => { const dimensions = getDimensions(details) const { multipart, pixelRatio, takenAt } = details From 7240597d893147f5cadc64ca741a5d0ec660c2c1 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Fri, 13 Dec 2024 14:44:13 -0500 Subject: [PATCH 04/12] Add some more types around data --- packages/server/lib/screenshots.ts | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index c69351c02402..f54505831950 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -19,6 +19,18 @@ const pathSeparatorRe = /[\\\/]/g // internal id incrementor let __ID__: string | null = null +interface Data { + specName: string + name: string + titles?: string[] + testFailure?: boolean + testAttemptIndex?: number + overwrite?: boolean + simple?: boolean + current?: number + total?: number +} + // many filesystems limit filename length to 255 bytes/characters, so truncate the filename to // the smallest common denominator of safe filenames, which is 255 bytes. when ENAMETOOLONG // errors are encountered, `maxSafeBytes` will be decremented to at most `MIN_PREFIX_BYTES`, at @@ -354,25 +366,27 @@ const ensureSafePath = function (withoutExt, extension, overwrite, num = 0) { }) } -const sanitizeToString = (title) => { +const sanitizeToString = (title: string | null | undefined) => { // test titles may be values which aren't strings like // null or undefined - so convert before trying to sanitize return sanitize(_.toString(title)) } -const getPath = function (data, ext, screenshotsFolder, overwrite) { +const getPath = function (data: Data, ext, screenshotsFolder: string, overwrite: Data['overwrite']) { let names const specNames = (data.specName || '') .split(pathSeparatorRe) if (data.name) { - names = data.name.split(pathSeparatorRe).map(sanitize) + names = data.name.split(pathSeparatorRe).map((name: string) => sanitize(name)) } else { - names = [_ + names = _ .chain(data.titles) - .map(sanitizeToString) + .map((title: string | null | undefined) => sanitizeToString(title)) .join(RUNNABLE_SEPARATOR) - .value()] + // @ts-expect-error - this shouldn't be necessary, but it breaks if you remove it + .concat([]) + .value() } const index = names.length - 1 @@ -391,7 +405,7 @@ const getPath = function (data, ext, screenshotsFolder, overwrite) { return ensureSafePath(withoutExt, ext, overwrite) } -const getPathToScreenshot = function (data, details, screenshotsFolder) { +const getPathToScreenshot = function (data: Data, details, screenshotsFolder: string) { const ext = mime.getExtension(getType(details)) return getPath(data, ext, screenshotsFolder, data.overwrite) @@ -406,7 +420,7 @@ export = { imagesMatch, - capture (data, automate) { + capture (data: Data, automate) { __ID__ = _.uniqueId('s') debug('capturing screenshot %o', data) @@ -482,7 +496,7 @@ export = { }) }, - save (data, details, screenshotsFolder) { + save (data: Data, details, screenshotsFolder: string) { return getPathToScreenshot(data, details, screenshotsFolder) .then((pathToScreenshot) => { debug('save', pathToScreenshot) From aad6277bd3e6691657e85841de8a4255cd5bef78 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Mon, 16 Dec 2024 14:14:56 -0500 Subject: [PATCH 05/12] Add some more info around types to the screenshots file --- packages/server/lib/screenshots.ts | 74 ++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index f54505831950..c141b23d9af8 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -19,16 +19,56 @@ const pathSeparatorRe = /[\\\/]/g // internal id incrementor let __ID__: string | null = null +type ScreenshotsFolder = string | false | undefined + +interface Clip { + x: number + y: number + width: number + height: number +} + +// TODO: This is likely not representative of the entire Type and should be updated interface Data { specName: string name: string + startTime: Date + viewport: { + width: number + height: number + } titles?: string[] testFailure?: boolean - testAttemptIndex?: number overwrite?: boolean simple?: boolean current?: number total?: number + testAttemptIndex?: number + appOnly?: boolean + hideRunnerUi?: boolean + clip?: Clip + userClip?: Clip +} + +// TODO: This is likely not representative of the entire Type and should be updated +interface Details { + image: any + pixelRatio: any + multipart: any + takenAt: Date +} + +// TODO: This is likely not representative of the entire Type and should be updated +interface SavedDetails { + size?: any + takenAt?: Date + dimensions?: any + multipart?: any + pixelRatio?: any + name?: any + specName?: string + testFailure?: boolean + path?: string } // many filesystems limit filename length to 255 bytes/characters, so truncate the filename to @@ -136,7 +176,7 @@ const hasHelperPixels = function (image, pixelRatio) { ) } -const captureAndCheck = function (data, automate, conditionFn) { +const captureAndCheck = function (data: Data, automate, conditionFn) { let attempt const start = new Date() let tries = 0 @@ -168,7 +208,7 @@ const captureAndCheck = function (data, automate, conditionFn) { })() } -const isMultipart = (data) => { +const isMultipart = (data: Data) => { return _.isNumber(data.current) && _.isNumber(data.total) } @@ -194,7 +234,7 @@ const crop = function (image, dimensions, pixelRatio = 1) { return image.clone().crop(x, y, width, height) } -const pixelConditionFn = function (data, image) { +const pixelConditionFn = function (data: Data, image) { const pixelRatio = image.bitmap.width / data.viewport.width const hasPixels = hasHelperPixels(image, pixelRatio) @@ -215,7 +255,7 @@ const pixelConditionFn = function (data, image) { return passes } -let multipartImages: { data, image, takenAt, __ID__ }[] = [] +let multipartImages: { data: Data, image, takenAt, __ID__ }[] = [] const clearMultipartState = function () { debug('clearing %d cached multipart images', multipartImages.length) @@ -227,7 +267,7 @@ const imagesMatch = (img1, img2) => { return img1.bitmap.data.equals(img2.bitmap.data) } -const lastImagesAreDifferent = function (data, image) { +const lastImagesAreDifferent = function (data: Data, image) { // ensure the previous image isn't the same, // which might indicate the page has not scrolled yet const previous = _.last(multipartImages) @@ -250,7 +290,7 @@ const lastImagesAreDifferent = function (data, image) { return !matches } -const multipartConditionFn = function (data, image) { +const multipartConditionFn = function (data: Data, image) { if (data.current === 1) { return pixelConditionFn(data, image) && lastImagesAreDifferent(data, image) } @@ -372,7 +412,7 @@ const sanitizeToString = (title: string | null | undefined) => { return sanitize(_.toString(title)) } -const getPath = function (data: Data, ext, screenshotsFolder: string, overwrite: Data['overwrite']) { +const getPath = function (data: Data, ext, screenshotsFolder: ScreenshotsFolder, overwrite: Data['overwrite']) { let names const specNames = (data.specName || '') .split(pathSeparatorRe) @@ -396,16 +436,22 @@ const getPath = function (data: Data, ext, screenshotsFolder: string, overwrite: names[index] = `${names[index]} (failed)` } - if (data.testAttemptIndex > 0) { + if (data.testAttemptIndex && data.testAttemptIndex > 0) { names[index] = `${names[index]} (attempt ${data.testAttemptIndex + 1})` } - const withoutExt = path.join(screenshotsFolder, ...specNames, ...names) + let withoutExt + + if (screenshotsFolder) { + withoutExt = path.join(screenshotsFolder, ...specNames, ...names) + } else { + withoutExt = path.join(...specNames, ...names) + } return ensureSafePath(withoutExt, ext, overwrite) } -const getPathToScreenshot = function (data: Data, details, screenshotsFolder: string) { +const getPathToScreenshot = function (data: Data, details: Details, screenshotsFolder: ScreenshotsFolder) { const ext = mime.getExtension(getType(details)) return getPath(data, ext, screenshotsFolder, data.overwrite) @@ -454,7 +500,7 @@ export = { debug(`multi-part ${data.current}/${data.total}`) } - if (multipart && (data.total > 1)) { + if (multipart && (data.total && data.total > 1)) { // keep previous screenshot partials around b/c if two screenshots are // taken in a row, the UI might not be caught up so we need something // to compare the new one to @@ -496,7 +542,7 @@ export = { }) }, - save (data: Data, details, screenshotsFolder: string) { + save (data: Data, details: Details, screenshotsFolder: ScreenshotsFolder) { return getPathToScreenshot(data, details, screenshotsFolder) .then((pathToScreenshot) => { debug('save', pathToScreenshot) @@ -526,7 +572,7 @@ export = { }) }, - afterScreenshot (data, details) { + afterScreenshot (data: Data, details: SavedDetails) { const duration = new Date().getTime() - new Date(data.startTime).getTime() details = _.extend({}, data, details, { duration }) From 883025fe70d563166cafcaac86d276fa770a4d47 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Tue, 17 Dec 2024 13:42:56 -0500 Subject: [PATCH 06/12] try to fix the error in screenshots --- packages/server/lib/screenshots.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index c141b23d9af8..3d4e79dfd2cf 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -367,7 +367,7 @@ const getDimensions = function (details) { return pick(details.image.bitmap) } -const ensureSafePath = function (withoutExt, extension, overwrite, num = 0) { +const ensureSafePath = function (withoutExt: string, extension: string, overwrite: boolean, num = 0) { const suffix = `${(num && !overwrite) ? ` (${num})` : ''}.${extension}` const maxSafePrefixBytes = maxSafeBytes - suffix.length @@ -418,7 +418,8 @@ const getPath = function (data: Data, ext, screenshotsFolder: ScreenshotsFolder, .split(pathSeparatorRe) if (data.name) { - names = data.name.split(pathSeparatorRe).map((name: string) => sanitize(name)) + // @ts-expect-error + names = data.name.split(pathSeparatorRe).map(sanitize) } else { names = _ .chain(data.titles) From f7e5958b47c2a24b67eb742bc8f6d8c62fc43b40 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Wed, 18 Dec 2024 10:51:02 -0500 Subject: [PATCH 07/12] fix type of overwrite --- packages/server/lib/screenshots.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 3d4e79dfd2cf..cd760386387b 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -367,7 +367,7 @@ const getDimensions = function (details) { return pick(details.image.bitmap) } -const ensureSafePath = function (withoutExt: string, extension: string, overwrite: boolean, num = 0) { +const ensureSafePath = function (withoutExt: string, extension: string, overwrite: Data['overwrite'], num = 0) { const suffix = `${(num && !overwrite) ? ` (${num})` : ''}.${extension}` const maxSafePrefixBytes = maxSafeBytes - suffix.length From 1315102988dcd1d7821b8832f1e9415ad11d0f50 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 19 Dec 2024 10:32:04 -0500 Subject: [PATCH 08/12] revert everything in that getPath function (just dont touch it) --- packages/server/lib/screenshots.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index cd760386387b..f2f15d754ba9 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -423,7 +423,7 @@ const getPath = function (data: Data, ext, screenshotsFolder: ScreenshotsFolder, } else { names = _ .chain(data.titles) - .map((title: string | null | undefined) => sanitizeToString(title)) + .map(sanitizeToString) .join(RUNNABLE_SEPARATOR) // @ts-expect-error - this shouldn't be necessary, but it breaks if you remove it .concat([]) From a794ab401db74278fc3b0ae8a1b6455d7c11683d Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 19 Dec 2024 11:29:56 -0500 Subject: [PATCH 09/12] more reverting --- packages/server/lib/screenshots.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index f2f15d754ba9..024ef60d7800 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -10,7 +10,6 @@ import colorString from 'color-string' import sanitize from 'sanitize-filename' import * as plugins from './plugins' import { fs } from './util/fs' -import { stat } from 'fs/promises' let debug = Debug('cypress:server:screenshot') const RUNNABLE_SEPARATOR = ' -- ' @@ -552,7 +551,8 @@ export = { .then((buffer) => { return fs.outputFile(pathToScreenshot, buffer) }).then(() => { - return stat(pathToScreenshot) + // @ts-expect-error TODO: size is not assignable here + return fs.statAsync(pathToScreenshot).get('size') }).then(({ size }) => { const dimensions = getDimensions(details) From cb5fb993e5408b8d079dd4c85a62c5c0000dd6b5 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 19 Dec 2024 13:31:02 -0500 Subject: [PATCH 10/12] fix the thenable --- packages/server/lib/screenshots.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 024ef60d7800..08f2871116a3 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -59,11 +59,11 @@ interface Details { // TODO: This is likely not representative of the entire Type and should be updated interface SavedDetails { - size?: any + size?: string takenAt?: Date - dimensions?: any + dimensions?: string multipart?: any - pixelRatio?: any + pixelRatio?: number name?: any specName?: string testFailure?: boolean @@ -553,7 +553,7 @@ export = { }).then(() => { // @ts-expect-error TODO: size is not assignable here return fs.statAsync(pathToScreenshot).get('size') - }).then(({ size }) => { + }).then((size) => { const dimensions = getDimensions(details) const { multipart, pixelRatio, takenAt } = details From eaefb6994fc886ff64e04b21fb4659b23150694c Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 19 Dec 2024 15:27:30 -0500 Subject: [PATCH 11/12] revert again --- packages/server/lib/screenshots.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 08f2871116a3..4e2b41bd8226 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -343,15 +343,10 @@ const getBuffer = function (details) { return Promise.resolve(details.buffer) } - return new Promise((resolve, reject) => { - details.image.getBuffer(Jimp.AUTO, (err, val) => { - if (err) { - reject(err) - } else { - resolve(val) - } - }) - }) + return Promise + .promisify(details.image.getBuffer) + // @ts-expect-error + .call(details.image, Jimp.AUTO) } const getDimensions = function (details) { From 6ee3416e4ef3fce1225222bca86909150c53bf0b Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Fri, 20 Dec 2024 12:53:47 -0500 Subject: [PATCH 12/12] revert outputFile change --- packages/server/lib/screenshots.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/server/lib/screenshots.ts b/packages/server/lib/screenshots.ts index 4e2b41bd8226..8f68189c7a41 100644 --- a/packages/server/lib/screenshots.ts +++ b/packages/server/lib/screenshots.ts @@ -384,7 +384,8 @@ const ensureSafePath = function (withoutExt: string, extension: string, overwrit } // path does not exist, attempt to create it to check for an ENAMETOOLONG error - return fs.outputFile(fullPath, '') + // @ts-expect-error + return fs.outputFileAsync(fullPath, '') .then(() => fullPath) .catch((err) => { debug('received error when testing path %o', { err, fullPath, maxSafePrefixBytes, maxSafeBytes })