add a test
This commit is contained in:
parent
9b9c15ecc4
commit
f6141b139e
@ -62,7 +62,7 @@ const handler = async (config) => {
|
||||
config.consola.info("running in dry mode, not saving\n", next);
|
||||
} else {
|
||||
await config.save_changelog(changelog);
|
||||
if (changelog.project.next_directory) {
|
||||
if (changelog.project?.next_directory) {
|
||||
config.consola.info(
|
||||
`removing files in ${changelog.project.next_directory}`
|
||||
);
|
||||
|
@ -4,28 +4,28 @@ import yaml from "yaml";
|
||||
import { render_release } from "./print.js";
|
||||
|
||||
export async function next_release() {
|
||||
const source = await fs.readFile(this.source, "utf-8").then(yaml.parse);
|
||||
return (
|
||||
source.releases.find(u.matches({ version: "NEXT" })) ?? {
|
||||
version: "NEXT",
|
||||
changes: [],
|
||||
}
|
||||
);
|
||||
const source = await this.changelog();
|
||||
return (
|
||||
source.releases.find(u.matches({ version: "NEXT" })) ?? {
|
||||
version: "NEXT",
|
||||
changes: [],
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const handler = async (config) => {
|
||||
const source = await fs.readFile(config.source, "utf-8").then(yaml.parse);
|
||||
const source = await config.changelog();
|
||||
|
||||
const res = render_release(
|
||||
{ ...config, next: true },
|
||||
source
|
||||
)(source.releases.find(u.matches({ version: "NEXT" })));
|
||||
const { body } = render_release(
|
||||
{ ...config, next: true },
|
||||
source
|
||||
)(await config.next_release());
|
||||
|
||||
config.consola.raw("\n" + res.body);
|
||||
config.consola.raw("\n" + body);
|
||||
};
|
||||
|
||||
export default {
|
||||
command: "upcoming",
|
||||
desc: "output the changes in NEXT",
|
||||
handler,
|
||||
command: "upcoming",
|
||||
desc: "output the changes in NEXT",
|
||||
handler,
|
||||
};
|
||||
|
29
src/command/upcoming.test.js
Normal file
29
src/command/upcoming.test.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { test, expect, vi } from "vitest";
|
||||
import upcoming from "./upcoming.js";
|
||||
|
||||
test("basic", async () => {
|
||||
const changelog = {
|
||||
releases: [{ version: "NEXT", changes: [] }, { version: "1.0.0" }],
|
||||
change_types: [],
|
||||
};
|
||||
|
||||
const noop = () => {};
|
||||
const config = {
|
||||
consola: {
|
||||
start: noop,
|
||||
raw: vi.fn(),
|
||||
},
|
||||
changelog: () => changelog,
|
||||
next_release: () => ({
|
||||
changes: [],
|
||||
}),
|
||||
latest_version: () => ({ version: "1.2.3" }),
|
||||
git: () => ({
|
||||
log: () => ({ all: [] }),
|
||||
}),
|
||||
};
|
||||
|
||||
await upcoming.handler(config);
|
||||
|
||||
expect(config.consola.raw).toHaveBeenCalled();
|
||||
});
|
Loading…
Reference in New Issue
Block a user