|
8 | 8 | } from '../../plugin/constants.js'; |
9 | 9 | import { addZod2MdTransformToTsConfig } from '../configuration/tsconfig.js'; |
10 | 10 | import { generateZod2MdConfig } from '../configuration/zod2md-config.js'; |
11 | | -import { syncZod2mdSetupGenerator } from './sync-zod2md-setup.js'; |
| 11 | +import { formatIssues, syncZod2mdSetupGenerator } from './sync-zod2md-setup.js'; |
12 | 12 |
|
13 | 13 | describe('sync-zod2md-setup generator', () => { |
14 | 14 | const createProjectGraphAsyncSpy = vi.spyOn( |
@@ -248,4 +248,139 @@ describe('sync-zod2md-setup generator', () => { |
248 | 248 | ).length; |
249 | 249 | expect(generateDocsCount).toBe(1); |
250 | 250 | }); |
| 251 | + |
| 252 | + describe('formatIssues', () => { |
| 253 | + it('should return undefined for empty issues array', () => { |
| 254 | + expect(formatIssues([])).toBeUndefined(); |
| 255 | + }); |
| 256 | + |
| 257 | + it('should format missing tsconfig issues', () => { |
| 258 | + const issues = [ |
| 259 | + { |
| 260 | + type: 'missing-tsconfig' as const, |
| 261 | + projectRoot: 'libs/project1', |
| 262 | + data: undefined, |
| 263 | + }, |
| 264 | + { |
| 265 | + type: 'missing-tsconfig' as const, |
| 266 | + projectRoot: 'libs/project2', |
| 267 | + data: undefined, |
| 268 | + }, |
| 269 | + ]; |
| 270 | + |
| 271 | + expect(formatIssues(issues)).toBe(`Missing tsconfig in: |
| 272 | + - libs/project1 |
| 273 | + - libs/project2`); |
| 274 | + }); |
| 275 | + |
| 276 | + it('should format missing target issues', () => { |
| 277 | + const issues = [ |
| 278 | + { |
| 279 | + type: 'missing-target' as const, |
| 280 | + projectRoot: 'libs/project1', |
| 281 | + data: { target: 'generate-docs' }, |
| 282 | + }, |
| 283 | + ]; |
| 284 | + |
| 285 | + expect(formatIssues(issues)).toBe(`Missing "generate-docs" target in: |
| 286 | + - libs/project1`); |
| 287 | + }); |
| 288 | + |
| 289 | + it('should format missing build dependencies issues', () => { |
| 290 | + const issues = [ |
| 291 | + { |
| 292 | + type: 'missing-build-depends-on' as const, |
| 293 | + projectRoot: 'libs/project1', |
| 294 | + data: { missing: ['generate-docs', 'ts-patch'] }, |
| 295 | + }, |
| 296 | + { |
| 297 | + type: 'missing-build-depends-on' as const, |
| 298 | + projectRoot: 'libs/project2', |
| 299 | + data: { missing: ['generate-docs'] }, |
| 300 | + }, |
| 301 | + ]; |
| 302 | + |
| 303 | + expect(formatIssues(issues)).toBe(`Missing build.dependsOn entries: |
| 304 | + - libs/project1: generate-docs, ts-patch |
| 305 | + - libs/project2: generate-docs`); |
| 306 | + }); |
| 307 | + |
| 308 | + it('should format missing ts plugin issues', () => { |
| 309 | + const issues = [ |
| 310 | + { |
| 311 | + type: 'missing-ts-plugin' as const, |
| 312 | + projectRoot: 'libs/project1', |
| 313 | + data: undefined, |
| 314 | + }, |
| 315 | + ]; |
| 316 | + |
| 317 | + expect(formatIssues(issues)) |
| 318 | + .toBe(`Missing Zod2Md TypeScript plugin configuration in: |
| 319 | + - libs/project1`); |
| 320 | + }); |
| 321 | + |
| 322 | + it('should format multiple issue types', () => { |
| 323 | + const issues = [ |
| 324 | + { |
| 325 | + type: 'missing-tsconfig' as const, |
| 326 | + projectRoot: 'libs/project1', |
| 327 | + data: undefined, |
| 328 | + }, |
| 329 | + { |
| 330 | + type: 'missing-target' as const, |
| 331 | + projectRoot: 'libs/project2', |
| 332 | + data: { target: 'generate-docs' }, |
| 333 | + }, |
| 334 | + { |
| 335 | + type: 'missing-build-depends-on' as const, |
| 336 | + projectRoot: 'libs/project3', |
| 337 | + data: { missing: ['generate-docs'] }, |
| 338 | + }, |
| 339 | + { |
| 340 | + type: 'missing-ts-plugin' as const, |
| 341 | + projectRoot: 'libs/project4', |
| 342 | + data: undefined, |
| 343 | + }, |
| 344 | + ]; |
| 345 | + |
| 346 | + const expected = `Missing tsconfig in: |
| 347 | + - libs/project1 |
| 348 | +
|
| 349 | +Missing "generate-docs" target in: |
| 350 | + - libs/project2 |
| 351 | +
|
| 352 | +Missing build.dependsOn entries: |
| 353 | + - libs/project3: generate-docs |
| 354 | +
|
| 355 | +Missing Zod2Md TypeScript plugin configuration in: |
| 356 | + - libs/project4`; |
| 357 | + |
| 358 | + expect(formatIssues(issues)).toBe(expected); |
| 359 | + }); |
| 360 | + |
| 361 | + it('should filter out null formatted sections', () => { |
| 362 | + const issues = [ |
| 363 | + { |
| 364 | + type: 'missing-tsconfig' as const, |
| 365 | + projectRoot: 'libs/project1', |
| 366 | + data: undefined, |
| 367 | + }, |
| 368 | + // No missing-target issues |
| 369 | + // No missing-build-deps issues |
| 370 | + { |
| 371 | + type: 'missing-ts-plugin' as const, |
| 372 | + projectRoot: 'libs/project2', |
| 373 | + data: undefined, |
| 374 | + }, |
| 375 | + ]; |
| 376 | + |
| 377 | + const expected = `Missing tsconfig in: |
| 378 | + - libs/project1 |
| 379 | +
|
| 380 | +Missing Zod2Md TypeScript plugin configuration in: |
| 381 | + - libs/project2`; |
| 382 | + |
| 383 | + expect(formatIssues(issues)).toBe(expected); |
| 384 | + }); |
| 385 | + }); |
251 | 386 | }); |
0 commit comments