@mui/internal-code-infra 0.0.4-canary.9 → 0.0.4-canary.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +19 -8
  3. package/build/babel-config.d.mts +5 -1
  4. package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
  5. package/build/brokenLinksChecker/index.d.mts +45 -2
  6. package/build/changelog/types.d.ts +3 -1
  7. package/build/cli/cmdArgosPush.d.mts +2 -2
  8. package/build/cli/cmdBuild.d.mts +3 -2
  9. package/build/cli/cmdCopyFiles.d.mts +2 -2
  10. package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
  11. package/build/cli/cmdGenerateChangelog.d.mts +2 -2
  12. package/build/cli/cmdGithubAuth.d.mts +2 -2
  13. package/build/cli/cmdListWorkspaces.d.mts +6 -4
  14. package/build/cli/cmdNetlifyIgnore.d.mts +3 -2
  15. package/build/cli/cmdPublish.d.mts +4 -2
  16. package/build/cli/cmdPublishCanary.d.mts +3 -3
  17. package/build/cli/cmdPublishNewPackage.d.mts +4 -2
  18. package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
  19. package/build/cli/cmdVale.d.mts +46 -0
  20. package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
  21. package/build/eslint/baseConfig.d.mts +3 -1
  22. package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
  23. package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
  24. package/build/eslint/mui/rules/no-floating-cleanup.d.mts +5 -0
  25. package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
  26. package/build/eslint/mui/rules/no-presentation-role.d.mts +5 -0
  27. package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
  28. package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
  29. package/build/remark/config.d.mts +43 -0
  30. package/build/remark/createLintTester.d.mts +10 -0
  31. package/build/remark/firstBlockHeading.d.mts +4 -0
  32. package/build/remark/gitDiff.d.mts +2 -0
  33. package/build/remark/noSpaceInLinks.d.mts +2 -0
  34. package/build/remark/straightQuotes.d.mts +2 -0
  35. package/build/remark/tableAlignment.d.mts +2 -0
  36. package/build/remark/terminalLanguage.d.mts +2 -0
  37. package/build/utils/babel.d.mts +1 -1
  38. package/build/utils/build.d.mts +56 -37
  39. package/build/utils/git.d.mts +7 -0
  40. package/build/utils/github.d.mts +1 -1
  41. package/build/utils/pnpm.d.mts +81 -2
  42. package/build/utils/testUtils.d.mts +7 -0
  43. package/build/utils/typescript.d.mts +6 -16
  44. package/package.json +74 -50
  45. package/src/babel-config.mjs +3 -1
  46. package/src/brokenLinksChecker/crawlWorker.mjs +240 -0
  47. package/src/brokenLinksChecker/index.mjs +263 -188
  48. package/src/changelog/fetchChangelogs.mjs +8 -2
  49. package/src/changelog/renderChangelog.mjs +1 -1
  50. package/src/changelog/types.ts +3 -1
  51. package/src/cli/cmdBuild.mjs +51 -85
  52. package/src/cli/cmdListWorkspaces.mjs +12 -27
  53. package/src/cli/cmdNetlifyIgnore.mjs +34 -93
  54. package/src/cli/cmdPublish.mjs +95 -20
  55. package/src/cli/cmdPublishCanary.mjs +128 -132
  56. package/src/cli/cmdPublishNewPackage.mjs +27 -6
  57. package/src/cli/cmdSetVersionOverrides.mjs +8 -9
  58. package/src/cli/cmdVale.mjs +513 -0
  59. package/src/cli/index.mjs +2 -0
  60. package/src/cli/packageJson.d.ts +1 -1
  61. package/src/eslint/baseConfig.mjs +51 -19
  62. package/src/eslint/docsConfig.mjs +2 -1
  63. package/src/eslint/mui/config.mjs +24 -4
  64. package/src/eslint/mui/index.mjs +6 -0
  65. package/src/eslint/mui/rules/no-floating-cleanup.mjs +187 -0
  66. package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
  67. package/src/eslint/mui/rules/no-presentation-role.mjs +60 -0
  68. package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
  69. package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
  70. package/src/estree-typescript.d.ts +1 -1
  71. package/src/remark/config.mjs +157 -0
  72. package/src/remark/createLintTester.mjs +19 -0
  73. package/src/remark/firstBlockHeading.mjs +87 -0
  74. package/src/remark/gitDiff.mjs +43 -0
  75. package/src/remark/noSpaceInLinks.mjs +42 -0
  76. package/src/remark/straightQuotes.mjs +31 -0
  77. package/src/remark/tableAlignment.mjs +23 -0
  78. package/src/remark/terminalLanguage.mjs +19 -0
  79. package/src/untyped-plugins.d.ts +11 -11
  80. package/src/utils/build.mjs +604 -270
  81. package/src/utils/git.mjs +27 -7
  82. package/src/utils/pnpm.mjs +277 -10
  83. package/src/utils/testUtils.mjs +18 -0
  84. package/src/utils/typescript.mjs +23 -42
  85. package/vale/.vale.ini +1 -0
  86. package/vale/styles/MUI/CorrectReferenceAllCases.yml +42 -0
  87. package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
  88. package/vale/styles/MUI/GoogleLatin.yml +11 -0
  89. package/vale/styles/MUI/MuiBrandName.yml +22 -0
  90. package/vale/styles/MUI/NoBritish.yml +112 -0
  91. package/vale/styles/MUI/NoCompanyName.yml +17 -0
  92. package/build/markdownlint/duplicate-h1.d.mts +0 -56
  93. package/build/markdownlint/git-diff.d.mts +0 -11
  94. package/build/markdownlint/index.d.mts +0 -52
  95. package/build/markdownlint/straight-quotes.d.mts +0 -11
  96. package/build/markdownlint/table-alignment.d.mts +0 -11
  97. package/build/markdownlint/terminal-language.d.mts +0 -11
  98. package/src/brokenLinksChecker/__fixtures__/static-site/broken-links.html +0 -20
  99. package/src/brokenLinksChecker/__fixtures__/static-site/broken-targets.html +0 -22
  100. package/src/brokenLinksChecker/__fixtures__/static-site/example.md +0 -20
  101. package/src/brokenLinksChecker/__fixtures__/static-site/external-links.html +0 -21
  102. package/src/brokenLinksChecker/__fixtures__/static-site/ignored-page.html +0 -17
  103. package/src/brokenLinksChecker/__fixtures__/static-site/index.html +0 -28
  104. package/src/brokenLinksChecker/__fixtures__/static-site/known-targets.json +0 -5
  105. package/src/brokenLinksChecker/__fixtures__/static-site/nested/page.html +0 -21
  106. package/src/brokenLinksChecker/__fixtures__/static-site/orphaned-page.html +0 -20
  107. package/src/brokenLinksChecker/__fixtures__/static-site/page-with-api-links.html +0 -20
  108. package/src/brokenLinksChecker/__fixtures__/static-site/page-with-custom-targets.html +0 -24
  109. package/src/brokenLinksChecker/__fixtures__/static-site/page-with-ignored-content.html +0 -28
  110. package/src/brokenLinksChecker/__fixtures__/static-site/page-with-known-target-links.html +0 -19
  111. package/src/brokenLinksChecker/__fixtures__/static-site/unclosed-tags.html +0 -1
  112. package/src/brokenLinksChecker/__fixtures__/static-site/valid.html +0 -20
  113. package/src/brokenLinksChecker/__fixtures__/static-site/with-anchors.html +0 -31
  114. package/src/brokenLinksChecker/index.test.ts +0 -261
  115. package/src/changelog/categorizeCommits.test.ts +0 -319
  116. package/src/changelog/filterCommits.test.ts +0 -363
  117. package/src/changelog/parseCommitLabels.test.ts +0 -509
  118. package/src/changelog/renderChangelog.test.ts +0 -378
  119. package/src/changelog/sortSections.test.ts +0 -199
  120. package/src/eslint/mui/rules/add-undef-to-optional.test.mjs +0 -361
  121. package/src/eslint/mui/rules/consistent-production-guard.test.mjs +0 -162
  122. package/src/eslint/mui/rules/disallow-active-elements-as-key-event-target.test.mjs +0 -66
  123. package/src/eslint/mui/rules/disallow-react-api-in-server-components.test.mjs +0 -305
  124. package/src/eslint/mui/rules/docgen-ignore-before-comment.test.mjs +0 -52
  125. package/src/eslint/mui/rules/flatten-parentheses.test.mjs +0 -245
  126. package/src/eslint/mui/rules/mui-name-matches-component-name.test.mjs +0 -247
  127. package/src/eslint/mui/rules/no-empty-box.test.mjs +0 -40
  128. package/src/eslint/mui/rules/no-styled-box.test.mjs +0 -73
  129. package/src/eslint/mui/rules/require-dev-wrapper.test.mjs +0 -265
  130. package/src/eslint/mui/rules/rules-of-use-theme-variants.test.mjs +0 -149
  131. package/src/eslint/mui/rules/straight-quotes.test.mjs +0 -67
  132. package/src/markdownlint/duplicate-h1.mjs +0 -69
  133. package/src/markdownlint/git-diff.mjs +0 -31
  134. package/src/markdownlint/index.mjs +0 -62
  135. package/src/markdownlint/straight-quotes.mjs +0 -26
  136. package/src/markdownlint/table-alignment.mjs +0 -42
  137. package/src/markdownlint/terminal-language.mjs +0 -19
  138. package/src/utils/build.test.mjs +0 -705
  139. package/src/utils/template.test.mjs +0 -133
  140. package/src/utils/typescript.test.mjs +0 -380
@@ -1,378 +0,0 @@
1
- /* eslint-disable testing-library/render-result-naming-convention */
2
- import { describe, expect, it } from 'vitest';
3
- // eslint-disable-next-line import/extensions
4
- import { renderChangelog } from './renderChangelog.mjs';
5
- import type { ChangelogSection, CategorizedCommit, ChangelogConfig } from './types';
6
-
7
- function createCommit(
8
- prNumber: number,
9
- message: string,
10
- mergedAt?: string | null,
11
- author?: string,
12
- ): CategorizedCommit {
13
- return {
14
- sha: `sha-${prNumber}`,
15
- message,
16
- labels: [],
17
- prNumber,
18
- html_url: `https://github.com/mui/mui-x/pull/${prNumber}`,
19
- author: author ? { login: author, association: 'team' } : null,
20
- createdAt: null,
21
- mergedAt: mergedAt || null,
22
- parsed: {
23
- scopes: [],
24
- components: [],
25
- flags: [],
26
- },
27
- };
28
- }
29
-
30
- function createSection(commits: CategorizedCommit[]): ChangelogSection {
31
- return {
32
- key: 'features',
33
- level: 3,
34
- commits,
35
- pkgInfo: null,
36
- };
37
- }
38
-
39
- const baseConfig: ChangelogConfig = {
40
- format: {
41
- version: 'v{{version}}',
42
- dateFormat: '_MMM DD, YYYY_',
43
- changelogMessage: '{{flagPrefix}}{{message}} (#{{prNumber}})',
44
- },
45
- categorization: {
46
- strategy: 'component',
47
- sections: {
48
- fallbackSection: 'Other',
49
- titles: {},
50
- },
51
- labels: {
52
- plan: {
53
- values: [],
54
- },
55
- },
56
- },
57
- };
58
-
59
- describe('renderChangelog - commit sorting by tags', () => {
60
- describe('sorting commits with tags', () => {
61
- it('should group commits by their starting tags', () => {
62
- const commits = [
63
- createCommit(
64
- 1,
65
- '[internal] Remove local Claude settings from the repo',
66
- '2025-01-10T00:00:00Z',
67
- 'cherniavskii',
68
- ),
69
- createCommit(2, '[code-infra] Update codeowners', '2025-01-01T00:00:00Z', 'JCQuintas'),
70
- createCommit(
71
- 3,
72
- '[code-infra] Fix `material-ui/disallow-react-api-in-server-components`',
73
- '2025-01-05T00:00:00Z',
74
- 'JCQuintas',
75
- ),
76
- createCommit(4, '[code-infra] Prepare for v9', '2025-01-02T00:00:00Z', 'JCQuintas'),
77
- createCommit(5, '[docs-infra] Fix two broken links', '2025-01-08T00:00:00Z', 'Janpot'),
78
- createCommit(
79
- 6,
80
- '[docs-infra] Fix missing slots section on API page',
81
- '2025-01-09T00:00:00Z',
82
- 'Janpot',
83
- ),
84
- ];
85
-
86
- const section = createSection(commits);
87
- const result = renderChangelog(
88
- [section],
89
- baseConfig,
90
- {
91
- version: '1.0.0',
92
- lastRelease: 'v0.1.0',
93
- release: 'v1.0.0',
94
- date: new Date('2025-01-15'),
95
- },
96
- { team: [], community: [], all: [] },
97
- );
98
-
99
- // Extract the commit messages from the rendered output
100
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
101
-
102
- // All code-infra commits should come first (sorted by tag), then docs-infra, then internal
103
- expect(lines[0]).toContain('Update codeowners');
104
- expect(lines[1]).toContain('Prepare for v9');
105
- expect(lines[2]).toContain('Fix `material-ui/disallow-react-api-in-server-components`');
106
- expect(lines[3]).toContain('Fix two broken links');
107
- expect(lines[4]).toContain('Fix missing slots section on API page');
108
- expect(lines[5]).toContain('Remove local Claude settings from the repo');
109
- });
110
-
111
- it('should sort commits with same tags by merge time', () => {
112
- const commits = [
113
- createCommit(1, '[code-infra] Commit 1', '2025-01-10T00:00:00Z'),
114
- createCommit(2, '[code-infra] Commit 2', '2025-01-05T00:00:00Z'),
115
- createCommit(3, '[code-infra] Commit 3', '2025-01-08T00:00:00Z'),
116
- ];
117
-
118
- const section = createSection(commits);
119
- const result = renderChangelog(
120
- [section],
121
- baseConfig,
122
- {
123
- version: '1.0.0',
124
- lastRelease: 'v0.1.0',
125
- release: 'v1.0.0',
126
- date: new Date('2025-01-15'),
127
- },
128
- { team: [], community: [], all: [] },
129
- );
130
-
131
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
132
-
133
- expect(lines[0]).toContain('Commit 2');
134
- expect(lines[1]).toContain('Commit 3');
135
- expect(lines[2]).toContain('Commit 1');
136
- });
137
-
138
- it('should handle commits with multiple tags', () => {
139
- const commits = [
140
- createCommit(1, '[code-infra] Update codeowners', '2025-01-01T00:00:00Z', 'JCQuintas'),
141
- createCommit(
142
- 2,
143
- '[code-infra][docs] V9 charts migration doc kickoff',
144
- '2025-01-11T00:00:00Z',
145
- 'JCQuintas',
146
- ),
147
- createCommit(3, '[docs-infra] Fix two broken links', '2025-01-08T00:00:00Z', 'Janpot'),
148
- ];
149
-
150
- const section = createSection(commits);
151
- const result = renderChangelog(
152
- [section],
153
- baseConfig,
154
- {
155
- version: '1.0.0',
156
- lastRelease: 'v0.1.0',
157
- release: 'v1.0.0',
158
- date: new Date('2025-01-15'),
159
- },
160
- { team: [], community: [], all: [] },
161
- );
162
-
163
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
164
-
165
- // [code-infra] should come before [code-infra][docs]
166
- expect(lines[0]).toContain('Update codeowners');
167
- expect(lines[1]).toContain('V9 charts migration doc kickoff');
168
- expect(lines[2]).toContain('Fix two broken links');
169
- });
170
-
171
- it('should handle commits without tags', () => {
172
- const commits = [
173
- createCommit(1, '[code-infra] Update codeowners', '2025-01-05T00:00:00Z'),
174
- createCommit(2, 'No tag commit', '2025-01-01T00:00:00Z'),
175
- createCommit(3, 'Another no tag commit', '2025-01-02T00:00:00Z'),
176
- ];
177
-
178
- const section = createSection(commits);
179
- const result = renderChangelog(
180
- [section],
181
- baseConfig,
182
- {
183
- version: '1.0.0',
184
- lastRelease: 'v0.1.0',
185
- release: 'v1.0.0',
186
- date: new Date('2025-01-15'),
187
- },
188
- { team: [], community: [], all: [] },
189
- );
190
-
191
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
192
-
193
- // Tagged commits should come before untagged
194
- expect(lines[0]).toContain('Update codeowners');
195
- expect(lines[1]).toContain('No tag commit');
196
- expect(lines[2]).toContain('Another no tag commit');
197
- });
198
-
199
- it('should match the user-provided example output order', () => {
200
- const commits = [
201
- createCommit(
202
- 20853,
203
- '[internal] Remove local Claude settings from the repo',
204
- '2025-01-01T00:00:00Z',
205
- 'cherniavskii',
206
- ),
207
- createCommit(20886, '[code-infra] Update codeowners', '2025-01-02T00:00:00Z', 'JCQuintas'),
208
- createCommit(
209
- 20909,
210
- '[code-infra] Fix `material-ui/disallow-react-api-in-server-components`',
211
- '2025-01-03T00:00:00Z',
212
- 'JCQuintas',
213
- ),
214
- createCommit(20860, '[code-infra] Prepare for v9', '2025-01-04T00:00:00Z', 'JCQuintas'),
215
- createCommit(20914, '[docs-infra] Fix two broken links', '2025-01-05T00:00:00Z', 'Janpot'),
216
- createCommit(
217
- 20915,
218
- '[docs-infra] Fix missing slots section on API page',
219
- '2025-01-06T00:00:00Z',
220
- 'Janpot',
221
- ),
222
- createCommit(
223
- 20922,
224
- '[code-infra] Github action to sync title and label',
225
- '2025-01-07T00:00:00Z',
226
- 'brijeshb42',
227
- ),
228
- createCommit(
229
- 20934,
230
- '[code-infra] Fix the label comparison to use lower case',
231
- '2025-01-08T00:00:00Z',
232
- 'brijeshb42',
233
- ),
234
- createCommit(
235
- 20973,
236
- '[code-infra][docs] V9 charts migration doc kickoff',
237
- '2025-01-09T00:00:00Z',
238
- 'JCQuintas',
239
- ),
240
- createCommit(
241
- 20932,
242
- '[internal] Set up shared instructions for coding agents',
243
- '2025-01-10T00:00:00Z',
244
- 'cherniavskii',
245
- ),
246
- createCommit(20928, '[code-infra] V9 preparation', '2025-01-11T00:00:00Z', 'JCQuintas'),
247
- createCommit(
248
- 20977,
249
- '[code-infra] Fix `renameImports` codemod not preserving comments',
250
- '2025-01-12T00:00:00Z',
251
- 'JCQuintas',
252
- ),
253
- createCommit(
254
- 20982,
255
- '[code-infra] Ignore scheduler demo with random data',
256
- '2025-01-13T00:00:00Z',
257
- 'JCQuintas',
258
- ),
259
- ];
260
-
261
- const section = createSection(commits);
262
- const result = renderChangelog(
263
- [section],
264
- baseConfig,
265
- {
266
- version: '1.0.0',
267
- lastRelease: 'v0.1.0',
268
- release: 'v1.0.0',
269
- date: new Date('2025-01-15'),
270
- },
271
- { team: [], community: [], all: [] },
272
- );
273
-
274
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
275
-
276
- // Expected order: all [code-infra] commits sorted by merge time (chronological),
277
- // then [code-infra][docs] (which has code-infra as first tag, followed by docs),
278
- // then [docs-infra], then [internal]
279
- expect(lines[0]).toContain('20886'); // [code-infra] 2025-01-02
280
- expect(lines[1]).toContain('20909'); // [code-infra] 2025-01-03
281
- expect(lines[2]).toContain('20860'); // [code-infra] 2025-01-04
282
- expect(lines[3]).toContain('20922'); // [code-infra] 2025-01-07
283
- expect(lines[4]).toContain('20934'); // [code-infra] 2025-01-08
284
- expect(lines[5]).toContain('20928'); // [code-infra] 2025-01-11
285
- expect(lines[6]).toContain('20977'); // [code-infra] 2025-01-12
286
- expect(lines[7]).toContain('20982'); // [code-infra] 2025-01-13
287
- expect(lines[8]).toContain('20973'); // [code-infra][docs] 2025-01-09
288
- expect(lines[9]).toContain('20914'); // [docs-infra] 2025-01-05
289
- expect(lines[10]).toContain('20915'); // [docs-infra] 2025-01-06
290
- expect(lines[11]).toContain('20853'); // [internal] 2025-01-01
291
- expect(lines[12]).toContain('20932'); // [internal] 2025-01-10
292
- });
293
-
294
- it('should handle tags with spaces and hyphens', () => {
295
- const commits = [
296
- createCommit(1, '[my-scope] Commit 1', '2025-01-05T00:00:00Z'),
297
- createCommit(2, '[my scope] Commit 2', '2025-01-01T00:00:00Z'),
298
- createCommit(3, '[my-scope] Commit 3', '2025-01-02T00:00:00Z'),
299
- ];
300
-
301
- const section = createSection(commits);
302
- const result = renderChangelog(
303
- [section],
304
- baseConfig,
305
- {
306
- version: '1.0.0',
307
- lastRelease: 'v0.1.0',
308
- release: 'v1.0.0',
309
- date: new Date('2025-01-15'),
310
- },
311
- { team: [], community: [], all: [] },
312
- );
313
-
314
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
315
-
316
- // All commits with same tag should be together
317
- expect(lines[0]).toContain('Commit 2');
318
- expect(lines[1]).toContain('Commit 3');
319
- expect(lines[2]).toContain('Commit 1');
320
- });
321
-
322
- it('should handle case-insensitive tag matching', () => {
323
- const commits = [
324
- createCommit(1, '[CODE-INFRA] Uppercase tag', '2025-01-01T00:00:00Z'),
325
- createCommit(2, '[code-infra] Lowercase tag', '2025-01-02T00:00:00Z'),
326
- createCommit(3, '[Code-Infra] Mixed case tag', '2025-01-03T00:00:00Z'),
327
- ];
328
-
329
- const section = createSection(commits);
330
- const result = renderChangelog(
331
- [section],
332
- baseConfig,
333
- {
334
- version: '1.0.0',
335
- lastRelease: 'v0.1.0',
336
- release: 'v1.0.0',
337
- date: new Date('2025-01-15'),
338
- },
339
- { team: [], community: [], all: [] },
340
- );
341
-
342
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
343
-
344
- // All should be treated as the same tag and sorted by merge time
345
- expect(lines[0]).toContain('Uppercase tag');
346
- expect(lines[1]).toContain('Lowercase tag');
347
- expect(lines[2]).toContain('Mixed case tag');
348
- });
349
-
350
- it('should sort commits with merge time fallback to prNumber', () => {
351
- const commits = [
352
- createCommit(1, '[code-infra] Commit with mergedAt', null),
353
- createCommit(3, '[code-infra] Commit 3', null),
354
- createCommit(2, '[code-infra] Commit 2', null),
355
- ];
356
-
357
- const section = createSection(commits);
358
- const result = renderChangelog(
359
- [section],
360
- baseConfig,
361
- {
362
- version: '1.0.0',
363
- lastRelease: 'v0.1.0',
364
- release: 'v1.0.0',
365
- date: new Date('2025-01-15'),
366
- },
367
- { team: [], community: [], all: [] },
368
- );
369
-
370
- const lines = result.split('\n').filter((line) => line.startsWith('- '));
371
-
372
- // Should be sorted by prNumber when mergedAt is null
373
- expect(lines[0]).toContain('Commit with mergedAt');
374
- expect(lines[1]).toContain('Commit 2');
375
- expect(lines[2]).toContain('Commit 3');
376
- });
377
- });
378
- });
@@ -1,199 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- // eslint-disable-next-line import/extensions
3
- import { sortSections } from './sortSections.mjs';
4
- import type { ChangelogSection, CategorizationConfig, LabelConfig } from './types';
5
-
6
- const baseLabelConfig: LabelConfig = {
7
- plan: {
8
- values: ['pro', 'premium'],
9
- },
10
- };
11
-
12
- function createSection(key: string, commits: number = 1): ChangelogSection {
13
- return {
14
- key,
15
- level: 3,
16
- commits: Array(commits).fill({
17
- sha: 'abc123',
18
- message: 'test commit',
19
- labels: [],
20
- prNumber: 1,
21
- html_url: 'https://github.com/test/repo/pull/1',
22
- author: null,
23
- createdAt: null,
24
- mergedAt: null,
25
- parsed: { scopes: [], components: [], flags: [] },
26
- }),
27
- pkgInfo: null,
28
- };
29
- }
30
-
31
- describe('sortSections', () => {
32
- describe('default ordering', () => {
33
- const config: CategorizationConfig = {
34
- strategy: 'component',
35
- labels: baseLabelConfig,
36
- sections: {
37
- fallbackSection: 'Other',
38
- },
39
- };
40
-
41
- it('should sort sections alphabetically by key when no order is specified', () => {
42
- const sections = [createSection('Zebra'), createSection('Apple'), createSection('Mango')];
43
-
44
- const result = sortSections(sections, config);
45
-
46
- expect(result.map((s) => s.key)).toEqual(['Apple', 'Mango', 'Zebra']);
47
- });
48
-
49
- it('should return empty array for empty input', () => {
50
- const result = sortSections([], config);
51
-
52
- expect(result).toEqual([]);
53
- });
54
- });
55
-
56
- describe('priority ordering', () => {
57
- it('should sort sections by order index (lower values first)', () => {
58
- const config: CategorizationConfig = {
59
- strategy: 'component',
60
- labels: baseLabelConfig,
61
- sections: {
62
- order: {
63
- Zebra: -1,
64
- Apple: 1,
65
- Mango: 0,
66
- },
67
- fallbackSection: 'Other',
68
- },
69
- };
70
-
71
- const sections = [createSection('Apple'), createSection('Zebra'), createSection('Mango')];
72
-
73
- const result = sortSections(sections, config);
74
-
75
- expect(result.map((s) => s.key)).toEqual(['Zebra', 'Mango', 'Apple']);
76
- });
77
-
78
- it('should sort alphabetically when order index is the same', () => {
79
- const config: CategorizationConfig = {
80
- strategy: 'component',
81
- labels: baseLabelConfig,
82
- sections: {
83
- order: {
84
- Zebra: 0,
85
- Apple: 0,
86
- Mango: 0,
87
- },
88
- fallbackSection: 'Other',
89
- },
90
- };
91
-
92
- const sections = [createSection('Zebra'), createSection('Apple'), createSection('Mango')];
93
-
94
- const result = sortSections(sections, config);
95
-
96
- expect(result.map((s) => s.key)).toEqual(['Apple', 'Mango', 'Zebra']);
97
- });
98
-
99
- it('should use default order index of 0 for sections not in order config', () => {
100
- const config: CategorizationConfig = {
101
- strategy: 'component',
102
- labels: baseLabelConfig,
103
- sections: {
104
- order: {
105
- Zebra: -1,
106
- Apple: 1,
107
- },
108
- fallbackSection: 'Other',
109
- },
110
- };
111
-
112
- const sections = [
113
- createSection('Apple'),
114
- createSection('Zebra'),
115
- createSection('Mango'), // Not in order config, defaults to 0
116
- ];
117
-
118
- const result = sortSections(sections, config);
119
-
120
- // Zebra (-1) < Mango (0) < Apple (1)
121
- expect(result.map((s) => s.key)).toEqual(['Zebra', 'Mango', 'Apple']);
122
- });
123
-
124
- it('should handle negative order indices', () => {
125
- const config: CategorizationConfig = {
126
- strategy: 'component',
127
- labels: baseLabelConfig,
128
- sections: {
129
- order: {
130
- First: -100,
131
- Second: -50,
132
- Third: 0,
133
- Last: 100,
134
- },
135
- fallbackSection: 'Other',
136
- },
137
- };
138
-
139
- const sections = [
140
- createSection('Last'),
141
- createSection('Third'),
142
- createSection('First'),
143
- createSection('Second'),
144
- ];
145
-
146
- const result = sortSections(sections, config);
147
-
148
- expect(result.map((s) => s.key)).toEqual(['First', 'Second', 'Third', 'Last']);
149
- });
150
-
151
- it('should not mutate the original array', () => {
152
- const config: CategorizationConfig = {
153
- strategy: 'component',
154
- labels: baseLabelConfig,
155
- sections: {
156
- order: {
157
- Zebra: -1,
158
- },
159
- fallbackSection: 'Other',
160
- },
161
- };
162
-
163
- const sections = [createSection('Apple'), createSection('Zebra')];
164
- const originalOrder = sections.map((s) => s.key);
165
-
166
- sortSections(sections, config);
167
-
168
- expect(sections.map((s) => s.key)).toEqual(originalOrder);
169
- });
170
- });
171
-
172
- describe('package strategy', () => {
173
- it('should sort package sections by order index', () => {
174
- const config: CategorizationConfig = {
175
- strategy: 'package',
176
- labels: baseLabelConfig,
177
- packageNaming: {
178
- mappings: {
179
- 'data grid': '@mui/x-data-grid',
180
- charts: '@mui/x-charts',
181
- },
182
- },
183
- sections: {
184
- order: {
185
- '@mui/x-charts': -1,
186
- '@mui/x-data-grid': 1,
187
- },
188
- fallbackSection: 'Other',
189
- },
190
- };
191
-
192
- const sections = [createSection('@mui/x-data-grid'), createSection('@mui/x-charts')];
193
-
194
- const result = sortSections(sections, config);
195
-
196
- expect(result.map((s) => s.key)).toEqual(['@mui/x-charts', '@mui/x-data-grid']);
197
- });
198
- });
199
- });