From f6141b139e8ad20e81a8c1fb2bead8037ceb59e2 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Thu, 18 May 2023 16:04:04 -0400 Subject: [PATCH] add a test --- src/command/cut.js | 2 +- src/command/upcoming.js | 32 ++++++++++++++++---------------- src/command/upcoming.test.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/command/upcoming.test.js diff --git a/src/command/cut.js b/src/command/cut.js index b325763..1ba7714 100644 --- a/src/command/cut.js +++ b/src/command/cut.js @@ -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}` ); diff --git a/src/command/upcoming.js b/src/command/upcoming.js index 3d480e4..031016e 100644 --- a/src/command/upcoming.js +++ b/src/command/upcoming.js @@ -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, }; diff --git a/src/command/upcoming.test.js b/src/command/upcoming.test.js new file mode 100644 index 0000000..2d63ba8 --- /dev/null +++ b/src/command/upcoming.test.js @@ -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(); +});