Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibz87 committed Feb 5, 2025
1 parent 0b7b24d commit 2e8e341
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function processTokens(tokens: Token[], opts: Options): Changelog {

while (link) {
if (!changelog.url) {
const matches = link.match(/^\[.*\]\:\s*(http.*?)\/(?:-\/)?compare\/.*$/);
const matches = link.match(/^\[.*\]\:\s*(http.*?)\/(?:-\/)?(branchCompare|compare)(\/|\?).*$/);

if (matches) {
changelog.url = matches[1];
Expand Down
24 changes: 24 additions & 0 deletions test/changelog.azdo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Changelog - Azure DevOps demo
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/)
and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]
- This is a brand new releases with:

## [0.0.2] - 2023-11-09
### Added
- I want to have a compare link

## [0.0.1] - 2023-11-09
### Added
- This is just a test changelog

[Unreleased]: https://dev.azure.com/myorg/myproject/_git/myrepo/branchCompare?baseVersion=GTv0.0.2&targetVersion=GBmaster
[0.0.2]: https://dev.azure.com/myorg/myproject/_git/myrepo/branchCompare?baseVersion=GTv0.0.1&targetVersion=GTv0.0.2
[0.0.1]: https://dev.azure.com/myorg/myproject/_git/myrepo?version=GTv0.0.1

---

This is a footer
22 changes: 22 additions & 0 deletions test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import getSettingsForURL from "../src/settings.ts";

const file = new URL("./changelog.custom.type.md", import.meta.url).pathname;
const fileGitlab = new URL("./changelog.gitlab.md", import.meta.url).pathname;
const fileAzdo = new URL("./changelog.azdo.md", import.meta.url).pathname;
const changelogContent = Deno.readTextFileSync(file);
const changelogContentGitlab = Deno.readTextFileSync(fileGitlab);
const changelogContentAzdo = Deno.readTextFileSync(fileAzdo);

Deno.test("parser testing", function () {
// is unable to parse changelog with unknown types
Expand Down Expand Up @@ -37,3 +39,23 @@ Deno.test("parser testing gitlab", function () {

assertEquals(changelog.toString().trim(), changelogContentGitlab.trim());
});

Deno.test("parser testing Azure DevOps", function () {
// parses a changelog with Azure DevOps links
const changelog = parser(changelogContentAzdo, );

// get settings from url
assert(changelog.url, "URL is not defined");

if(changelog.url) {
const settings = getSettingsForURL(changelog.url);
assert(settings)

if (settings) {
changelog.head = settings.head;
changelog.tagLinkBuilder = settings.tagLink;
}
}

assertEquals(changelog.toString().trim(), changelogContentAzdo.trim());
});

0 comments on commit 2e8e341

Please sign in to comment.