chore: run prettier

This commit is contained in:
Harsh Shandilya 2023-06-03 01:10:42 +05:30
parent bf43ae42f4
commit 7607f96ee1
No known key found for this signature in database
8 changed files with 83 additions and 83 deletions

View File

@ -3,8 +3,8 @@ import formatDate from "../src/formatDate";
it.each([
["Dec 09 2019", "2019-12-09"],
["Dec 16 2019", "2019-12-16"],
["Jan 09 2019", "2019-01-09"]
])("should format '%s' as '%s'", function(given, expected) {
["Jan 09 2019", "2019-01-09"],
])("should format '%s' as '%s'", function (given, expected) {
const date = new Date(Date.parse(given));
const formatted = formatDate(date);

View File

@ -1,6 +1,6 @@
import getGenesisHash from "../src/getGenesisHash";
it("should return a hash", async function() {
it("should return a hash", async function () {
const hash = await getGenesisHash();
expect(hash).toHaveLength(40);

View File

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

View File

@ -10,39 +10,43 @@ interface Fixture {
repo: string;
}
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference", "tag_release", "tag_on_tag"])(
`should update %s changelog`,
async function(testcase) {
const before = await read(`./__tests__/fixtures/${testcase}/CHANGELOG.md`, {
encoding: "utf-8"
});
const expected = await read(
`./__tests__/fixtures/${testcase}/CHANGELOG.expected.md`,
{
encoding: "utf-8"
}
);
const release: Fixture = await import(
`./fixtures/${testcase}/fixture`
).then(module => module.default);
it.each([
"empty_release",
"standard",
"first_release",
"lowercase_link_reference",
"tag_release",
"tag_on_tag",
])(`should update %s changelog`, async function (testcase) {
const before = await read(`./__tests__/fixtures/${testcase}/CHANGELOG.md`, {
encoding: "utf-8",
});
const expected = await read(
`./__tests__/fixtures/${testcase}/CHANGELOG.expected.md`,
{
encoding: "utf-8",
}
);
const release: Fixture = await import(`./fixtures/${testcase}/fixture`).then(
(module) => module.default
);
const actual = await updateChangelog(
before,
release.tag,
release.version,
release.date,
release.genesisHash,
release.owner,
release.repo
);
actual.path = `./__tests__/fixtures/${testcase}/CHANGELOG.actual.md`;
await write(actual, {
encoding: "utf-8"
});
const actual = await updateChangelog(
before,
release.tag,
release.version,
release.date,
release.genesisHash,
release.owner,
release.repo
);
actual.path = `./__tests__/fixtures/${testcase}/CHANGELOG.actual.md`;
await write(actual, {
encoding: "utf-8",
});
const actualContent = actual.toString("utf-8");
const expectedContent = expected.toString("utf-8");
const actualContent = actual.toString("utf-8");
const expectedContent = expected.toString("utf-8");
expect(actualContent).toEqual(expectedContent);
}
);
expect(actualContent).toEqual(expectedContent);
});

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ export default async function getGenesisHash(): Promise<string> {
const outStream = new WritableStreamBuffer();
const exitCode = await exec("git", ["rev-list", "--max-parents=0", "HEAD"], {
outStream
outStream,
});
if (exitCode !== 0) {

View File

@ -49,6 +49,6 @@ export default function getInputs(): Inputs {
date,
owner,
repo,
changelogPath
changelogPath,
};
}

View File

@ -78,7 +78,7 @@ function releaseTransformation({
releaseDate,
genesisHash,
owner,
repo
repo,
}: Options) {
return transformer;
@ -103,9 +103,7 @@ function releaseTransformation({
function determinePreviousVersion(tree: MarkdownRootNode): string | null {
const children = tree.children;
const versions = children.filter(
node => node.type === "definition"
);
const versions = children.filter((node) => node.type === "definition");
const previousRelease = versions[1] as DefinitionNode | undefined;
@ -117,9 +115,7 @@ function determinePreviousVersion(tree: MarkdownRootNode): string | null {
const split = link.split("...");
if (split.length !== 2) {
throw new Error(
"Invalid changelog format, compare url is not standard"
);
throw new Error("Invalid changelog format, compare url is not standard");
}
return split[1];
@ -134,7 +130,7 @@ function convertUnreleasedSectionToNewRelease(
// the unreleased section should always be at the top
const unreleasedSection = children.find(
node => node.type === "heading" && node.depth === 2
(node) => node.type === "heading" && node.depth === 2
) as HeadingNode | undefined;
if (!unreleasedSection) {
@ -167,14 +163,14 @@ function convertUnreleasedSectionToNewRelease(
children: [
{
type: "text",
value: version
}
]
value: version,
},
],
},
{
type: "text",
value
}
value,
},
];
unreleasedSection.children = newReleaseSection;
@ -184,7 +180,7 @@ function addEmptyUnreleasedSection(tree: MarkdownRootNode) {
const children = tree.children;
const firstHeadingSectionIndex = children.findIndex(
node => node.type === "heading" && node.depth === 2
(node) => node.type === "heading" && node.depth === 2
);
const beforeFirstHeading = children.slice(0, firstHeadingSectionIndex);
@ -205,13 +201,13 @@ function addEmptyUnreleasedSection(tree: MarkdownRootNode) {
children: [
{
type: "text",
value: "Unreleased"
}
]
}
]
value: "Unreleased",
},
],
},
],
},
...afterFirstHeading
...afterFirstHeading,
];
}
@ -227,7 +223,7 @@ function updateCompareUrls(
const children = tree.children;
const unreleasedDefinitionIndex = children.findIndex(
node => node.type === "definition" && node.identifier === "unreleased"
(node) => node.type === "definition" && node.identifier === "unreleased"
);
const before =
@ -250,15 +246,15 @@ function updateCompareUrls(
type: "definition",
identifier: "unreleased",
url: unreleasedCompareUrl,
label: "Unreleased"
label: "Unreleased",
},
{
type: "definition",
identifier: newVersion,
url: previousVersionCompareUrl,
label: newVersion
label: newVersion,
},
...after
...after,
];
}
@ -279,7 +275,7 @@ export default async function updateChangelog(
releaseDate,
genesisHash,
owner,
repo
repo,
})
.use(stringify)
.process(file);