Skip to content

Commit d856f94

Browse files
Fix hook output displaying [object Object] instead of version strings (#131)
* Initial plan * Initial investigation of hook output issue Co-authored-by: justinmchase <[email protected]> * Fix hook output to display version strings instead of [object Object] Co-authored-by: justinmchase <[email protected]> * Remove deprecated jsr:@std/assert version --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: justinmchase <[email protected]> Co-authored-by: Justin Chase <[email protected]>
1 parent 837dcc3 commit d856f94

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

deno.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hooks/patch.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { describe, it } from "testing/bdd";
2+
import { assertSpyCall, stub } from "testing/mock";
3+
import { parse } from "semver";
4+
import { patch } from "./patch.ts";
5+
6+
describe("patch", () => {
7+
it("should log formatted version string for csproj", async () => {
8+
const consoleLogStub = stub(console, "log");
9+
const readTextFileStub = stub(
10+
Deno,
11+
"readTextFile",
12+
() =>
13+
Promise.resolve(
14+
"<Project>\n <PropertyGroup>\n <Version>1.0.0</Version>\n </PropertyGroup>\n</Project>",
15+
),
16+
);
17+
const writeTextFileStub = stub(
18+
Deno,
19+
"writeTextFile",
20+
() => Promise.resolve(),
21+
);
22+
23+
try {
24+
await patch("test.csproj", parse("1.2.3")!);
25+
26+
// Verify console.log was called with formatted string, not [object Object]
27+
assertSpyCall(consoleLogStub, 0, {
28+
args: ["patching 1.2.3 in test.csproj"],
29+
});
30+
} finally {
31+
consoleLogStub.restore();
32+
readTextFileStub.restore();
33+
writeTextFileStub.restore();
34+
}
35+
});
36+
37+
it("should log formatted version string for package.json", async () => {
38+
const consoleLogStub = stub(console, "log");
39+
const readTextFileStub = stub(
40+
Deno,
41+
"readTextFile",
42+
() => Promise.resolve('{"version": "1.0.0"}'),
43+
);
44+
const writeTextFileStub = stub(
45+
Deno,
46+
"writeTextFile",
47+
() => Promise.resolve(),
48+
);
49+
const statStub = stub(
50+
Deno,
51+
"stat",
52+
() => Promise.reject(new Deno.errors.NotFound()),
53+
);
54+
55+
try {
56+
await patch("package.json", parse("1.2.3")!);
57+
58+
// Verify console.log was called with formatted string, not [object Object]
59+
assertSpyCall(consoleLogStub, 0, {
60+
args: ["patching 1.2.3 in package.json"],
61+
});
62+
} finally {
63+
consoleLogStub.restore();
64+
readTextFileStub.restore();
65+
writeTextFileStub.restore();
66+
statStub.restore();
67+
}
68+
});
69+
});

src/hooks/replace.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, it } from "testing/bdd";
2+
import { assertSpyCall, stub } from "testing/mock";
3+
import { parse } from "semver";
4+
import { replace } from "./replace.ts";
5+
6+
describe("replace", () => {
7+
it("should log formatted version strings", async () => {
8+
const consoleLogStub = stub(console, "log");
9+
const readTextFileStub = stub(
10+
Deno,
11+
"readTextFile",
12+
() => Promise.resolve("version 1.0.0"),
13+
);
14+
const writeTextFileStub = stub(
15+
Deno,
16+
"writeTextFile",
17+
() => Promise.resolve(),
18+
);
19+
20+
try {
21+
await replace("test.txt", parse("1.0.0")!, parse("1.2.3")!);
22+
23+
// Verify console.log was called with formatted strings, not [object Object]
24+
assertSpyCall(consoleLogStub, 0, {
25+
args: ["replacing 1.0.0 -> 1.2.3 in test.txt"],
26+
});
27+
28+
// Verify file operations
29+
assertSpyCall(readTextFileStub, 0, {
30+
args: ["test.txt"],
31+
});
32+
assertSpyCall(writeTextFileStub, 0, {
33+
args: ["test.txt", "version 1.2.3"],
34+
});
35+
} finally {
36+
consoleLogStub.restore();
37+
readTextFileStub.restore();
38+
writeTextFileStub.restore();
39+
}
40+
});
41+
});

src/hooks/replace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export async function replace(
55
previous: SemVer,
66
current: SemVer,
77
) {
8-
console.log(`replacing ${previous} -> ${current} in ${file}`);
9-
const contents = await Deno.readTextFile(file);
108
const previousString = format(previous);
119
const currentString = format(current);
10+
console.log(`replacing ${previousString} -> ${currentString} in ${file}`);
11+
const contents = await Deno.readTextFile(file);
1212
const updated = contents.replaceAll(previousString, currentString);
1313
await Deno.writeTextFile(file, updated);
1414
}

0 commit comments

Comments
 (0)