-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteScreenshotFromPath.ts
More file actions
39 lines (30 loc) · 1.12 KB
/
writeScreenshotFromPath.ts
File metadata and controls
39 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {readFile} from 'node:fs/promises';
import {getFullPackConfig} from '../config';
import {getDimensionsString, getPngDimensions} from '../screenshot';
import type {FilePathFromRoot, ScreenshotMeta} from '../../types/internal';
import type {AdditionalLogFields} from './types';
type Options = Readonly<{
additionalLogFields: AdditionalLogFields;
meta: ScreenshotMeta;
path: FilePathFromRoot;
type: Exclude<keyof AdditionalLogFields, 'expected' | 'isLocalRun'>;
}>;
/**
* Reads screenshot from path and writes to storage.
* @internal
*/
export const writeScreenshotFromPath = async ({
additionalLogFields,
meta,
path,
type,
}: Options): Promise<string> => {
const {getScreenshotUrlById, writeScreenshot} = getFullPackConfig().matchScreenshot;
const screenshot = await readFile(path);
const screenshotId = await writeScreenshot(screenshot, meta);
const dimensions = getDimensionsString(getPngDimensions(screenshot));
const url = getScreenshotUrlById(screenshotId);
// eslint-disable-next-line no-param-reassign
additionalLogFields[type] = {dimensions, screenshotId, url};
return screenshotId;
};