keep-a-changelog-new-release/__tests__/getInputs.test.ts

95 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2020-02-15 11:19:02 +05:30
import { morph } from "mock-env";
import getInputs from "../src/getInputs";
2023-06-03 01:10:42 +05:30
test("version or tag is required", function () {
expect(() => morph(getInputs, { GITHUB_REPOSITORY: "foo/bar" })).toThrow();
2020-02-15 11:19:02 +05:30
});
2023-06-03 01:10:42 +05:30
test("tag is used before version", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "0.7.0",
INPUT_VERSION: "0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
});
expect(inputs).toHaveProperty("tag", "0.7.0");
expect(inputs).toHaveProperty("version", "0.7.0");
});
2023-06-03 01:10:42 +05:30
test("version fallback works", function () {
2020-02-15 11:19:02 +05:30
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
2020-02-15 11:19:02 +05:30
});
expect(inputs).toHaveProperty("tag", "0.6.0");
expect(inputs).toHaveProperty("version", "0.6.0");
});
2023-06-03 01:10:42 +05:30
test("can parse prefixed tag", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "v0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
});
expect(inputs).toHaveProperty("tag", "v0.6.0");
expect(inputs).toHaveProperty("version", "0.6.0");
});
2023-06-03 01:10:42 +05:30
test("date is optional but has a default", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
});
2020-02-15 11:19:02 +05:30
expect(inputs).toHaveProperty("version", "0.6.0");
expect(inputs).toHaveProperty("date");
});
2023-06-03 01:10:42 +05:30
test("parses date into ISO8601", function () {
2020-02-15 11:19:02 +05:30
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
2023-06-03 01:10:42 +05:30
INPUT_DATE: "Dec 09 2019",
2020-02-15 11:19:02 +05:30
});
expect(inputs).toHaveProperty("date", "2019-12-09");
});
2023-06-03 01:10:42 +05:30
test("parses GITHUB_REPOSITORY into owner and repo", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
});
expect(inputs).toHaveProperty("owner", "foo");
expect(inputs).toHaveProperty("repo", "bar");
});
2023-06-03 01:10:42 +05:30
test("can handle ISO8601 date", function () {
2020-02-15 11:19:02 +05:30
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
2023-06-03 01:10:42 +05:30
INPUT_DATE: "2019-12-09",
2020-02-15 11:19:02 +05:30
});
expect(inputs).toHaveProperty("date", "2019-12-09");
});
2023-06-03 01:10:42 +05:30
test("changelog path is optional but has a default", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
2023-06-03 01:10:42 +05:30
GITHUB_REPOSITORY: "foo/bar",
});
expect(inputs).toHaveProperty("changelogPath", "./CHANGELOG.md");
});
2023-06-03 01:10:42 +05:30
test("parse changelog path from input", function () {
const inputs = morph(getInputs, {
INPUT_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar",
2023-06-03 01:10:42 +05:30
INPUT_CHANGELOGPATH: "./foo/bar/CHANGELOG.md",
});
expect(inputs).toHaveProperty("changelogPath", "./foo/bar/CHANGELOG.md");
});