@@ -2,10 +2,15 @@ import { describe, it } from "mocha";
2
2
import { expect } from "chai" ;
3
3
import fs from "fs-extra" ;
4
4
import path from "path" ;
5
- import { replaceTokensInFile , replaceTokensInFiles } from "../src/utils/file-utils" ;
5
+ import {
6
+ getDestinationDir ,
7
+ getRepositoryUrl ,
8
+ replaceTokensInFile ,
9
+ replaceTokensInFiles ,
10
+ } from "../src/utils/file-utils" ;
6
11
7
12
describe ( "file-utils" , async ( ) => {
8
- const baseDir = path . join ( __dirname , "tests" , " tmp-files") ;
13
+ const baseDir = path . join ( __dirname , "tmp-files" ) ;
9
14
10
15
await fs . ensureDir ( baseDir ) ;
11
16
@@ -53,4 +58,44 @@ describe("file-utils", async () => {
53
58
expect ( data ) . to . be . equal ( "test1" ) ;
54
59
} ) ;
55
60
} ) ;
61
+
62
+ describe ( "get destination dir" , async ( ) => {
63
+ const destDir = await getDestinationDir ( path . join ( baseDir , "baz" ) ) ;
64
+
65
+ it ( "should return the destination dir" , ( ) => {
66
+ expect ( destDir ) . to . be . equal ( path . join ( baseDir , "baz" ) ) ;
67
+ } ) ;
68
+
69
+ it ( "should return the destination dir" , async ( ) => {
70
+ const destDir2 = await getDestinationDir ( path . join ( baseDir , "baz" ) ) ;
71
+
72
+ expect ( destDir2 ) . to . be . equal ( path . join ( baseDir , "baz" ) ) ;
73
+ } ) ;
74
+
75
+ it ( "should throw exception" , async ( ) => {
76
+ await fs . writeFile ( path . join ( baseDir , "baz" , "tmp.txt" ) , "" ) ;
77
+
78
+ let ex = false ;
79
+
80
+ try {
81
+ await getDestinationDir ( path . join ( baseDir , "baz" ) ) ;
82
+
83
+ console . log ( "never" ) ;
84
+ } catch {
85
+ ex = true ;
86
+ }
87
+
88
+ expect ( ex ) . to . be . equal ( true ) ;
89
+ } ) ;
90
+ } ) ;
91
+
92
+ describe ( "get repository url" , ( ) => {
93
+ it ( "should return the repository url" , ( ) => {
94
+ expect ( getRepositoryUrl ( ) ) . to . be . not . equal ( "" ) ;
95
+ } ) ;
96
+ } ) ;
97
+
98
+ after ( async ( ) => {
99
+ await fs . remove ( baseDir ) ;
100
+ } ) ;
56
101
} ) ;
0 commit comments