|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const validatePRBody = require('../validatePRBody'); |
| 13 | + |
| 14 | +function prBody(changelog) { |
| 15 | + return `## Summary |
| 16 | +
|
| 17 | +Explain why the change is needed. |
| 18 | +
|
| 19 | +${changelog} |
| 20 | +
|
| 21 | +## Test Plan |
| 22 | +
|
| 23 | +Run the unit tests.`; |
| 24 | +} |
| 25 | + |
| 26 | +describe('validatePRBody changelog headings', () => { |
| 27 | + it.each(['## Changelog', '## Changelog:'])( |
| 28 | + 'accepts %s with a tagged entry', |
| 29 | + heading => { |
| 30 | + expect( |
| 31 | + validatePRBody(prBody(`${heading}\n\n[GENERAL] [FIXED] - Fix a bug`)), |
| 32 | + ).toEqual({message: '', status: 'PASS'}); |
| 33 | + }, |
| 34 | + ); |
| 35 | + |
| 36 | + it('accepts a heading without a colon with CRLF line endings', () => { |
| 37 | + const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI'); |
| 38 | + expect(validatePRBody(body.replace(/\n/g, '\r\n'))).toEqual({ |
| 39 | + message: '', |
| 40 | + status: 'PASS', |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it('accepts consecutive internal changelogs consistently', () => { |
| 45 | + const body = prBody('## Changelog\n\n[INTERNAL] [FIXED] - Fix CI'); |
| 46 | + expect(validatePRBody(body).status).toBe('PASS'); |
| 47 | + expect(validatePRBody(body).status).toBe('PASS'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('still requires a tagged entry', () => { |
| 51 | + expect(validatePRBody(prBody('## Changelog\n\nNo tags')).message).toContain( |
| 52 | + 'Invalid Changelog Format', |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('does not treat an unmarked Changelog line as a heading', () => { |
| 57 | + expect( |
| 58 | + validatePRBody(prBody('Changelog\n\n[GENERAL] [FIXED] - Fix a bug')) |
| 59 | + .message, |
| 60 | + ).toContain('Missing Changelog'); |
| 61 | + }); |
| 62 | +}); |
0 commit comments