Skip to content

Commit 5abfe8f

Browse files
committed
chore: write tests
Signed-off-by: Jakub Freisler <[email protected]>
1 parent 4ce389a commit 5abfe8f

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/afterScreenshot.hook.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { it, expect, describe } from "vitest";
22
import path from "path";
33
import { promises as fs, existsSync } from "fs";
4-
import { initAfterScreenshotHook } from "./afterScreenshot.hook";
4+
import { initAfterScreenshotHook, parseAbsolutePath } from "./afterScreenshot.hook";
55
import { dir, file, setGracefulCleanup } from "tmp-promise";
6-
import { IMAGE_SNAPSHOT_PREFIX } from "./constants";
6+
import { IMAGE_SNAPSHOT_PREFIX, PATH_VARIABLES } from "./constants";
77

88
setGracefulCleanup();
99

@@ -31,3 +31,23 @@ describe("initAfterScreenshotHook", () => {
3131
await fs.unlink(expectedNewPath);
3232
});
3333
});
34+
35+
describe('parseAbsolutePath', () => {
36+
const projectRoot = '/its/project/root';
37+
38+
it('resolves relative paths against project root', () => {
39+
expect(parseAbsolutePath({ screenshotPath: 'some/path.png', projectRoot }))
40+
.toBe('/its/project/root/some/path.png');
41+
});
42+
43+
it('builds proper win paths when found', () => {
44+
expect(parseAbsolutePath({ screenshotPath: `${PATH_VARIABLES.winSystemRootPath}/D/some/path.png`, projectRoot }))
45+
// that's expected output accorind to https://stackoverflow.com/a/64135721/8805801
46+
.toBe('D:\\/some/path.png');
47+
});
48+
49+
it('resolves relative paths against project root', () => {
50+
expect(parseAbsolutePath({ screenshotPath: `${PATH_VARIABLES.unixSystemRootPath}/some/path.png`, projectRoot }))
51+
.toBe('/some/path.png');
52+
});
53+
});

src/afterScreenshot.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const getConfigVariableOrThrow = <K extends keyof Cypress.PluginConfigOptions>(
2525
};
2626
/* c8 ignore stop */
2727

28-
const parseAbsolutePath = ({
28+
export const parseAbsolutePath = ({
2929
screenshotPath,
3030
projectRoot,
3131
}: {

0 commit comments

Comments
 (0)