|
1 | 1 | import { describe, it } from 'node:test'; |
2 | 2 | import assert from 'node:assert'; |
3 | 3 |
|
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'; |
5 | 11 |
|
6 | 12 | import * as fixtures from '../fixtures/index.js'; |
7 | 13 |
|
@@ -46,6 +52,38 @@ describe('LinkParser', () => { |
46 | 52 | } |
47 | 53 | }); |
48 | 54 |
|
| 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 | + |
49 | 87 | it('should parse PR URL', () => { |
50 | 88 | const tests = [{ |
51 | 89 | input: 'https://github.com/nodejs/node/pull/15148', |
@@ -92,3 +130,33 @@ describe('LinkParser', () => { |
92 | 130 | } |
93 | 131 | }); |
94 | 132 | }); |
| 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