Skip to content

Commit

Permalink
detect content type for binary files based on magic headers (via #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
baev authored Jan 8, 2025
1 parent 2b5328d commit 013aec4
Show file tree
Hide file tree
Showing 16 changed files with 825 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/commands/awesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export const AwesomeCommand = createCommand({
{
description: "Group test results by labels. The labels should be separated by commas",
default: "parentSuite,suite,subSuite",
}
]
},
],
],
action: AwesomeCommandAction,
});
8 changes: 4 additions & 4 deletions packages/core/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import type {
ResultsVisitor,
} from "@allurereport/reader-api";
import type { EventEmitter } from "node:events";
import { extname } from "node:path";
import type { AllureStoreEvents } from "../utils/event.js";
import { testFixtureResultRawToState, testResultRawToState } from "./convert.js";

Expand Down Expand Up @@ -131,7 +130,8 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {
this.#eventEmitter?.emit("testFixtureResult", testFixtureResult.id);
}

async visitAttachmentFile(resultFile: ResultFile): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async visitAttachmentFile(resultFile: ResultFile, context: ReaderContext): Promise<void> {
const originalFileName = resultFile.getOriginalFileName();
const id = md5(originalFileName);

Expand All @@ -143,7 +143,7 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {
// we need to preserve the same object since it's referenced in steps
const link = maybeLink as AttachmentLinkLinked;
link.missed = false;
link.ext = link?.ext ?? extname(originalFileName);
link.ext = link?.ext ?? resultFile.getExtension();
link.contentType = link.contentType ?? resultFile.getContentType();
link.contentLength = resultFile.getContentLength();
} else {
Expand All @@ -152,7 +152,7 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {
missed: false,
id,
originalFileName,
ext: extname(originalFileName),
ext: resultFile.getExtension(),
contentType: resultFile.getContentType(),
contentLength: resultFile.getContentLength(),
});
Expand Down
3 changes: 2 additions & 1 deletion packages/core/test/store/convert.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { md5 } from "@allurereport/plugin-api";
import { describe, expect, it } from "vitest";
import { StateData, testResultRawToState } from "../../src/store/convert.js";
import type { StateData } from "../../src/store/convert.js";
import { testResultRawToState } from "../../src/store/convert.js";

const emptyStateData: StateData = { testCases: new Map(), attachments: new Map(), visitAttachmentLink: () => {} };

Expand Down
5 changes: 3 additions & 2 deletions packages/core/test/store/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HistoryDataPoint } from "@allurereport/core-api";
import type { HistoryDataPoint } from "@allurereport/core-api";
import { md5 } from "@allurereport/plugin-api";
import { BufferResultFile, RawTestResult } from "@allurereport/reader-api";
import type { RawTestResult } from "@allurereport/reader-api";
import { BufferResultFile } from "@allurereport/reader-api";
import { describe, expect, it } from "vitest";
import { DefaultAllureStore } from "../../src/store/store.js";

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-api/src/resultFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Readable } from "node:stream";
export interface ResultFile {
readContent: <T>(transform: (stream: Readable) => Promise<T | undefined>) => Promise<T | undefined>;
getOriginalFileName: () => string;
getExtension: () => string;
getContentType: () => string | undefined;
getContentLength: () => number | undefined;
asJson: <T>() => Promise<T | undefined>;
Expand Down
Loading

0 comments on commit 013aec4

Please sign in to comment.