Skip to content

Commit d77e8aa

Browse files
committed
test: improve links coverage
1 parent 7d3e092 commit d77e8aa

1 file changed

Lines changed: 69 additions & 1 deletion

File tree

test/unit/links.test.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { describe, it } from 'node:test';
22
import assert from 'node:assert';
33

4-
import { LinkParser, parsePRFromURL } from '../../lib/links.js';
4+
import {
5+
getMachineUrl,
6+
getPrURL,
7+
LinkParser,
8+
parsePrURL,
9+
parsePRFromURL
10+
} from '../../lib/links.js';
511

612
import * as fixtures from '../fixtures/index.js';
713

@@ -46,6 +52,38 @@ describe('LinkParser', () => {
4652
}
4753
});
4854

55+
it('should parse an alternate PR URL', () => {
56+
const url = 'https://github.com/nodejs/node/pull/12345';
57+
const parser = new LinkParser(
58+
'nodejs',
59+
'node',
60+
`PR-URL: <a href="${url}">${url}</a>`
61+
);
62+
63+
assert.deepStrictEqual(parser.getAltPrUrl(), [url]);
64+
});
65+
66+
it('should ignore references without matching links', () => {
67+
const parser = new LinkParser(
68+
'nodejs',
69+
'node',
70+
'Fixes: <a>#1</a>\nRefs: #2\nPR-URL: https://example.com/pull/3'
71+
);
72+
73+
assert.deepStrictEqual(parser.getFixes(), []);
74+
assert.deepStrictEqual(parser.getRefs(), []);
75+
assert.deepStrictEqual(parser.getAltPrUrl(), []);
76+
});
77+
78+
it('should ignore malformed array entries', () => {
79+
const parser = new LinkParser('nodejs', 'node', '');
80+
81+
assert.deepStrictEqual(parser.getAltPrUrl(), []);
82+
assert.deepStrictEqual(parser.getFixesUrlsFromArray(['invalid']), []);
83+
assert.deepStrictEqual(parser.getRefsUrlsFromArray(['invalid']), []);
84+
assert.deepStrictEqual(parser.getPRUrlsFromArray(['invalid']), []);
85+
});
86+
4987
it('should parse PR URL', () => {
5088
const tests = [{
5189
input: 'https://github.com/nodejs/node/pull/15148',
@@ -92,3 +130,33 @@ describe('LinkParser', () => {
92130
}
93131
});
94132
});
133+
134+
describe('link formatting', () => {
135+
it('should format a pull request URL', () => {
136+
assert.strictEqual(
137+
getPrURL({ owner: 'nodejs', repo: 'node', prid: 12345 }),
138+
'https://github.com/nodejs/node/pull/12345'
139+
);
140+
});
141+
142+
it('should format a machine link', () => {
143+
assert.strictEqual(
144+
getMachineUrl({ hostname: 'test-host', url: 'https://ci.example.test' }),
145+
'[test-host](https://ci.example.test)'
146+
);
147+
});
148+
});
149+
150+
describe('parsePrURL', () => {
151+
it('should parse a PR-URL trailer', () => {
152+
assert.deepStrictEqual(
153+
parsePrURL('PR-URL: https://github.com/nodejs/node/pull/12345'),
154+
{ owner: 'nodejs', repo: 'node', prid: 12345 }
155+
);
156+
});
157+
158+
it('should return undefined for invalid input', () => {
159+
assert.strictEqual(parsePrURL(12345), undefined);
160+
assert.strictEqual(parsePrURL('not a PR-URL trailer'), undefined);
161+
});
162+
});

0 commit comments

Comments
 (0)