Skip to content

Commit c7823ef

Browse files
committed
chore: run linter
Signed-off-by: Jakub Freisler <[email protected]>
1 parent c3b44a4 commit c7823ef

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

src/image.utils.ts

+29-8
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ import { METADATA_KEY } from "./constants";
1010

1111
type PluginMetadata = {
1212
version: string;
13-
testingType?: 'e2e' | 'component';
13+
testingType?: "e2e" | "component";
1414
};
1515

1616
type PluginMetadataConfig = {
1717
testingType?: string;
1818
};
1919

2020
export const addPNGMetadata = (config: PluginMetadataConfig, png: Buffer) =>
21-
addMetadata(png, METADATA_KEY, JSON.stringify({ version, testingType: config.testingType || 'e2e' } as PluginMetadata) /* c8 ignore next */);
21+
addMetadata(
22+
png,
23+
METADATA_KEY,
24+
JSON.stringify({
25+
version,
26+
testingType: config.testingType || "e2e",
27+
} as PluginMetadata) /* c8 ignore next */
28+
);
2229
export const getPNGMetadata = (png: Buffer): PluginMetadata | undefined => {
2330
const metadataString = getMetadata(png, METADATA_KEY /* c8 ignore next */);
2431

@@ -28,18 +35,30 @@ export const getPNGMetadata = (png: Buffer): PluginMetadata | undefined => {
2835
} catch {
2936
return { version: metadataString };
3037
}
31-
}
38+
};
3239
export const isImageCurrentVersion = (png: Buffer) =>
3340
getPNGMetadata(png)?.version === version;
3441
export const isImageGeneratedByPlugin = (png: Buffer) =>
3542
!!getPNGMetadata(png /* c8 ignore next */);
36-
export const isImageOfTestType = (png: Buffer, testingType?: PluginMetadataConfig['testingType']) => {
43+
export const isImageOfTestType = (
44+
png: Buffer,
45+
testingType?: PluginMetadataConfig["testingType"]
46+
) => {
3747
if (!isImageGeneratedByPlugin(png)) return false;
38-
const imageTestingType = getPNGMetadata(png /* c8 ignore next */)?.testingType;
39-
return imageTestingType === testingType || testingType === imageTestingType === undefined;
48+
const imageTestingType = getPNGMetadata(
49+
png /* c8 ignore next */
50+
)?.testingType;
51+
return (
52+
imageTestingType === testingType ||
53+
(testingType === imageTestingType) === undefined
54+
);
4055
};
4156

42-
export const writePNG = (config: PluginMetadataConfig, name: string, png: PNG | Buffer) =>
57+
export const writePNG = (
58+
config: PluginMetadataConfig,
59+
name: string,
60+
png: PNG | Buffer
61+
) =>
4362
fs.writeFileSync(
4463
name,
4564
addPNGMetadata(config, png instanceof PNG ? PNG.sync.write(png) : png)
@@ -117,7 +136,9 @@ export const alignImagesToSameSize = (
117136
];
118137
};
119138

120-
export const cleanupUnused = (config: PluginMetadataConfig & { projectRoot: string; }) => {
139+
export const cleanupUnused = (
140+
config: PluginMetadataConfig & { projectRoot: string }
141+
) => {
121142
glob
122143
.sync("**/*.png", {
123144
cwd: config.projectRoot,

src/task.hook.test.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe("cleanupImagesTask", () => {
118118
);
119119
};
120120

121-
describe('when testing type does not match', () => {
121+
describe("when testing type does not match", () => {
122122
it("does not remove unused screenshot", async () => {
123123
const { path: projectRoot } = await dir();
124124
const screenshotPath = await writeTmpFixture(
@@ -129,14 +129,14 @@ describe("cleanupImagesTask", () => {
129129
cleanupImagesTask({
130130
projectRoot,
131131
env: { pluginVisualRegressionCleanupUnusedImages: true },
132-
testingType: 'component',
132+
testingType: "component",
133133
} as unknown as Cypress.PluginConfigOptions);
134134

135135
expect(existsSync(screenshotPath)).toBe(true);
136136
});
137137
});
138138

139-
describe('when testing type matches', () => {
139+
describe("when testing type matches", () => {
140140
it("does not remove used screenshot", async () => {
141141
const { path: projectRoot } = await dir();
142142
const screenshotPath = await writeTmpFixture(
@@ -147,7 +147,7 @@ describe("cleanupImagesTask", () => {
147147
cleanupImagesTask({
148148
projectRoot,
149149
env: { pluginVisualRegressionCleanupUnusedImages: true },
150-
testingType: 'e2e',
150+
testingType: "e2e",
151151
} as unknown as Cypress.PluginConfigOptions);
152152

153153
expect(existsSync(screenshotPath)).toBe(true);
@@ -163,7 +163,7 @@ describe("cleanupImagesTask", () => {
163163
cleanupImagesTask({
164164
projectRoot,
165165
env: { pluginVisualRegressionCleanupUnusedImages: true },
166-
testingType: 'e2e',
166+
testingType: "e2e",
167167
} as unknown as Cypress.PluginConfigOptions);
168168

169169
expect(existsSync(screenshotPath)).toBe(false);
@@ -205,7 +205,10 @@ describe("compareImagesTask", () => {
205205
describe("when old screenshot exists", () => {
206206
it("resolves with a success message", async () =>
207207
expect(
208-
compareImagesTask({ testingType: 'e2e' }, await generateConfig({ updateImages: true }))
208+
compareImagesTask(
209+
{ testingType: "e2e" },
210+
await generateConfig({ updateImages: true })
211+
)
209212
).resolves.toEqual({
210213
message:
211214
"Image diff factor (0%) is within boundaries of maximum threshold option 0.5.",
@@ -224,7 +227,9 @@ describe("compareImagesTask", () => {
224227
const cfg = await generateConfig({ updateImages: false });
225228
await fs.unlink(cfg.imgOld);
226229

227-
await expect(compareImagesTask({ testingType: 'e2e' }, cfg)).resolves.toEqual({
230+
await expect(
231+
compareImagesTask({ testingType: "e2e" }, cfg)
232+
).resolves.toEqual({
228233
message:
229234
"Image diff factor (0%) is within boundaries of maximum threshold option 0.5.",
230235
imgDiff: 0,
@@ -241,7 +246,9 @@ describe("compareImagesTask", () => {
241246
it("resolves with an error message", async () => {
242247
const cfg = await generateConfig({ updateImages: false });
243248

244-
await expect(compareImagesTask({ testingType: 'e2e' }, cfg)).resolves.toMatchSnapshot();
249+
await expect(
250+
compareImagesTask({ testingType: "e2e" }, cfg)
251+
).resolves.toMatchSnapshot();
245252
});
246253
});
247254

@@ -250,7 +257,9 @@ describe("compareImagesTask", () => {
250257
const cfg = await generateConfig({ updateImages: false });
251258
await writeTmpFixture(cfg.imgNew, oldImgFixture);
252259

253-
await expect(compareImagesTask({ testingType: 'e2e' }, cfg)).resolves.toMatchSnapshot();
260+
await expect(
261+
compareImagesTask({ testingType: "e2e" }, cfg)
262+
).resolves.toMatchSnapshot();
254263
});
255264
});
256265
});

0 commit comments

Comments
 (0)