1
1
import Auto , { SEMVER } from '@auto-it/core' ;
2
2
import mockFs from "mock-fs" ;
3
3
import fs from "fs" ;
4
- import BazelPlugin from '../src' ;
4
+ import VersionFilePlugin from '../src' ;
5
5
import { makeHooks } from '@auto-it/core/dist/utils/make-hooks' ;
6
6
import { dummyLog } from "@auto-it/core/dist/utils/logger" ;
7
7
@@ -27,7 +27,7 @@ describe('Version File Read Operations', () => {
27
27
mockFs ( {
28
28
"VERSION" : `1.0.0` ,
29
29
} ) ;
30
- const plugin = new BazelPlugin ( { } ) ;
30
+ const plugin = new VersionFilePlugin ( { } ) ;
31
31
const hooks = makeHooks ( ) ;
32
32
33
33
plugin . apply ( {
@@ -44,7 +44,7 @@ describe('Version File Read Operations', () => {
44
44
mockFs ( {
45
45
"VERSIONFILE" : `1.0.0` ,
46
46
} ) ;
47
- const plugin = new BazelPlugin ( { versionFile : "VERSIONFILE" } ) ;
47
+ const plugin = new VersionFilePlugin ( { versionFile : "VERSIONFILE" } ) ;
48
48
const hooks = makeHooks ( ) ;
49
49
50
50
plugin . apply ( {
@@ -63,14 +63,19 @@ describe("Version File Write Operations", () => {
63
63
mockFs ( {
64
64
"VERSION" : `1.0.0` ,
65
65
} ) ;
66
- const plugin = new BazelPlugin ( { } ) ;
66
+ const plugin = new VersionFilePlugin ( { } ) ;
67
67
const hooks = makeHooks ( ) ;
68
68
69
+ const prefixRelease : ( a : string ) => string = ( version : string ) => {
70
+ return `v${ version } ` ;
71
+ } ;
72
+
69
73
plugin . apply ( {
70
74
hooks,
71
75
remote : "origin" ,
72
76
baseBranch : "main" ,
73
77
logger : dummyLog ( ) ,
78
+ prefixRelease
74
79
} as Auto ) ;
75
80
76
81
await hooks . version . promise ( { bump : SEMVER . major } )
@@ -84,14 +89,19 @@ describe("Version File Write Operations", () => {
84
89
mockFs ( {
85
90
"VERSION" : `1.0.0` ,
86
91
} ) ;
87
- const plugin = new BazelPlugin ( { } ) ;
92
+ const plugin = new VersionFilePlugin ( { } ) ;
88
93
const hooks = makeHooks ( ) ;
89
94
95
+ const prefixRelease : ( a : string ) => string = ( version : string ) => {
96
+ return `v${ version } ` ;
97
+ } ;
98
+
90
99
plugin . apply ( {
91
100
hooks,
92
101
remote : "origin" ,
93
102
baseBranch : "main" ,
94
103
logger : dummyLog ( ) ,
104
+ prefixRelease
95
105
} as Auto ) ;
96
106
97
107
await hooks . version . promise ( { bump : SEMVER . minor } )
@@ -105,14 +115,19 @@ describe("Version File Write Operations", () => {
105
115
mockFs ( {
106
116
"VERSION" : `1.0.0` ,
107
117
} ) ;
108
- const plugin = new BazelPlugin ( { } ) ;
118
+ const plugin = new VersionFilePlugin ( { } ) ;
109
119
const hooks = makeHooks ( ) ;
110
120
121
+ const prefixRelease : ( a : string ) => string = ( version : string ) => {
122
+ return `v${ version } ` ;
123
+ } ;
124
+
111
125
plugin . apply ( {
112
126
hooks,
113
127
remote : "origin" ,
114
128
baseBranch : "main" ,
115
129
logger : dummyLog ( ) ,
130
+ prefixRelease
116
131
} as Auto ) ;
117
132
118
133
await hooks . version . promise ( { bump : SEMVER . patch } )
@@ -121,14 +136,40 @@ describe("Version File Write Operations", () => {
121
136
expect ( execPromise ) . toHaveBeenNthCalledWith ( 1 , "git" , [ "commit" , "-am" , "\"Bump version to: v1.0.1 [skip ci]\"" ] ) ;
122
137
expect ( execPromise ) . toHaveBeenNthCalledWith ( 2 , "git" , [ "tag" , "v1.0.1" ] ) ;
123
138
} ) ;
139
+
140
+ test ( "It should version the file properly for without a prefix" , async ( ) => {
141
+ mockFs ( {
142
+ "VERSION" : `1.0.0` ,
143
+ } ) ;
144
+ const plugin = new VersionFilePlugin ( { } ) ;
145
+ const hooks = makeHooks ( ) ;
146
+
147
+ const prefixRelease : ( a : string ) => string = ( version : string ) => {
148
+ return `${ version } ` ;
149
+ } ;
150
+
151
+ plugin . apply ( {
152
+ hooks,
153
+ remote : "origin" ,
154
+ baseBranch : "main" ,
155
+ logger : dummyLog ( ) ,
156
+ prefixRelease
157
+ } as Auto ) ;
158
+
159
+ await hooks . version . promise ( { bump : SEMVER . patch } )
160
+ expect ( fs . readFileSync ( "VERSION" , "utf-8" ) ) . toStrictEqual ( "1.0.1" ) ;
161
+ // check that the proper git operations were performed
162
+ expect ( execPromise ) . toHaveBeenNthCalledWith ( 1 , "git" , [ "commit" , "-am" , "\"Bump version to: 1.0.1 [skip ci]\"" ] ) ;
163
+ expect ( execPromise ) . toHaveBeenNthCalledWith ( 2 , "git" , [ "tag" , "1.0.1" ] ) ;
164
+ } ) ;
124
165
} )
125
166
126
167
describe ( "Test Release Types" , ( ) => {
127
168
test ( "Full release with no release script" , async ( ) => {
128
169
mockFs ( {
129
170
"VERSION" : `1.0.0` ,
130
171
} ) ;
131
- const plugin = new BazelPlugin ( { } ) ;
172
+ const plugin = new VersionFilePlugin ( { } ) ;
132
173
const hooks = makeHooks ( ) ;
133
174
134
175
plugin . apply ( {
@@ -148,7 +189,7 @@ describe("Test Release Types", () => {
148
189
mockFs ( {
149
190
"VERSION" : `1.0.0` ,
150
191
} ) ;
151
- const plugin = new BazelPlugin ( { publishScript :"./tools/release.sh" } ) ;
192
+ const plugin = new VersionFilePlugin ( { publishScript :"./tools/release.sh" } ) ;
152
193
const hooks = makeHooks ( ) ;
153
194
154
195
plugin . apply ( {
@@ -171,7 +212,7 @@ describe("Test Release Types", () => {
171
212
mockFs ( {
172
213
"VERSION" : `1.0.0` ,
173
214
} ) ;
174
- const plugin = new BazelPlugin ( { } ) ;
215
+ const plugin = new VersionFilePlugin ( { } ) ;
175
216
const hooks = makeHooks ( ) ;
176
217
177
218
plugin . apply ( ( {
@@ -199,7 +240,7 @@ describe("Test Release Types", () => {
199
240
mockFs ( {
200
241
"VERSION" : `1.0.0` ,
201
242
} ) ;
202
- const plugin = new BazelPlugin ( { publishScript :"./tools/release.sh" } ) ;
243
+ const plugin = new VersionFilePlugin ( { publishScript :"./tools/release.sh" } ) ;
203
244
const hooks = makeHooks ( ) ;
204
245
205
246
plugin . apply ( ( {
@@ -235,7 +276,7 @@ describe("Test Release Types", () => {
235
276
mockFs ( {
236
277
"VERSION" : `1.0.0` ,
237
278
} ) ;
238
- const plugin = new BazelPlugin ( { } ) ;
279
+ const plugin = new VersionFilePlugin ( { } ) ;
239
280
const hooks = makeHooks ( ) ;
240
281
241
282
plugin . apply ( ( {
@@ -272,7 +313,7 @@ describe("Test Release Types", () => {
272
313
mockFs ( {
273
314
"VERSION" : `1.0.0` ,
274
315
} ) ;
275
- const plugin = new BazelPlugin ( { publishScript :"./tools/release.sh" } ) ;
316
+ const plugin = new VersionFilePlugin ( { publishScript :"./tools/release.sh" } ) ;
276
317
const hooks = makeHooks ( ) ;
277
318
278
319
plugin . apply ( ( {
@@ -311,7 +352,7 @@ describe("Test Release Types", () => {
311
352
mockFs ( {
312
353
VERSION : `1.0.0` ,
313
354
} ) ;
314
- const plugin = new BazelPlugin ( {
355
+ const plugin = new VersionFilePlugin ( {
315
356
publishScript : "./tools/release.sh" ,
316
357
publishScriptReleaseTypeArgs : {
317
358
publish : [ "args" , "for" , "publish" ] ,
0 commit comments