From 45b8da99a95f71d3549c22d463c4a9bd38fb2fb9 Mon Sep 17 00:00:00 2001 From: Tobias Soloschenko Date: Mon, 8 Jul 2024 15:47:52 +0200 Subject: [PATCH] feat: use branch prerelease property for detection (#863) * 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 Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> --- lib/is-prerelease.js | 12 +++++++-- test/is-prerelease.test.js | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 test/is-prerelease.test.js diff --git a/lib/is-prerelease.js b/lib/is-prerelease.js index 6eb91c16..c04a7ba3 100644 --- a/lib/is-prerelease.js +++ b/lib/is-prerelease.js @@ -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 + ); } diff --git a/test/is-prerelease.test.js b/test/is-prerelease.test.js new file mode 100644 index 00000000..8c2c60f1 --- /dev/null +++ b/test/is-prerelease.test.js @@ -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); +});