-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathplugin.test.ts
More file actions
104 lines (72 loc) · 3.77 KB
/
Copy pathplugin.test.ts
File metadata and controls
104 lines (72 loc) · 3.77 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { mkdtemp, readFile, rm, stat, unlink } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { FileSystemReportFiles } from "../src/plugin.js";
describe("FileSystemReportFiles", () => {
const temporaryDirectories: string[] = [];
afterEach(async () => {
for (const directoryPath of temporaryDirectories) {
await rm(directoryPath, { recursive: true, force: true });
}
temporaryDirectories.length = 0;
});
const createWriter = async () => {
const outputDirectory = await mkdtemp(join(tmpdir(), "allure-core-plugin-test-"));
temporaryDirectories.push(outputDirectory);
return {
outputDirectory,
writer: new FileSystemReportFiles(outputDirectory),
};
};
it("uses hardlinks for equal payloads written into different paths", async () => {
const { writer } = await createWriter();
const sourcePath = await writer.addFile("report1/main.js", Buffer.from("shared-content", "utf8"));
const targetPath = await writer.addFile("report2/main.js", Buffer.from("shared-content", "utf8"));
const sourceStat = await stat(sourcePath);
const targetStat = await stat(targetPath);
expect(await readFile(sourcePath, "utf8")).toBe("shared-content");
expect(await readFile(targetPath, "utf8")).toBe("shared-content");
if (process.platform !== "win32") {
expect(sourceStat.ino).toBe(targetStat.ino);
}
});
it("rewrites only a target file when shared link receives a different payload", async () => {
const { writer } = await createWriter();
const sourcePath = await writer.addFile("report1/main.css", Buffer.from("same-content", "utf8"));
const targetPath = await writer.addFile("report2/main.css", Buffer.from("same-content", "utf8"));
await writer.addFile("report2/main.css", Buffer.from("updated-content", "utf8"));
expect(await readFile(sourcePath, "utf8")).toBe("same-content");
expect(await readFile(targetPath, "utf8")).toBe("updated-content");
if (process.platform !== "win32") {
const sourceStat = await stat(sourcePath);
const targetStat = await stat(targetPath);
expect(sourceStat.ino).not.toBe(targetStat.ino);
}
});
it("falls back to regular write when canonical hardlink source disappears", async () => {
const { writer } = await createWriter();
const canonicalPath = await writer.addFile("report1/asset.js", Buffer.from("content-to-share", "utf8"));
await unlink(canonicalPath);
const fallbackPath = await writer.addFile("report2/asset.js", Buffer.from("content-to-share", "utf8"));
expect(await readFile(fallbackPath, "utf8")).toBe("content-to-share");
});
it("does not rewrite file when path receives identical content again", async () => {
const { writer } = await createWriter();
const targetPath = await writer.addFile("awesome/main.js", Buffer.from("stable-shared-asset", "utf8"));
const firstStat = await stat(targetPath);
await writer.addFile("awesome/main.js", Buffer.from("stable-shared-asset", "utf8"));
if (process.platform !== "win32") {
const secondStat = await stat(targetPath);
expect(firstStat.ino).toBe(secondStat.ino);
}
});
it("does not reuse rewritten canonical path for the old payload", async () => {
const { writer } = await createWriter();
const canonicalPath = await writer.addFile("report1/asset.txt", Buffer.from("old-content", "utf8"));
await writer.addFile("report1/asset.txt", Buffer.from("new-content", "utf8"));
const targetPath = await writer.addFile("report2/asset.txt", Buffer.from("old-content", "utf8"));
expect(await readFile(canonicalPath, "utf8")).toBe("new-content");
expect(await readFile(targetPath, "utf8")).toBe("old-content");
});
});