@@ -6,6 +6,7 @@ import { Utils } from '../src';
6
6
const { getWorkspace, getActor, escapeRegExp, getRegExp, getPrefixRegExp, getSuffixRegExp, useNpm, versionCompare, getOctokit} = Utils ;
7
7
const { isSemanticVersioningTagName, isPrRef, getPrMergeRef, getBoolValue, replaceAll, getPrHeadRef, arrayChunk, sleep} = Utils ;
8
8
const { getBranch, getRefForUpdate, uniqueArray, getBuildInfo, split, getArrayInput, generateNewPatchVersion, getPrBranch} = Utils ;
9
+ const { isBranch, isTagRef, normalizeRef, trimRef, getTag, getRefspec} = Utils ;
9
10
10
11
jest . useFakeTimers ( ) ;
11
12
@@ -482,3 +483,63 @@ describe('getOctokit', () => {
482
483
expect ( ( ) => getOctokit ( ) ) . toThrow ( ) ;
483
484
} ) ;
484
485
} ) ;
486
+
487
+ describe ( 'isBranch' , ( ) => {
488
+ it ( 'should return true' , ( ) => {
489
+ expect ( isBranch ( 'refs/heads/master' ) ) . toBe ( true ) ;
490
+ expect ( isBranch ( 'heads/master' ) ) . toBe ( true ) ;
491
+ } ) ;
492
+
493
+ it ( 'should return false' , ( ) => {
494
+ expect ( isBranch ( 'test' ) ) . toBe ( false ) ;
495
+ expect ( isBranch ( 'heads' ) ) . toBe ( false ) ;
496
+ } ) ;
497
+ } ) ;
498
+
499
+ describe ( 'isTagRef' , ( ) => {
500
+ it ( 'should return true' , ( ) => {
501
+ expect ( isTagRef ( 'refs/tags/v1.2.3' ) ) . toBe ( true ) ;
502
+ } ) ;
503
+
504
+ it ( 'should return false' , ( ) => {
505
+ expect ( isTagRef ( 'refs/heads/master' ) ) . toBe ( false ) ;
506
+ expect ( isTagRef ( 'heads/master' ) ) . toBe ( false ) ;
507
+ } ) ;
508
+ } ) ;
509
+
510
+ describe ( 'normalizeRef' , ( ) => {
511
+ it ( 'should normalize ref' , ( ) => {
512
+ expect ( normalizeRef ( 'master' ) ) . toBe ( 'refs/heads/master' ) ;
513
+ expect ( normalizeRef ( 'refs/heads/master' ) ) . toBe ( 'refs/heads/master' ) ;
514
+ expect ( normalizeRef ( 'refs/tags/v1.2.3' ) ) . toBe ( 'refs/tags/v1.2.3' ) ;
515
+ expect ( normalizeRef ( 'refs/pull/123/merge' ) ) . toBe ( 'refs/pull/123/merge' ) ;
516
+ } ) ;
517
+ } ) ;
518
+
519
+ describe ( 'trimRef' , ( ) => {
520
+ it ( 'should trim ref' , ( ) => {
521
+ expect ( trimRef ( 'master' ) ) . toBe ( 'master' ) ;
522
+ expect ( trimRef ( 'refs/heads/master' ) ) . toBe ( 'master' ) ;
523
+ expect ( trimRef ( 'refs/tags/v1.2.3' ) ) . toBe ( 'v1.2.3' ) ;
524
+ expect ( trimRef ( 'refs/pull/123/merge' ) ) . toBe ( '123/merge' ) ;
525
+ } ) ;
526
+ } ) ;
527
+
528
+ describe ( 'getTag' , ( ) => {
529
+ it ( 'should get tag' , ( ) => {
530
+ expect ( getTag ( 'master' ) ) . toBe ( '' ) ;
531
+ expect ( getTag ( 'heads/master' ) ) . toBe ( '' ) ;
532
+ expect ( getTag ( 'refs/heads/master' ) ) . toBe ( '' ) ;
533
+ expect ( getTag ( 'refs/tags/v1.2.3' ) ) . toBe ( 'v1.2.3' ) ;
534
+ expect ( getTag ( 'refs/pull/123/merge' ) ) . toBe ( '' ) ;
535
+ } ) ;
536
+ } ) ;
537
+
538
+ describe ( 'getRefspec' , ( ) => {
539
+ it ( 'should get refspec' , ( ) => {
540
+ expect ( getRefspec ( 'master' ) ) . toBe ( 'refs/heads/master:refs/remotes/origin/master' ) ;
541
+ expect ( getRefspec ( 'refs/heads/master' , 'test' ) ) . toBe ( 'refs/heads/master:refs/remotes/test/master' ) ;
542
+ expect ( getRefspec ( 'refs/tags/v1.2.3' ) ) . toBe ( 'refs/tags/v1.2.3:refs/tags/v1.2.3' ) ;
543
+ expect ( getRefspec ( 'refs/pull/123/merge' ) ) . toBe ( 'refs/pull/123/merge:refs/pull/123/merge' ) ;
544
+ } ) ;
545
+ } ) ;
0 commit comments