@@ -14,15 +14,16 @@ jest.mock('@actions/core', () => ({
14
14
} ) )
15
15
16
16
/*
17
- Test generateWorktree against a known git repository.
18
- The upstream repository `origin` is set up once for the test suite,
19
- and for each test run, a new clone is created.
20
-
21
- See workstree.error.test.ts for testing mocked errors from git.*/
17
+ Test generateWorktree against a known git repository.
18
+ The upstream repository `origin` is set up once for the test suite,
19
+ and for each test run, a new clone is created.
22
20
21
+ See workstree.error.test.ts for testing mocked errors from git.
22
+ */
23
23
describe ( 'generateWorktree' , ( ) => {
24
24
let tempdir : string | null = null
25
25
let clonedir : string | null = null
26
+
26
27
beforeAll ( async ( ) => {
27
28
// Set up origin repository
28
29
const silent = true
@@ -50,6 +51,7 @@ describe('generateWorktree', () => {
50
51
await execute ( 'git add .' , origin , silent )
51
52
await execute ( 'git commit -mgh1' , origin , silent )
52
53
} )
54
+
53
55
beforeEach ( async ( ) => {
54
56
// Clone origin to our workspace for each test
55
57
const silent = true
@@ -65,17 +67,19 @@ describe('generateWorktree', () => {
65
67
await execute ( 'git fetch --depth=1 origin main' , clonedir , silent )
66
68
await execute ( 'git checkout main' , clonedir , silent )
67
69
} )
70
+
68
71
afterEach ( async ( ) => {
69
72
// Tear down workspace
70
73
await rmRF ( clonedir as string )
71
74
} )
75
+
72
76
afterAll ( async ( ) => {
73
77
// Tear down origin repository
74
78
if ( tempdir ) {
75
79
await rmRF ( tempdir )
76
- // console.log(tempdir)
77
80
}
78
81
} )
82
+
79
83
describe ( 'with existing branch and new commits' , ( ) => {
80
84
it ( 'should check out the latest commit' , async ( ) => {
81
85
const workspace = clonedir as string
@@ -92,24 +96,29 @@ describe('generateWorktree', () => {
92
96
'worktree' ,
93
97
true
94
98
)
99
+
95
100
const dirEntries = await fs . promises . readdir (
96
101
path . join ( workspace , 'worktree' )
97
102
)
103
+
98
104
expect ( dirEntries . sort ( ( a , b ) => a . localeCompare ( b ) ) ) . toEqual ( [
99
105
'.git' ,
100
106
'gh1'
101
107
] )
108
+
102
109
const commitMessages = await execute (
103
110
'git log --format=%s' ,
104
111
path . join ( workspace , 'worktree' ) ,
105
112
true
106
113
)
114
+
107
115
expect ( commitMessages . stdout ) . toBe ( 'gh1' )
108
116
} )
109
117
} )
110
118
describe ( 'with missing branch and new commits' , ( ) => {
111
119
it ( 'should create initial commit' , async ( ) => {
112
120
const workspace = clonedir as string
121
+
113
122
await generateWorktree (
114
123
{
115
124
hostname : 'github.com' ,
@@ -123,21 +132,26 @@ describe('generateWorktree', () => {
123
132
'worktree' ,
124
133
false
125
134
)
135
+
126
136
const dirEntries = await fs . promises . readdir (
127
137
path . join ( workspace , 'worktree' )
128
138
)
139
+
129
140
expect ( dirEntries ) . toEqual ( [ '.git' ] )
141
+
130
142
const commitMessages = await execute (
131
143
'git log --format=%s' ,
132
144
path . join ( workspace , 'worktree' ) ,
133
145
true
134
146
)
147
+
135
148
expect ( commitMessages . stdout ) . toBe ( 'Initial no-pages commit' )
136
149
} )
137
150
} )
138
151
describe ( 'with existing branch and singleCommit' , ( ) => {
139
152
it ( 'should check out the latest commit' , async ( ) => {
140
153
const workspace = clonedir as string
154
+
141
155
await generateWorktree (
142
156
{
143
157
hostname : 'github.com' ,
@@ -151,13 +165,16 @@ describe('generateWorktree', () => {
151
165
'worktree' ,
152
166
true
153
167
)
168
+
154
169
const dirEntries = await fs . promises . readdir (
155
170
path . join ( workspace , 'worktree' )
156
171
)
172
+
157
173
expect ( dirEntries . sort ( ( a , b ) => a . localeCompare ( b ) ) ) . toEqual ( [
158
174
'.git' ,
159
175
'gh1'
160
176
] )
177
+
161
178
expect ( async ( ) => {
162
179
await execute (
163
180
'git log --format=%s' ,
@@ -170,6 +187,7 @@ describe('generateWorktree', () => {
170
187
describe ( 'with missing branch and singleCommit' , ( ) => {
171
188
it ( 'should create initial commit' , async ( ) => {
172
189
const workspace = clonedir as string
190
+
173
191
await generateWorktree (
174
192
{
175
193
hostname : 'github.com' ,
@@ -183,10 +201,13 @@ describe('generateWorktree', () => {
183
201
'worktree' ,
184
202
false
185
203
)
204
+
186
205
const dirEntries = await fs . promises . readdir (
187
206
path . join ( workspace , 'worktree' )
188
207
)
208
+
189
209
expect ( dirEntries ) . toEqual ( [ '.git' ] )
210
+
190
211
expect ( async ( ) => {
191
212
await execute (
192
213
'git log --format=%s' ,
0 commit comments