Skip to content

Commit

Permalink
fix(readme): update version even if no operator is present (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox authored Nov 26, 2023
1 parent 82e7111 commit 0e1aac1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/regexes/readme.regexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function createReadmeVersionRequirementRegexs(projectName) {
const readmeVersionRegexesArray = [
composeMixDepsSemVerRegex(
projectName,
/.*"\s*(?:>|>=|<|<=|==|!=|~>)\s*/,
/.*"\s*(?:>|>=|<|<=|==|!=|~>)?\s*/,
/"/,
true,
),
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/regexes/readme.regexes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("readmeVersionRegex", () => {
const { readmeVersionRegex } =
createReadmeVersionRequirementRegexs("test_package");

const operators = [">", ">=", "<", "<=", "==", "!=", "~>"];
const operators = ["", ">", ">=", "<", "<=", "==", "!=", "~>"];

expect.assertions(validSemVers.length * operators.length);
for (let semVer of validSemVers) {
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/readme/readme-no-operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Hello World

## Installation

```elixir
def deps do
[{:hello_world, "{{VERSION}}"}]
end
```
2 changes: 1 addition & 1 deletion tests/helpers/create-test-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { temporaryDirectory } from "tempy";
* @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
* @param {"empty" | "no-operator" | null} [gitOverride] (README.md) override for the filename suffix
* @returns {Project}
*/
export function createTestProject(
Expand Down
79 changes: 46 additions & 33 deletions tests/prepare.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ 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 Expand Up @@ -175,14 +153,27 @@ describe("prepare step", () => {
*/

describe("update README.md", () => {
// eslint-disable-next-line jest/prefer-expect-assertions
it("should update project version", async () => {
expect.assertions(6);

for (let asGitTag of [false, true]) {
const configs = [
{ asGitTag: false },
{ asGitTag: true },
{ override: "no-operator" },
];

expect.assertions(configs.length * 3);
for (let { asGitTag, override } of configs) {
const {
cwd,
readme: { path },
} = createTestProject("0.0.0-dev", null, null, asGitTag);
} = createTestProject(
"0.0.0-dev",
null,
null,
asGitTag,
// @ts-ignore
override,
);

await prepare(
{},
Expand All @@ -193,21 +184,43 @@ describe("prepare step", () => {
},
);

const packageContent = fs.readFileSync(path, { encoding: "utf-8" });

const readmeContent = fs.readFileSync(path, { encoding: "utf-8" });
console.debug(readmeContent);
const { readmeVersionRegex, readmeVersionRegexesArray } =
createReadmeVersionRequirementRegexs("hello_world");

expect(packageContent).toMatch(readmeVersionRegex);
expect(packageContent).not.toMatch(/0\.0\.0-dev/);
expect(readmeContent).toMatch(readmeVersionRegex);
expect(readmeContent).not.toMatch(/0\.0\.0-dev/);
const { version } = readVersion(
packageContent,
readmeContent,
readmeVersionRegexesArray,
);
expect(version).toBe("1.0.0");
}
});

it("should ignore empty README and 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 preserve indentation and newline", async () => {
expect.assertions(2);

Expand All @@ -226,8 +239,8 @@ describe("prepare step", () => {
},
);

const packageContent = fs.readFileSync(path, { encoding: "utf-8" });
expect(packageContent).toBe(
const readmeContent = fs.readFileSync(path, { encoding: "utf-8" });
expect(readmeContent).toBe(
content.replace("0.0.0-tobereplaced", "1.0.0"),
);
}
Expand Down

0 comments on commit 0e1aac1

Please sign in to comment.