Skip to content

Commit 3db36a2

Browse files
committed
fix more tests
1 parent 22d5f32 commit 3db36a2

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

packages/cli/test/commands/agentLatest.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { join } from "node:path";
2+
13
import { readLatestAgentState, resolveAgentStateDir } from "@allurereport/plugin-agent";
2-
import { epic, feature, label, story } from "allure-js-commons";
4+
import { attachment, epic, feature, label, story } from "allure-js-commons";
35
import { run } from "clipanion";
46
import { type Mock, beforeEach, describe, expect, it, vi } from "vitest";
57

@@ -40,21 +42,28 @@ beforeEach(async () => {
4042
describe("agent latest command", () => {
4143
it("should print the latest output directory and index path for the resolved project cwd", async () => {
4244
const consoleModule = await import("node:console");
45+
const outputDir = "/tmp/allure-agent-123";
46+
const indexPath = join(outputDir, "index.md");
4347

4448
(readLatestAgentState as Mock).mockResolvedValueOnce({
4549
schema: "allure-agent-latest/v1",
4650
cwd: "/cwd",
47-
outputDir: "/tmp/allure-agent-123",
51+
outputDir,
4852
command: "npm test",
4953
startedAt: "2026-04-15T18:00:00.000Z",
5054
status: "finished",
5155
});
5256

5357
await run(AgentLatestCommand, ["agent", "latest"]);
5458

59+
await attachment(
60+
"latest output path contract",
61+
JSON.stringify({ outputDir, indexPath }, null, 2),
62+
"application/json",
63+
);
5564
expect(readLatestAgentState).toHaveBeenCalledWith("/cwd");
56-
expect(consoleModule.log).toHaveBeenNthCalledWith(1, "agent output: /tmp/allure-agent-123");
57-
expect(consoleModule.log).toHaveBeenNthCalledWith(2, "agent index: /tmp/allure-agent-123/index.md");
65+
expect(consoleModule.log).toHaveBeenNthCalledWith(1, `agent output: ${outputDir}`);
66+
expect(consoleModule.log).toHaveBeenNthCalledWith(2, `agent index: ${indexPath}`);
5867
});
5968

6069
it("should exit with code 1 when no latest output exists for the project", async () => {

packages/cli/test/commands/agentSelect.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { dirname, resolve } from "node:path";
2+
13
import { resolveAgentSelectionOutputDir, selectAgentTestPlan } from "@allurereport/plugin-agent";
2-
import { epic, feature, label, story } from "allure-js-commons";
4+
import { attachment, epic, feature, label, story } from "allure-js-commons";
35
import { run, UsageError } from "clipanion";
46
import { type Mock, beforeEach, describe, expect, it, vi } from "vitest";
57

@@ -90,6 +92,8 @@ describe("agent select command", () => {
9092
it("should write the selected test plan and print selection summary when output is provided", async () => {
9193
const consoleModule = await import("node:console");
9294
const fsModule = await import("node:fs/promises");
95+
const outputPath = resolve("/cwd", "./testplan.json");
96+
const outputDir = dirname(outputPath);
9397

9498
(resolveAgentSelectionOutputDir as Mock).mockResolvedValueOnce("/tmp/agent-output");
9599
(selectAgentTestPlan as Mock).mockResolvedValueOnce({
@@ -113,13 +117,18 @@ describe("agent select command", () => {
113117
"./testplan.json",
114118
]);
115119

116-
expect(fsModule.mkdir).toHaveBeenCalledWith("/cwd", { recursive: true });
120+
await attachment(
121+
"selected test plan output path contract",
122+
JSON.stringify({ outputPath, outputDir }, null, 2),
123+
"application/json",
124+
);
125+
expect(fsModule.mkdir).toHaveBeenCalledWith(outputDir, { recursive: true });
117126
expect(fsModule.writeFile).toHaveBeenCalledWith(
118-
"/cwd/testplan.json",
127+
outputPath,
119128
`{\n "version": "1.0",\n "tests": [\n {\n "selector": "suite feature A"\n },\n {\n "selector": "suite feature B"\n }\n ]\n}\n`,
120129
"utf-8",
121130
);
122-
expect(consoleModule.log).toHaveBeenNthCalledWith(1, "agent testplan: /cwd/testplan.json");
131+
expect(consoleModule.log).toHaveBeenNthCalledWith(1, `agent testplan: ${outputPath}`);
123132
expect(consoleModule.log).toHaveBeenNthCalledWith(2, "agent selection source: /tmp/agent-output");
124133
expect(consoleModule.log).toHaveBeenNthCalledWith(3, "agent selection preset: failed");
125134
expect(consoleModule.log).toHaveBeenNthCalledWith(4, "agent selection tests: 2");

0 commit comments

Comments
 (0)