More test cases:
This commit is contained in:
@ -64,7 +64,11 @@ class UpdateFlakeLockAction extends DetSysAction {
|
||||
const commitMessage =
|
||||
this.commitMessage !== ""
|
||||
? this.commitMessage
|
||||
: renderCommitMessage(this.commitMessageTemplate, flakeDotLock);
|
||||
: renderCommitMessage(
|
||||
this.commitMessageTemplate,
|
||||
flakeDir,
|
||||
flakeDotLock,
|
||||
);
|
||||
|
||||
// Nix command of this form:
|
||||
// nix ${maybe nix options} flake ${"update" or "lock"} ${maybe --update-input flags} --commit-lock-file --commit-lockfile-summary ${commit message}
|
||||
|
@ -1,31 +1,58 @@
|
||||
import { renderCommitMessage } from "./template.js";
|
||||
import { describe, expect, test } from "vitest";
|
||||
import { renderCommitMessage, renderPullRequestBody } from "./template.js";
|
||||
import { template } from "handlebars";
|
||||
import { Test, describe, expect, test } from "vitest";
|
||||
|
||||
describe("templating", () => {
|
||||
test("commit message", () => {
|
||||
type TestCase = {
|
||||
template: string;
|
||||
flakeDotLockDir: string;
|
||||
flakeDotLock: string;
|
||||
expected: string;
|
||||
};
|
||||
|
||||
const testCases: TestCase[] = [
|
||||
{
|
||||
template: "Updating lockfile at {{ flake_dot_lock }}",
|
||||
template: "Updating flake.lock in dir {{ flake_dot_lock_dir }}",
|
||||
flakeDotLockDir: ".",
|
||||
flakeDotLock: "./flake.lock",
|
||||
expected: "Updating lockfile at ./flake.lock",
|
||||
expected: "Updating flake.lock in dir .",
|
||||
},
|
||||
{
|
||||
template:
|
||||
"Here I go doing some updating of my pristine flake.lock at {{ flake_dot_lock }}",
|
||||
flakeDotLockDir: "subflake",
|
||||
flakeDotLock: "subflake/flake.lock",
|
||||
expected:
|
||||
"Here I go doing some updating of my pristine flake.lock at subflake/flake.lock",
|
||||
},
|
||||
{
|
||||
template: "This variable doesn't exist: {{ foo }}",
|
||||
flakeDotLockDir: ".",
|
||||
flakeDotLock: "./flake.lock",
|
||||
expected: "This variable doesn't exist: ",
|
||||
},
|
||||
];
|
||||
|
||||
testCases.forEach(({ template, flakeDotLock, expected }) => {
|
||||
expect(renderCommitMessage(template, flakeDotLock)).toEqual(expected);
|
||||
testCases.forEach(
|
||||
({ template, flakeDotLockDir, flakeDotLock, expected }) => {
|
||||
expect(
|
||||
renderCommitMessage(template, flakeDotLockDir, flakeDotLock),
|
||||
).toEqual(expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("pull request body", () => {
|
||||
type TestCase = {
|
||||
template: string;
|
||||
expected: string;
|
||||
};
|
||||
|
||||
const testCases: TestCase[] = [];
|
||||
|
||||
testCases.forEach(({ template, expected }) => {
|
||||
expect(renderPullRequestBody(template)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,10 +1,19 @@
|
||||
import Handlebars from "handlebars";
|
||||
|
||||
export function renderPullRequestBody(template: string): string {
|
||||
const tpl = Handlebars.compile(template);
|
||||
return tpl({});
|
||||
}
|
||||
|
||||
export function renderCommitMessage(
|
||||
template: string,
|
||||
flakeDotLockDir: string,
|
||||
flakeDotLock: string,
|
||||
): string {
|
||||
return render(template, { flake_dot_lock: flakeDotLock });
|
||||
return render(template, {
|
||||
flake_dot_lock_dir: flakeDotLockDir,
|
||||
flake_dot_lock: flakeDotLock,
|
||||
});
|
||||
}
|
||||
|
||||
function render(template: string, inputs: Record<string, string>): string {
|
||||
|
Reference in New Issue
Block a user