From ebb7b6576c66c52cd4afe27666922de611e3329e Mon Sep 17 00:00:00 2001 From: Pierre Cavin Date: Wed, 22 Nov 2023 02:57:59 +0100 Subject: [PATCH] test: add empty readme test case --- tests/fixtures/readme/readme-empty.md | 5 ++++ tests/helpers/create-test-project.js | 22 +++++++++----- tests/prepare.test.js | 43 ++++++++++++++++++++------- tests/verify-conditions.test.js | 2 +- 4 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 tests/fixtures/readme/readme-empty.md diff --git a/tests/fixtures/readme/readme-empty.md b/tests/fixtures/readme/readme-empty.md new file mode 100644 index 0000000..86967ac --- /dev/null +++ b/tests/fixtures/readme/readme-empty.md @@ -0,0 +1,5 @@ +# Hello World + +## Installation + +Checkout our documentation! diff --git a/tests/helpers/create-test-project.js b/tests/helpers/create-test-project.js index 4b0c8d1..e7d6ab6 100644 --- a/tests/helpers/create-test-project.js +++ b/tests/helpers/create-test-project.js @@ -16,15 +16,22 @@ import { temporaryDirectory } from "tempy"; */ /** - * Creates a temporary folder with a mix.exs file with the specified version + * Creates a temporary folder with mix.exs & README.md files with the specified version * * @param {string | null} [version] initial version to set in mix.exs (empty if not provided) - * @param {boolean | null} [asAttribute] whether to set the version as a module attribute - * @param {"trap" | "complex-name" | null} [mixSuffix] optional mix fixture file suffix - * @param {boolean | null} [asGitTag] whether to set the version as a module attribute + * @param {boolean | null} [asAttribute] (mix.exs) whether to set the version as a module attribute + * @param {"trap" | "complex-name" | null} [mixSuffix] (mix.exs) optional mix fixture file suffix + * @param {boolean | null} [asGitTag] (README.md) whether to set the version as a git tag + * @param {"empty" | null} [gitOverride] (README.md) override for the filename suffix * @returns {Project} */ -export function createTestProject(version, asAttribute, mixSuffix, asGitTag) { +export function createTestProject( + version, + asAttribute, + mixSuffix, + asGitTag, + gitOverride, +) { /** * mix.exs */ @@ -49,11 +56,12 @@ export function createTestProject(version, asAttribute, mixSuffix, asGitTag) { * README.md */ - const dependencyType = "-" + (asGitTag ? "git-tag" : "regular"); + const dependencyType = asGitTag ? "git-tag" : "regular"; + const readmeFixtureSuffix = gitOverride ? `${gitOverride}` : dependencyType; const readmePath = path.resolve(cwd, "README.md"); const readmeContent = fs - .readFileSync(`./tests/fixtures/readme/readme${dependencyType}.md`, { + .readFileSync(`./tests/fixtures/readme/readme-${readmeFixtureSuffix}.md`, { encoding: "utf-8", }) .replace("{{VERSION}}", version ?? ""); diff --git a/tests/prepare.test.js b/tests/prepare.test.js index b97c7d5..b3d2cc5 100644 --- a/tests/prepare.test.js +++ b/tests/prepare.test.js @@ -22,17 +22,16 @@ describe("prepare step", () => { for (let asAttribute of [false, true]) { const { cwd } = createTestProject("0.0.0-dev", asAttribute); - expect( - async () => - await prepare( - {}, - { - ...context, - cwd, - nextRelease: { version: "1.0.0" }, - }, - ), - ).not.toThrow(); + await expect( + prepare( + {}, + { + ...context, + cwd, + nextRelease: { version: "1.0.0" }, + }, + ), + ).resolves.not.toThrow(); } }); @@ -68,6 +67,28 @@ describe("prepare step", () => { } }); + it("should ignore empty README ang call the logger with the cwd", async () => { + expect.assertions(2); + + const { cwd } = createTestProject("0.0.0-dev", null, null, null, "empty"); + + await expect( + prepare( + {}, + { + ...context, + cwd, + nextRelease: { version: "1.0.0" }, + }, + ), + ).resolves.not.toThrow(); + + expect(context.logger.log).toHaveBeenCalledWith( + "No version found in README.md in %s", + cwd, + ); + }); + it("should not update the version outside of the project definition", async () => { expect.assertions(10); diff --git a/tests/verify-conditions.test.js b/tests/verify-conditions.test.js index c9ea91a..93d6ded 100644 --- a/tests/verify-conditions.test.js +++ b/tests/verify-conditions.test.js @@ -10,7 +10,7 @@ describe("verifyConditions step", () => { for (let asAttribute of [false, true]) { const { cwd } = createTestProject("0.0.0-dev", asAttribute); - expect(async () => await verifyConditions({}, { cwd })).not.toThrow(); + await expect(verifyConditions({}, { cwd })).resolves.not.toThrow(); } });