|
| 1 | +import parse from '@commitlint/parse'; |
| 2 | +import {trailerExists} from './trailer-exists'; |
| 3 | + |
| 4 | +const messages = { |
| 5 | + empty: 'test:\n', |
| 6 | + with: `test: subject\n\nbody\n\nfooter\n\nSigned-off-by:\n\n`, |
| 7 | + without: `test: subject\n\nbody\n\nfooter\n\n`, |
| 8 | + inSubject: `test: subject Signed-off-by:\n\nbody\n\nfooter\n\n`, |
| 9 | + inBody: `test: subject\n\nbody Signed-off-by:\n\nfooter\n\n`, |
| 10 | + withSignoffAndNoise: `test: subject |
| 11 | +
|
| 12 | +message body |
| 13 | +
|
| 14 | +Arbitrary-trailer: |
| 15 | +Signed-off-by: |
| 16 | +Another-arbitrary-trailer: |
| 17 | +
|
| 18 | +# Please enter the commit message for your changes. Lines starting |
| 19 | +# with '#' will be ignored, and an empty message aborts the commit. |
| 20 | +`, |
| 21 | +}; |
| 22 | + |
| 23 | +const parsed = { |
| 24 | + empty: parse(messages.empty), |
| 25 | + with: parse(messages.with), |
| 26 | + without: parse(messages.without), |
| 27 | + inSubject: parse(messages.inSubject), |
| 28 | + inBody: parse(messages.inBody), |
| 29 | + withSignoffAndNoise: parse(messages.withSignoffAndNoise), |
| 30 | +}; |
| 31 | + |
| 32 | +test('empty against "always trailer-exists" should fail', async () => { |
| 33 | + const [actual] = trailerExists( |
| 34 | + await parsed.empty, |
| 35 | + 'always', |
| 36 | + 'Signed-off-by:' |
| 37 | + ); |
| 38 | + |
| 39 | + const expected = false; |
| 40 | + expect(actual).toEqual(expected); |
| 41 | +}); |
| 42 | + |
| 43 | +test('empty against "never trailer-exists" should succeed', async () => { |
| 44 | + const [actual] = trailerExists(await parsed.empty, 'never', 'Signed-off-by:'); |
| 45 | + const expected = true; |
| 46 | + expect(actual).toEqual(expected); |
| 47 | +}); |
| 48 | + |
| 49 | +test('with against "always trailer-exists" should succeed', async () => { |
| 50 | + const [actual] = trailerExists(await parsed.with, 'always', 'Signed-off-by:'); |
| 51 | + const expected = true; |
| 52 | + expect(actual).toEqual(expected); |
| 53 | +}); |
| 54 | + |
| 55 | +test('with against "never trailer-exists" should fail', async () => { |
| 56 | + const [actual] = trailerExists(await parsed.with, 'never', 'Signed-off-by:'); |
| 57 | + const expected = false; |
| 58 | + expect(actual).toEqual(expected); |
| 59 | +}); |
| 60 | + |
| 61 | +test('without against "always trailer-exists" should fail', async () => { |
| 62 | + const [actual] = trailerExists( |
| 63 | + await parsed.without, |
| 64 | + 'always', |
| 65 | + 'Signed-off-by:' |
| 66 | + ); |
| 67 | + |
| 68 | + const expected = false; |
| 69 | + expect(actual).toEqual(expected); |
| 70 | +}); |
| 71 | + |
| 72 | +test('without against "never trailer-exists" should succeed', async () => { |
| 73 | + const [actual] = trailerExists( |
| 74 | + await parsed.without, |
| 75 | + 'never', |
| 76 | + 'Signed-off-by:' |
| 77 | + ); |
| 78 | + |
| 79 | + const expected = true; |
| 80 | + expect(actual).toEqual(expected); |
| 81 | +}); |
| 82 | + |
| 83 | +test('comments and other trailers should be ignored', async () => { |
| 84 | + const [actual] = trailerExists( |
| 85 | + await parsed.withSignoffAndNoise, |
| 86 | + 'always', |
| 87 | + 'Signed-off-by:' |
| 88 | + ); |
| 89 | + |
| 90 | + const expected = true; |
| 91 | + expect(actual).toEqual(expected); |
| 92 | +}); |
| 93 | + |
| 94 | +test('inSubject against "always trailer-exists" should fail', async () => { |
| 95 | + const [actual] = trailerExists( |
| 96 | + await parsed.inSubject, |
| 97 | + 'always', |
| 98 | + 'Signed-off-by:' |
| 99 | + ); |
| 100 | + |
| 101 | + const expected = false; |
| 102 | + expect(actual).toEqual(expected); |
| 103 | +}); |
| 104 | + |
| 105 | +test('inSubject against "never trailer-exists" should succeed', async () => { |
| 106 | + const [actual] = trailerExists( |
| 107 | + await parsed.inSubject, |
| 108 | + 'never', |
| 109 | + 'Signed-off-by:' |
| 110 | + ); |
| 111 | + |
| 112 | + const expected = true; |
| 113 | + expect(actual).toEqual(expected); |
| 114 | +}); |
| 115 | + |
| 116 | +test('inBody against "always trailer-exists" should fail', async () => { |
| 117 | + const [actual] = trailerExists( |
| 118 | + await parsed.inBody, |
| 119 | + 'always', |
| 120 | + 'Signed-off-by:' |
| 121 | + ); |
| 122 | + |
| 123 | + const expected = false; |
| 124 | + expect(actual).toEqual(expected); |
| 125 | +}); |
| 126 | + |
| 127 | +test('inBody against "never trailer-exists" should succeed', async () => { |
| 128 | + const [actual] = trailerExists( |
| 129 | + await parsed.inBody, |
| 130 | + 'never', |
| 131 | + 'Signed-off-by:' |
| 132 | + ); |
| 133 | + |
| 134 | + const expected = true; |
| 135 | + expect(actual).toEqual(expected); |
| 136 | +}); |
0 commit comments