|
1 | 1 | import { it, expect, describe } from "vitest";
|
2 | 2 | import path from "path";
|
3 | 3 | import { promises as fs, existsSync } from "fs";
|
4 |
| -import { initAfterScreenshotHook } from "./afterScreenshot.hook"; |
| 4 | +import { initAfterScreenshotHook, parseAbsolutePath } from "./afterScreenshot.hook"; |
5 | 5 | import { dir, file, setGracefulCleanup } from "tmp-promise";
|
6 |
| -import { IMAGE_SNAPSHOT_PREFIX } from "./constants"; |
| 6 | +import { IMAGE_SNAPSHOT_PREFIX, PATH_VARIABLES } from "./constants"; |
7 | 7 |
|
8 | 8 | setGracefulCleanup();
|
9 | 9 |
|
@@ -31,3 +31,23 @@ describe("initAfterScreenshotHook", () => {
|
31 | 31 | await fs.unlink(expectedNewPath);
|
32 | 32 | });
|
33 | 33 | });
|
| 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 | +}); |
0 commit comments