-
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.
- Loading branch information
Showing
9 changed files
with
209 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ export { | |
layer, | ||
link, | ||
links, | ||
logStep, | ||
owner, | ||
parameter, | ||
parentSuite, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { type Mocked, describe, expect, it, vi } from "vitest"; | ||
import { logStep } from "../src/facade.js"; | ||
import { Status } from "../src/model.js"; | ||
import { type TestRuntime } from "../src/sdk/runtime/index.js"; | ||
|
||
const mockRuntime = (): Mocked<TestRuntime> => { | ||
return { | ||
attachment: vi.fn(), | ||
attachmentFromPath: vi.fn(), | ||
description: vi.fn(), | ||
descriptionHtml: vi.fn(), | ||
displayName: vi.fn(), | ||
historyId: vi.fn(), | ||
labels: vi.fn(), | ||
links: vi.fn(), | ||
logStep: vi.fn(), | ||
parameter: vi.fn(), | ||
step: vi.fn(), | ||
stepDisplayName: vi.fn(), | ||
stepParameter: vi.fn(), | ||
testCaseId: vi.fn(), | ||
} as Mocked<TestRuntime>; | ||
}; | ||
|
||
describe("logStep", () => { | ||
it("should log step", async () => { | ||
const runtime = mockRuntime(); | ||
vi.stubGlobal("allureTestRuntime", () => runtime); | ||
|
||
await logStep("log step"); | ||
|
||
const [name, status, error] = runtime.logStep.mock.calls[0]; | ||
expect(name).toEqual("log step"); | ||
expect(status).toBeUndefined(); | ||
expect(error).toBeUndefined(); | ||
}); | ||
it("should log step with status", async () => { | ||
const runtime = mockRuntime(); | ||
vi.stubGlobal("allureTestRuntime", () => runtime); | ||
|
||
await logStep("passed step", Status.PASSED); | ||
|
||
const [name, status, error] = runtime.logStep.mock.calls[0]; | ||
expect(name).toEqual("passed step"); | ||
expect(status).toEqual(Status.PASSED); | ||
expect(error).toBeUndefined(); | ||
}); | ||
it("should log step with status failed", async () => { | ||
const runtime = mockRuntime(); | ||
vi.stubGlobal("allureTestRuntime", () => runtime); | ||
|
||
await logStep("failed step", Status.FAILED); | ||
|
||
const [name, status, error] = runtime.logStep.mock.calls[0]; | ||
expect(name).toEqual("failed step"); | ||
expect(status).toEqual(Status.FAILED); | ||
expect(error).toBeUndefined(); | ||
}); | ||
it("should log step with error", async () => { | ||
const runtime = mockRuntime(); | ||
vi.stubGlobal("allureTestRuntime", () => runtime); | ||
|
||
const err = new Error("some error"); | ||
await logStep("failed step", Status.FAILED, err); | ||
|
||
const [name, status, error] = runtime.logStep.mock.calls[0]; | ||
expect(name).toEqual("failed step"); | ||
expect(status).toEqual(Status.FAILED); | ||
expect(error).toEqual(err); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
packages/allure-js-commons/test/sdk/runtime/MessageTestRuntime.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,67 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
import { Status } from "../../../src/model.js"; | ||
import { MessageTestRuntime } from "../../../src/sdk/runtime/MessageTestRuntime.js"; | ||
|
||
const implementMessageTestRuntime = () => | ||
new (class extends MessageTestRuntime { | ||
sendMessage = vi | ||
.fn<Parameters<MessageTestRuntime["sendMessage"]>, ReturnType<MessageTestRuntime["sendMessage"]>>() | ||
.mockImplementation(() => Promise.resolve()); | ||
})(); | ||
|
||
describe("logStep", () => { | ||
it("should create step with name", async () => { | ||
const messageTestRuntime = implementMessageTestRuntime(); | ||
|
||
await messageTestRuntime.logStep("some step name"); | ||
|
||
expect(messageTestRuntime.sendMessage).toBeCalledTimes(2); | ||
|
||
const [[message1], [message2]] = messageTestRuntime.sendMessage.mock.calls; | ||
expect(message1).toEqual({ | ||
type: "step_start", | ||
data: expect.objectContaining({ | ||
name: "some step name", | ||
}), | ||
}); | ||
expect(message2).toEqual({ | ||
type: "step_stop", | ||
data: expect.objectContaining({ | ||
status: Status.PASSED, | ||
}), | ||
}); | ||
}); | ||
it("should create step with name and status", async () => { | ||
const messageTestRuntime = implementMessageTestRuntime(); | ||
await messageTestRuntime.logStep("failed step", Status.FAILED); | ||
|
||
expect(messageTestRuntime.sendMessage).toBeCalledTimes(2); | ||
|
||
const [[message1], [message2]] = messageTestRuntime.sendMessage.mock.calls; | ||
expect(message1).toEqual({ | ||
type: "step_start", | ||
data: expect.objectContaining({ | ||
name: "failed step", | ||
}), | ||
}); | ||
expect(message2).toEqual({ | ||
type: "step_stop", | ||
data: expect.objectContaining({ | ||
status: Status.FAILED, | ||
}), | ||
}); | ||
}); | ||
it("should set correct step timings", async () => { | ||
const messageTestRuntime = implementMessageTestRuntime(); | ||
const before = Date.now(); | ||
await messageTestRuntime.logStep("broken step", Status.BROKEN); | ||
const after = Date.now(); | ||
|
||
expect(messageTestRuntime.sendMessage).toBeCalledTimes(2); | ||
|
||
const [[message1], [message2]] = messageTestRuntime.sendMessage.mock.calls; | ||
expect(message1.data.start).toBeGreaterThanOrEqual(before); | ||
expect(message1.data.start).toBeLessThanOrEqual(after); | ||
expect(message1.data.start).toEqual(message2.data.stop); | ||
}); | ||
}); |
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