@zjex/git-workflow 0.3.10 → 0.4.0

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.
package/tests/tag.test.ts CHANGED
@@ -393,4 +393,240 @@ describe("Tag 功能测试", () => {
393
393
  });
394
394
  });
395
395
  });
396
+
397
+ describe("无效标签检测", () => {
398
+ it("应该识别不包含数字的标签为无效", () => {
399
+ const tag = "vnull";
400
+ const isInvalid = !/\d/.test(tag);
401
+
402
+ expect(isInvalid).toBe(true);
403
+ });
404
+
405
+ it("应该识别 vundefined 为无效标签", () => {
406
+ const tag = "vundefined";
407
+ const isInvalid = !/\d/.test(tag);
408
+
409
+ expect(isInvalid).toBe(true);
410
+ });
411
+
412
+ it("应该识别空版本号为无效标签", () => {
413
+ const tag = "v";
414
+ const isInvalid = !/\d/.test(tag);
415
+
416
+ expect(isInvalid).toBe(true);
417
+ });
418
+
419
+ it("应该识别纯字母标签为无效", () => {
420
+ const tag = "release";
421
+ const isInvalid = !/\d/.test(tag);
422
+
423
+ expect(isInvalid).toBe(true);
424
+ });
425
+
426
+ it("应该识别包含数字的标签为有效", () => {
427
+ const tag = "v1.0.0";
428
+ const isValid = /\d/.test(tag);
429
+
430
+ expect(isValid).toBe(true);
431
+ });
432
+
433
+ it("应该识别预发布版本为有效", () => {
434
+ const tag = "v1.0.0-beta.1";
435
+ const isValid = /\d/.test(tag);
436
+
437
+ expect(isValid).toBe(true);
438
+ });
439
+
440
+ it("应该识别无前缀版本号为有效", () => {
441
+ const tag = "1.0.0";
442
+ const isValid = /\d/.test(tag);
443
+
444
+ expect(isValid).toBe(true);
445
+ });
446
+
447
+ it("应该识别带前缀的单数字版本为有效", () => {
448
+ const tag = "v1";
449
+ const isValid = /\d/.test(tag);
450
+
451
+ expect(isValid).toBe(true);
452
+ });
453
+ });
454
+
455
+ describe("无效标签过滤", () => {
456
+ it("应该从标签列表中过滤出所有无效标签", () => {
457
+ const allTags = [
458
+ "v1.0.0",
459
+ "vnull",
460
+ "v1.1.0",
461
+ "vundefined",
462
+ "release-1.0.0",
463
+ "v",
464
+ "v2.0.0",
465
+ ];
466
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
467
+
468
+ expect(invalidTags).toEqual(["vnull", "vundefined", "v"]);
469
+ expect(invalidTags.length).toBe(3);
470
+ });
471
+
472
+ it("应该在没有无效标签时返回空数组", () => {
473
+ const allTags = ["v1.0.0", "v1.1.0", "v2.0.0", "release-1.0.0"];
474
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
475
+
476
+ expect(invalidTags).toEqual([]);
477
+ expect(invalidTags.length).toBe(0);
478
+ });
479
+
480
+ it("应该在全是无效标签时返回所有标签", () => {
481
+ const allTags = ["vnull", "vundefined", "v", "release"];
482
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
483
+
484
+ expect(invalidTags).toEqual(allTags);
485
+ expect(invalidTags.length).toBe(4);
486
+ });
487
+
488
+ it("应该保留有效标签", () => {
489
+ const allTags = [
490
+ "v1.0.0",
491
+ "vnull",
492
+ "v1.1.0",
493
+ "vundefined",
494
+ "v2.0.0-beta.1",
495
+ ];
496
+ const validTags = allTags.filter((tag) => /\d/.test(tag));
497
+
498
+ expect(validTags).toEqual(["v1.0.0", "v1.1.0", "v2.0.0-beta.1"]);
499
+ expect(validTags.length).toBe(3);
500
+ });
501
+
502
+ it("应该处理空标签列表", () => {
503
+ const allTags: string[] = [];
504
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
505
+
506
+ expect(invalidTags).toEqual([]);
507
+ expect(invalidTags.length).toBe(0);
508
+ });
509
+
510
+ it("应该处理混合前缀的无效标签", () => {
511
+ const allTags = [
512
+ "v1.0.0",
513
+ "vnull",
514
+ "release-",
515
+ "hotfix",
516
+ "g1.0.0",
517
+ "tag",
518
+ ];
519
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
520
+
521
+ expect(invalidTags).toEqual(["vnull", "release-", "hotfix", "tag"]);
522
+ expect(invalidTags.length).toBe(4);
523
+ });
524
+ });
525
+
526
+ describe("标签计数统计", () => {
527
+ it("应该正确统计无效标签数量", () => {
528
+ const allTags = ["v1.0.0", "vnull", "vundefined", "v2.0.0"];
529
+ const invalidTags = allTags.filter((tag) => !/\d/.test(tag));
530
+ const count = invalidTags.length;
531
+
532
+ expect(count).toBe(2);
533
+ });
534
+
535
+ it("应该正确统计删除成功和失败的数量", () => {
536
+ const invalidTags = ["vnull", "vundefined", "v"];
537
+ let success = 0;
538
+ let failed = 0;
539
+
540
+ // 模拟删除操作
541
+ invalidTags.forEach((tag) => {
542
+ // 模拟成功删除前两个,失败最后一个
543
+ if (tag !== "v") {
544
+ success++;
545
+ } else {
546
+ failed++;
547
+ }
548
+ });
549
+
550
+ expect(success).toBe(2);
551
+ expect(failed).toBe(1);
552
+ });
553
+
554
+ it("应该处理全部删除成功的情况", () => {
555
+ const invalidTags = ["vnull", "vundefined"];
556
+ let success = 0;
557
+ let failed = 0;
558
+
559
+ invalidTags.forEach(() => {
560
+ success++;
561
+ });
562
+
563
+ expect(success).toBe(2);
564
+ expect(failed).toBe(0);
565
+ });
566
+
567
+ it("应该处理全部删除失败的情况", () => {
568
+ const invalidTags = ["vnull", "vundefined"];
569
+ let success = 0;
570
+ let failed = 0;
571
+
572
+ invalidTags.forEach(() => {
573
+ failed++;
574
+ });
575
+
576
+ expect(success).toBe(0);
577
+ expect(failed).toBe(2);
578
+ });
579
+ });
580
+
581
+ describe("标签信息格式化", () => {
582
+ it("应该格式化标签详细信息", () => {
583
+ const tag = "vnull";
584
+ const commitHash = "abc1234";
585
+ const commitDate = "2026-01-14 10:00:00 +0800";
586
+ const commitMsg = "Release vnull";
587
+
588
+ const info = {
589
+ tag,
590
+ commit: commitHash,
591
+ date: commitDate,
592
+ message: commitMsg,
593
+ };
594
+
595
+ expect(info.tag).toBe("vnull");
596
+ expect(info.commit).toBe("abc1234");
597
+ expect(info.date).toBe("2026-01-14 10:00:00 +0800");
598
+ expect(info.message).toBe("Release vnull");
599
+ });
600
+
601
+ it("应该处理无法获取提交信息的情况", () => {
602
+ const tag = "vnull";
603
+ const info = {
604
+ tag,
605
+ commit: null,
606
+ date: null,
607
+ message: null,
608
+ };
609
+
610
+ expect(info.tag).toBe("vnull");
611
+ expect(info.commit).toBeNull();
612
+ expect(info.date).toBeNull();
613
+ expect(info.message).toBeNull();
614
+ });
615
+
616
+ it("应该格式化多个标签的信息列表", () => {
617
+ const invalidTags = ["vnull", "vundefined"];
618
+ const tagInfos = invalidTags.map((tag) => ({
619
+ tag,
620
+ commit: `${tag}-hash`,
621
+ date: "2026-01-14",
622
+ message: `Release ${tag}`,
623
+ }));
624
+
625
+ expect(tagInfos.length).toBe(2);
626
+ expect(tagInfos[0].tag).toBe("vnull");
627
+ expect(tagInfos[0].commit).toBe("vnull-hash");
628
+ expect(tagInfos[1].tag).toBe("vundefined");
629
+ expect(tagInfos[1].commit).toBe("vundefined-hash");
630
+ });
631
+ });
396
632
  });
@@ -403,4 +403,56 @@ describe("Update Notifier 模块测试", () => {
403
403
  );
404
404
  });
405
405
  });
406
+
407
+ describe("通知框样式配置", () => {
408
+ it("简单通知应该使用无边距配置", () => {
409
+ const marginConfig = { top: 0, bottom: 0, left: 0, right: 0 };
410
+
411
+ expect(marginConfig.top).toBe(0);
412
+ expect(marginConfig.bottom).toBe(0);
413
+ expect(marginConfig.left).toBe(0);
414
+ expect(marginConfig.right).toBe(0);
415
+ });
416
+
417
+ it("交互式通知应该使用最小边距配置", () => {
418
+ const marginConfig = { top: 0, bottom: 0, left: 1, right: 1 };
419
+
420
+ expect(marginConfig.top).toBe(0);
421
+ expect(marginConfig.bottom).toBe(0);
422
+ expect(marginConfig.left).toBeGreaterThanOrEqual(0);
423
+ expect(marginConfig.right).toBeGreaterThanOrEqual(0);
424
+ });
425
+
426
+ it("更新成功通知应该有底部边距", () => {
427
+ const marginConfig = { top: 0, bottom: 1, left: 2, right: 2 };
428
+
429
+ expect(marginConfig.top).toBe(0);
430
+ expect(marginConfig.bottom).toBe(1);
431
+ });
432
+
433
+ it("所有通知的顶部边距应该为 0", () => {
434
+ const configs = [
435
+ { top: 0, bottom: 0, left: 0, right: 0 },
436
+ { top: 0, bottom: 0, left: 1, right: 1 },
437
+ { top: 0, bottom: 1, left: 2, right: 2 },
438
+ ];
439
+
440
+ configs.forEach((config) => {
441
+ expect(config.top).toBe(0);
442
+ });
443
+ });
444
+
445
+ it("padding 配置应该合理", () => {
446
+ const paddingConfigs = [
447
+ { top: 0, bottom: 0, left: 2, right: 2 }, // 简单通知
448
+ { top: 1, bottom: 1, left: 3, right: 3 }, // 交互式通知
449
+ { top: 1, bottom: 1, left: 2, right: 2 }, // 成功通知
450
+ ];
451
+
452
+ paddingConfigs.forEach((padding) => {
453
+ expect(padding.left).toBeGreaterThanOrEqual(2);
454
+ expect(padding.right).toBeGreaterThanOrEqual(2);
455
+ });
456
+ });
457
+ });
406
458
  });