|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import { test } from 'node:test' |
| 3 | +import type { PackageRelease } from './changes.ts' |
| 4 | +import { generatePrBody } from './release-pr.ts' |
| 5 | + |
| 6 | +function makeRelease({ |
| 7 | + packageDirName, |
| 8 | + packageName, |
| 9 | + nextVersion, |
| 10 | +}: { |
| 11 | + packageDirName: string |
| 12 | + packageName: string |
| 13 | + nextVersion: string |
| 14 | +}): PackageRelease { |
| 15 | + return { |
| 16 | + packageDirName, |
| 17 | + packageName, |
| 18 | + currentVersion: '1.0.0', |
| 19 | + nextVersion, |
| 20 | + bump: 'patch', |
| 21 | + changes: [{ file: 'patch.test-change.md', bump: 'patch', content: 'Test change' }], |
| 22 | + dependencyBumps: [], |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +test('generatePrBody puts remix first and sorts remaining packages alphabetically', () => { |
| 27 | + let body = generatePrBody([ |
| 28 | + makeRelease({ |
| 29 | + packageDirName: 'zeta', |
| 30 | + packageName: '@remix-run/zeta', |
| 31 | + nextVersion: '1.0.1', |
| 32 | + }), |
| 33 | + makeRelease({ |
| 34 | + packageDirName: 'remix', |
| 35 | + packageName: 'remix', |
| 36 | + nextVersion: '3.0.0', |
| 37 | + }), |
| 38 | + makeRelease({ |
| 39 | + packageDirName: 'beta', |
| 40 | + packageName: '@remix-run/beta', |
| 41 | + nextVersion: '1.0.1', |
| 42 | + }), |
| 43 | + makeRelease({ |
| 44 | + packageDirName: 'alpha', |
| 45 | + packageName: '@remix-run/alpha', |
| 46 | + nextVersion: '1.0.1', |
| 47 | + }), |
| 48 | + ]) |
| 49 | + |
| 50 | + let remixTableIndex = body.indexOf('| remix |') |
| 51 | + let alphaTableIndex = body.indexOf('| @remix-run/alpha |') |
| 52 | + let betaTableIndex = body.indexOf('| @remix-run/beta |') |
| 53 | + let zetaTableIndex = body.indexOf('| @remix-run/zeta |') |
| 54 | + |
| 55 | + assert.notEqual(remixTableIndex, -1) |
| 56 | + assert.notEqual(alphaTableIndex, -1) |
| 57 | + assert.notEqual(betaTableIndex, -1) |
| 58 | + assert.notEqual(zetaTableIndex, -1) |
| 59 | + assert.ok(remixTableIndex < alphaTableIndex) |
| 60 | + assert.ok(alphaTableIndex < betaTableIndex) |
| 61 | + assert.ok(betaTableIndex < zetaTableIndex) |
| 62 | + |
| 63 | + let remixChangelogIndex = body.indexOf('## remix v3.0.0') |
| 64 | + let alphaChangelogIndex = body.indexOf('## @remix-run/alpha v1.0.1') |
| 65 | + let betaChangelogIndex = body.indexOf('## @remix-run/beta v1.0.1') |
| 66 | + let zetaChangelogIndex = body.indexOf('## @remix-run/zeta v1.0.1') |
| 67 | + |
| 68 | + assert.notEqual(remixChangelogIndex, -1) |
| 69 | + assert.notEqual(alphaChangelogIndex, -1) |
| 70 | + assert.notEqual(betaChangelogIndex, -1) |
| 71 | + assert.notEqual(zetaChangelogIndex, -1) |
| 72 | + assert.ok(remixChangelogIndex < alphaChangelogIndex) |
| 73 | + assert.ok(alphaChangelogIndex < betaChangelogIndex) |
| 74 | + assert.ok(betaChangelogIndex < zetaChangelogIndex) |
| 75 | +}) |
0 commit comments