-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preserve original attachment file extension
- Loading branch information
Showing
8 changed files
with
98 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/allure-js-commons/test/sdk/node/ReporterRuntime.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { AllureNodeReporterRuntime } from "../../../src/sdk/node"; | ||
import { mockWriter } from "../../utils/writer"; | ||
|
||
describe("AllureNodeReporterRuntime", () => { | ||
describe("writeAttachmentFromPath", () => { | ||
it("should use extension from fileExtension option if specified", async () => { | ||
const writer = mockWriter(); | ||
const runtime = new AllureNodeReporterRuntime({ writer }); | ||
|
||
runtime.startTest({}); | ||
|
||
runtime.writeAttachmentFromPath("some attachment", "some/path/to/file", { | ||
fileExtension: ".mst", | ||
contentType: "*/*", | ||
}); | ||
|
||
const attachment = runtime.getCurrentTest()!.attachments[0]; | ||
|
||
expect(attachment.name).to.be.eq("some attachment"); | ||
expect(attachment.source).to.match(/.+\.mst/); | ||
const writeAttachmentFromPathCall = writer.writeAttachmentFromPath.mock.calls[0]; | ||
|
||
expect(writeAttachmentFromPathCall[0]).to.be.eq("some/path/to/file"); | ||
expect(writeAttachmentFromPathCall[1]).to.be.eq(attachment.source); | ||
}); | ||
|
||
it("should use extension from original file if fileExtension option is not specified", async () => { | ||
const writer = mockWriter(); | ||
const runtime = new AllureNodeReporterRuntime({ writer }); | ||
|
||
runtime.startTest({}); | ||
|
||
runtime.writeAttachmentFromPath("some attachment", "some/path/to/file.abc", { | ||
contentType: "*/*", | ||
}); | ||
|
||
const attachment = runtime.getCurrentTest()!.attachments[0]; | ||
|
||
expect(attachment.name).to.be.eq("some attachment"); | ||
expect(attachment.source).to.match(/.+\.abc/); | ||
const writeAttachmentFromPathCall = writer.writeAttachmentFromPath.mock.calls[0]; | ||
|
||
expect(writeAttachmentFromPathCall[0]).to.be.eq("some/path/to/file.abc"); | ||
expect(writeAttachmentFromPathCall[1]).to.be.eq(attachment.source); | ||
}); | ||
|
||
it("should detect extension by content type if no option or path specified", async () => { | ||
const writer = mockWriter(); | ||
const runtime = new AllureNodeReporterRuntime({ writer }); | ||
|
||
runtime.startTest({}); | ||
|
||
runtime.writeAttachment({ | ||
contentType: "text/csv", | ||
name: "some other attachment", | ||
content: "attachment content", | ||
}); | ||
|
||
const attachment = runtime.getCurrentTest()!.attachments[0]; | ||
|
||
expect(attachment.name).to.be.eq("some other attachment"); | ||
expect(attachment.source).to.match(/.+\.csv/); | ||
const writeAttachmentFromPathCall = writer.writeAttachment.mock.calls[0]; | ||
|
||
expect(writeAttachmentFromPathCall[0]).to.be.eq(attachment.source); | ||
expect(writeAttachmentFromPathCall[1]).to.be.eq("attachment content"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { vi } from "vitest"; | ||
import { Category, TestResult, TestResultContainer } from "../../src"; | ||
|
||
export const mockWriter = () => ({ | ||
writeResult: vi.fn<[TestResult], void>(), | ||
writeGroup: vi.fn<[TestResultContainer], void>(), | ||
writeEnvironmentInfo: vi.fn<[Record<string, string | undefined>], void>(), | ||
writeCategoriesDefinitions: vi.fn<[Category[]], void>(), | ||
writeAttachment: vi.fn<[string, Buffer | string, BufferEncoding | undefined], void>(), | ||
writeAttachmentFromPath: vi.fn<[string, string], void>(), | ||
}); |