Skip to content

Commit

Permalink
test: wrap test strings in "def project" block
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Nov 21, 2023
1 parent d7c4e2f commit fd6805d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
27 changes: 18 additions & 9 deletions lib/helpers/regexes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@ import {
invalidSemVers,
validSemVers,
} from "../../tests/fixtures/regexes.fixture.js";
import { DEF_P_1, DEF_P_2 } from "../../tests/helpers/test.constants.js";
import { replaceVersionInContent, versionRegex } from "./regexes.js";

describe("replaceVersionInContent", () => {
it("should replace the version part of a match", () => {
expect(replaceVersionInContent(`version: "0.0.0-dev"`, "1.0.0")).toBe(
`version: "1.0.0"`,
);
expect(replaceVersionInContent(`@version "0.0.0-dev"`, "1.0.0")).toBe(
`@version "1.0.0"`,
expect(
replaceVersionInContent(
`${DEF_P_1}version: "0.0.0-dev"${DEF_P_2}`,
"1.0.0",
),
).toBe(`${DEF_P_1}version: "1.0.0"${DEF_P_2}`);

expect(replaceVersionInContent('@version "0.0.0-dev"', "1.0.0")).toBe(
'@version "1.0.0"',
);
});

it("should preserve indentation and newline", () => {
expect(
replaceVersionInContent(`\n version: "0.0.0-dev" \n`, "1.0.0"),
).toBe(`\n version: "1.0.0" \n`);
replaceVersionInContent(
`\n ${DEF_P_1}\n version: "0.0.0-dev"\n ${DEF_P_2} \n`,
"1.0.0",
),
).toBe(`\n ${DEF_P_1}\n version: "1.0.0"\n ${DEF_P_2} \n`);

expect(
replaceVersionInContent(`\n @version "0.0.0-dev" \n`, "1.0.0"),
).toBe(`\n @version "1.0.0" \n`);
replaceVersionInContent('\n @version "0.0.0-dev" \n', "1.0.0"),
).toBe('\n @version "1.0.0" \n');
});

it("should throw if no match is found", () => {
Expand Down
7 changes: 5 additions & 2 deletions tests/helpers/read-project-version.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { readProjectVersion } from "./read-project-version.js";
import { DEF_P_1, DEF_P_2 } from "./test.constants.js";

describe("readProjectVersion", () => {
it("should return version and subparts when match", () => {
const simple = readProjectVersion('version: "0.0.4"');
const simple = readProjectVersion(`${DEF_P_1}version: "0.0.4"${DEF_P_2}`);
expect(simple.version).toBe("0.0.4");
expect(simple.major).toBe("0");
expect(simple.minor).toBe("0");
expect(simple.patch).toBe("4");
expect(simple.prerelease).toBeUndefined();
expect(simple.metadata).toBeUndefined();

const prerelease = readProjectVersion('version: "1.0.0-alpha"');
const prerelease = readProjectVersion(
`${DEF_P_1}version: "1.0.0-alpha"${DEF_P_2}`,
);
expect(prerelease.version).toBe("1.0.0-alpha");
expect(prerelease.major).toBe("1");
expect(prerelease.minor).toBe("0");
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/test.constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEF_P_1 = "def project do\n[";
export const DEF_P_2 = "]\nend";

0 comments on commit fd6805d

Please sign in to comment.