1
1
import * as simpleGit from 'simple-git' ;
2
2
import GitUrlParse from 'git-url-parse' ;
3
3
4
- import { afterEach , describe , expect , it , vi } from 'vitest' ;
4
+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
5
5
import any from '@travi/any' ;
6
6
import { when } from 'jest-when' ;
7
7
@@ -11,21 +11,36 @@ vi.mock('simple-git');
11
11
vi . mock ( 'git-url-parse' ) ;
12
12
13
13
describe ( 'vcs' , ( ) => {
14
+ const projectRoot = any . string ( ) ;
15
+ const owner = any . word ( ) ;
16
+ const name = any . word ( ) ;
17
+ const remoteUrl = any . url ( ) ;
18
+
19
+ beforeEach ( ( ) => {
20
+ const remote = vi . fn ( ) ;
21
+
22
+ when ( simpleGit . simpleGit ) . calledWith ( { baseDir : projectRoot } ) . mockReturnValue ( { remote} ) ;
23
+ when ( remote ) . calledWith ( [ 'get-url' , 'origin' ] ) . mockResolvedValue ( `${ remoteUrl } \n` ) ;
24
+ } ) ;
25
+
14
26
afterEach ( ( ) => {
15
27
vi . clearAllMocks ( ) ;
16
28
} ) ;
17
29
18
30
it ( 'should determine the existing details from the remote origin' , async ( ) => {
19
- const owner = any . word ( ) ;
20
- const name = any . word ( ) ;
21
31
const host = any . word ( ) ;
22
- const remoteUrl = any . url ( ) ;
23
- const projectRoot = any . string ( ) ;
24
- const remote = vi . fn ( ) ;
25
- when ( simpleGit . simpleGit ) . calledWith ( { baseDir : projectRoot } ) . mockReturnValue ( { remote} ) ;
26
- when ( remote ) . calledWith ( [ 'get-url' , 'origin' ] ) . mockResolvedValue ( `${ remoteUrl } \n` ) ;
27
32
when ( GitUrlParse ) . calledWith ( remoteUrl ) . mockReturnValue ( { owner, name, host} ) ;
28
33
29
34
expect ( await determineExistingHostDetails ( { projectRoot} ) ) . toEqual ( { owner, name, host} ) ;
30
35
} ) ;
36
+
37
+ it (
38
+ 'should return `github` when the host is determined to be `github.com` until that can be a breaking change' ,
39
+ async ( ) => {
40
+ const host = 'github.com' ;
41
+ when ( GitUrlParse ) . calledWith ( remoteUrl ) . mockReturnValue ( { owner, name, host} ) ;
42
+
43
+ expect ( await determineExistingHostDetails ( { projectRoot} ) ) . toEqual ( { owner, name, host : 'github' } ) ;
44
+ }
45
+ ) ;
31
46
} ) ;
0 commit comments