Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure results dir created before write result #974

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PathLike, copyFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
import { join } from "path";
import { PathLike, copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import properties from "properties";
import { Category, TestResult, TestResultContainer } from "../../../model.js";
import { Writer } from "../../Writer.js";
Expand All @@ -9,14 +9,7 @@ const writeJson = (path: string, data: unknown): void => {
};

export class FileSystemAllureWriter implements Writer {
constructor(private config: { resultsDir: string }) {
// TODO: create results dir every time we write something
if (!existsSync(this.config.resultsDir)) {
mkdirSync(this.config.resultsDir, {
recursive: true,
});
}
}
constructor(private config: { resultsDir: string }) {}

writeAttachment(distFileName: string, content: Buffer | string, encoding: BufferEncoding = "utf-8"): void {
const path = this.buildPath(distFileName);
Expand Down Expand Up @@ -54,6 +47,12 @@ export class FileSystemAllureWriter implements Writer {
}

private buildPath(name: string): string {
if (!existsSync(this.config.resultsDir)) {
mkdirSync(this.config.resultsDir, {
recursive: true,
});
}

return join(this.config.resultsDir, name);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { randomUUID } from "crypto";
import { existsSync, mkdtempSync, readFileSync, readdirSync, writeFileSync } from "fs";
import * as os from "os";
import path from "path";
import { randomUUID } from "node:crypto";
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import * as os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { AllureNodeReporterRuntime, Config, ContentType, FileSystemAllureWriter } from "../../src/sdk/node/index.js";

Expand Down Expand Up @@ -39,15 +39,22 @@ describe("FileSystemAllureWriter", () => {
expect(actualContent.toString("utf8")).toBe(data);
});

it("Should create allure-report nested path", () => {
it("creates allure-report nested path every time writer write something", () => {
const tmpReportPath = path.join(os.tmpdir(), `./allure-testing-dir/${randomUUID()}`);
epszaw marked this conversation as resolved.
Show resolved Hide resolved
const config: Config = {
writer: new FileSystemAllureWriter({
resultsDir: tmpReportPath,
}),
};
const runtime = new AllureNodeReporterRuntime(config);

new AllureNodeReporterRuntime(config);
runtime.startTest({});
runtime.stopTest();
runtime.writeTest();
rmSync(tmpReportPath, { recursive: true });
runtime.startTest({});
runtime.stopTest();
runtime.writeTest();

expect(existsSync(tmpReportPath)).toBe(true);
});
Expand Down
Loading