Skip to content

Commit

Permalink
test: add empty readme test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Nov 22, 2023
1 parent b2c974f commit ebb7b65
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 19 deletions.
5 changes: 5 additions & 0 deletions tests/fixtures/readme/readme-empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Hello World

## Installation

Checkout our documentation!
22 changes: 15 additions & 7 deletions tests/helpers/create-test-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 ?? "");
Expand Down
43 changes: 32 additions & 11 deletions tests/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/verify-conditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down

0 comments on commit ebb7b65

Please sign in to comment.