Skip to content

Commit

Permalink
feat: use branch prerelease property for detection (#863)
Browse files Browse the repository at this point in the history
* feat: use branch prerelease property for detection

* Update lib/is-prerelease.js

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>

---------

Co-authored-by: Olabode Lawal-Shittabey <babblebey@gmail.com>
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 8, 2024
1 parent c31876b commit 45b8da9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/is-prerelease.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export default function isPrerelease({ type, main }) {
return type === "prerelease" || (type === "release" && !main);
export default function isPrerelease({ type, main, prerelease }) {
if (prerelease === false) {
return false;
}
return (
type === "prerelease" ||
(type === "release" && !main) ||
typeof prerelease == "string" ||
prerelease === true
);
}
52 changes: 52 additions & 0 deletions test/is-prerelease.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import test from "ava";
import isPrerelease from "../lib/is-prerelease.js";

test("Test for empty object", (t) => {
const branch = {};
t.is(isPrerelease(branch), false);
});

test("Test if prerelease true property as boolean is used correctly", (t) => {
const branch = {
prerelease: true,
};
t.is(isPrerelease(branch), true);
});

test("Test if prerelease false property as boolean is used correctly", (t) => {
const branch = {
prerelease: false,
};
t.is(isPrerelease(branch), false);
});

test("Test if prerelease property as string is used correctly", (t) => {
const branch = {
prerelease: "rc",
};
t.is(isPrerelease(branch), true);
});

test("Test if prerelease type is used correctly", (t) => {
const branch = {
type: "prerelease",
};
t.is(isPrerelease(branch), true);
});

test("Test if prerelease type and main is used correctly", (t) => {
const branch = {
type: "release",
main: false,
};
t.is(isPrerelease(branch), true);
});

test("Test if prerelease type and main in addition to prerelease is used correctly", (t) => {
const branch = {
type: "release",
main: false,
prerelease: false,
};
t.is(isPrerelease(branch), false);
});

0 comments on commit 45b8da9

Please sign in to comment.