Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions src/hooks/patch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, it } from "testing/bdd";
import { assertSpyCall, stub } from "testing/mock";
import { parse } from "semver";
import { patch } from "./patch.ts";

describe("patch", () => {
it("should log formatted version string for csproj", async () => {
const consoleLogStub = stub(console, "log");
const readTextFileStub = stub(
Deno,
"readTextFile",
() =>
Promise.resolve(
"<Project>\n <PropertyGroup>\n <Version>1.0.0</Version>\n </PropertyGroup>\n</Project>",
),
);
const writeTextFileStub = stub(
Deno,
"writeTextFile",
() => Promise.resolve(),
);

try {
await patch("test.csproj", parse("1.2.3")!);

// Verify console.log was called with formatted string, not [object Object]
assertSpyCall(consoleLogStub, 0, {
args: ["patching 1.2.3 in test.csproj"],
});
} finally {
consoleLogStub.restore();
readTextFileStub.restore();
writeTextFileStub.restore();
}
});

it("should log formatted version string for package.json", async () => {
const consoleLogStub = stub(console, "log");
const readTextFileStub = stub(
Deno,
"readTextFile",
() => Promise.resolve('{"version": "1.0.0"}'),
);
const writeTextFileStub = stub(
Deno,
"writeTextFile",
() => Promise.resolve(),
);
const statStub = stub(
Deno,
"stat",
() => Promise.reject(new Deno.errors.NotFound()),
);

try {
await patch("package.json", parse("1.2.3")!);

// Verify console.log was called with formatted string, not [object Object]
assertSpyCall(consoleLogStub, 0, {
args: ["patching 1.2.3 in package.json"],
});
} finally {
consoleLogStub.restore();
readTextFileStub.restore();
writeTextFileStub.restore();
statStub.restore();
}
});
});
41 changes: 41 additions & 0 deletions src/hooks/replace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, it } from "testing/bdd";
import { assertSpyCall, stub } from "testing/mock";
import { parse } from "semver";
import { replace } from "./replace.ts";

describe("replace", () => {
it("should log formatted version strings", async () => {
const consoleLogStub = stub(console, "log");
const readTextFileStub = stub(
Deno,
"readTextFile",
() => Promise.resolve("version 1.0.0"),
);
const writeTextFileStub = stub(
Deno,
"writeTextFile",
() => Promise.resolve(),
);

try {
await replace("test.txt", parse("1.0.0")!, parse("1.2.3")!);

// Verify console.log was called with formatted strings, not [object Object]
assertSpyCall(consoleLogStub, 0, {
args: ["replacing 1.0.0 -> 1.2.3 in test.txt"],
});

// Verify file operations
assertSpyCall(readTextFileStub, 0, {
args: ["test.txt"],
});
assertSpyCall(writeTextFileStub, 0, {
args: ["test.txt", "version 1.2.3"],
});
} finally {
consoleLogStub.restore();
readTextFileStub.restore();
writeTextFileStub.restore();
}
});
});
4 changes: 2 additions & 2 deletions src/hooks/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export async function replace(
previous: SemVer,
current: SemVer,
) {
console.log(`replacing ${previous} -> ${current} in ${file}`);
const contents = await Deno.readTextFile(file);
const previousString = format(previous);
const currentString = format(current);
console.log(`replacing ${previousString} -> ${currentString} in ${file}`);
const contents = await Deno.readTextFile(file);
const updated = contents.replaceAll(previousString, currentString);
await Deno.writeTextFile(file, updated);
}
Loading