Skip to content

Commit c289de4

Browse files
committed
lint and test
1 parent a493f85 commit c289de4

3 files changed

Lines changed: 108 additions & 5 deletions

File tree

packages/core-api/src/static.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const createFaviconLinkTag = (src: string) => {
1717
export const createBaseUrlScript = () => {
1818
return `
1919
<script>
20-
const { origin, pathname } = window.location;
20+
const { origin, pathname } = window.location;
2121
const url = new URL(pathname, origin);
2222
const baseEl = document.createElement("base");
23-
23+
2424
baseEl.href = url.toString();
25-
25+
2626
window.document.head.appendChild(baseEl);
2727
</script>
2828
`;

packages/core/test/plugin.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import { mkdtemp, readFile, rm, stat, unlink } from "node:fs/promises";
2+
import { tmpdir } from "node:os";
3+
import { join } from "node:path";
4+
5+
import { afterEach, describe, expect, it } from "vitest";
6+
7+
import { FileSystemReportFiles } from "../src/plugin.js";
8+
9+
describe("FileSystemReportFiles", () => {
10+
const temporaryDirectories: string[] = [];
11+
12+
afterEach(async () => {
13+
for (const directoryPath of temporaryDirectories) {
14+
await rm(directoryPath, { recursive: true, force: true });
15+
}
16+
temporaryDirectories.length = 0;
17+
});
18+
19+
const createWriter = async () => {
20+
const outputDirectory = await mkdtemp(join(tmpdir(), "allure-core-plugin-test-"));
21+
22+
temporaryDirectories.push(outputDirectory);
23+
24+
return {
25+
outputDirectory,
26+
writer: new FileSystemReportFiles(outputDirectory),
27+
};
28+
};
29+
30+
it("uses hardlinks for equal payloads written into different paths", async () => {
31+
const { writer } = await createWriter();
32+
33+
const sourcePath = await writer.addFile("report1/main.js", Buffer.from("shared-content", "utf8"));
34+
const targetPath = await writer.addFile("report2/main.js", Buffer.from("shared-content", "utf8"));
35+
const sourceStat = await stat(sourcePath);
36+
const targetStat = await stat(targetPath);
37+
38+
expect(await readFile(sourcePath, "utf8")).toBe("shared-content");
39+
expect(await readFile(targetPath, "utf8")).toBe("shared-content");
40+
41+
if (process.platform !== "win32") {
42+
expect(sourceStat.ino).toBe(targetStat.ino);
43+
}
44+
});
45+
46+
it("rewrites only a target file when shared link receives a different payload", async () => {
47+
const { writer } = await createWriter();
48+
49+
const sourcePath = await writer.addFile("report1/main.css", Buffer.from("same-content", "utf8"));
50+
const targetPath = await writer.addFile("report2/main.css", Buffer.from("same-content", "utf8"));
51+
52+
await writer.addFile("report2/main.css", Buffer.from("updated-content", "utf8"));
53+
54+
expect(await readFile(sourcePath, "utf8")).toBe("same-content");
55+
expect(await readFile(targetPath, "utf8")).toBe("updated-content");
56+
57+
if (process.platform !== "win32") {
58+
const sourceStat = await stat(sourcePath);
59+
const targetStat = await stat(targetPath);
60+
61+
expect(sourceStat.ino).not.toBe(targetStat.ino);
62+
}
63+
});
64+
65+
it("falls back to regular write when canonical hardlink source disappears", async () => {
66+
const { writer } = await createWriter();
67+
68+
const canonicalPath = await writer.addFile("report1/asset.js", Buffer.from("content-to-share", "utf8"));
69+
70+
await unlink(canonicalPath);
71+
72+
const fallbackPath = await writer.addFile("report2/asset.js", Buffer.from("content-to-share", "utf8"));
73+
74+
expect(await readFile(fallbackPath, "utf8")).toBe("content-to-share");
75+
});
76+
77+
it("does not rewrite file when path receives identical content again", async () => {
78+
const { writer } = await createWriter();
79+
80+
const targetPath = await writer.addFile("awesome/main.js", Buffer.from("stable-shared-asset", "utf8"));
81+
const firstStat = await stat(targetPath);
82+
83+
await writer.addFile("awesome/main.js", Buffer.from("stable-shared-asset", "utf8"));
84+
85+
if (process.platform !== "win32") {
86+
const secondStat = await stat(targetPath);
87+
88+
expect(firstStat.ino).toBe(secondStat.ino);
89+
}
90+
});
91+
});

packages/e2e/test/commons/output.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,20 @@ test.describe("output", () => {
181181
expect(reportTwoAttachmentFiles).toHaveLength(1);
182182
expect(reportOneAttachmentFiles[0]).toBe(reportTwoAttachmentFiles[0]);
183183

184-
const reportOneAttachmentPath = resolve(bootstrap.reportDir, "awesome1", "data", "attachments", reportOneAttachmentFiles[0]);
185-
const reportTwoAttachmentPath = resolve(bootstrap.reportDir, "awesome2", "data", "attachments", reportTwoAttachmentFiles[0]);
184+
const reportOneAttachmentPath = resolve(
185+
bootstrap.reportDir,
186+
"awesome1",
187+
"data",
188+
"attachments",
189+
reportOneAttachmentFiles[0],
190+
);
191+
const reportTwoAttachmentPath = resolve(
192+
bootstrap.reportDir,
193+
"awesome2",
194+
"data",
195+
"attachments",
196+
reportTwoAttachmentFiles[0],
197+
);
186198

187199
expect(await readFile(reportOneAttachmentPath, "utf8")).toBe("global-shared-content");
188200
expect(await readFile(reportTwoAttachmentPath, "utf8")).toBe("global-shared-content");

0 commit comments

Comments
 (0)