|
| 1 | +import { equal, match } from 'node:assert/strict'; |
| 2 | +import { execPath } from 'node:process'; |
| 3 | +import { describe, it } from 'node:test'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +import { spawnPromisified } from '../../utils/src/spawn-promisified.ts'; |
| 7 | + |
| 8 | +import { SUPPORTED_PREFIXES } from './pr-prefixes.ts'; |
| 9 | + |
| 10 | +describe('Pull Request checks', { concurrency: true }, async () => { |
| 11 | + const encoding = 'utf8'; |
| 12 | + const prTestPath = fileURLToPath(import.meta.resolve('./pr-title.ts')); |
| 13 | + |
| 14 | + for (const prefix of SUPPORTED_PREFIXES) { |
| 15 | + describe(prefix, () => { |
| 16 | + it('should pass when valid', async () => { |
| 17 | + const { code, stderr } = await spawnPromisified( |
| 18 | + execPath, |
| 19 | + [prTestPath], |
| 20 | + { |
| 21 | + encoding, |
| 22 | + env: { PR_TITLE: `${prefix}(DEP0000): update …` }, |
| 23 | + }, |
| 24 | + ); |
| 25 | + |
| 26 | + equal(stderr, ''); |
| 27 | + equal(code, 0); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should fail when missing scope', async () => { |
| 31 | + const { code, stderr } = await spawnPromisified( |
| 32 | + execPath, |
| 33 | + [prTestPath], |
| 34 | + { |
| 35 | + encoding, |
| 36 | + env: { PR_TITLE: `${prefix}: update …` }, |
| 37 | + }, |
| 38 | + ); |
| 39 | + |
| 40 | + match(stderr, /AssertionError/); |
| 41 | + match(stderr, new RegExp(prefix)); |
| 42 | + match(stderr, /pull request title/i); |
| 43 | + equal(code, 1); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should fail scope is misformatted', async () => { |
| 47 | + const { code, stderr } = await spawnPromisified( |
| 48 | + execPath, |
| 49 | + [prTestPath], |
| 50 | + { |
| 51 | + encoding, |
| 52 | + env: { PR_TITLE: `${prefix}(DEP0000) update …` }, |
| 53 | + }, |
| 54 | + ); |
| 55 | + |
| 56 | + match(stderr, /AssertionError/); |
| 57 | + match(stderr, new RegExp(prefix)); |
| 58 | + match(stderr, /pull request title/i); |
| 59 | + equal(code, 1); |
| 60 | + }); |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + describe('unsupported prefix', () => { |
| 65 | + it('should fail', async () => { |
| 66 | + const prefix = 'foo'; |
| 67 | + const { code, stderr } = await spawnPromisified(execPath, [prTestPath], { |
| 68 | + encoding, |
| 69 | + env: { PR_TITLE: `${prefix}(DEP0000): update …` }, |
| 70 | + }); |
| 71 | + |
| 72 | + match(stderr, /AssertionError/); |
| 73 | + match(stderr, new RegExp(prefix)); |
| 74 | + match(stderr, /pull request title/i); |
| 75 | + for (const p of SUPPORTED_PREFIXES) match(stderr, new RegExp(p)); |
| 76 | + equal(code, 1); |
| 77 | + }); |
| 78 | + }) |
| 79 | +}); |
0 commit comments