@@ -30,7 +30,10 @@ describe('git-revision-webpack-plugin (integration)', function () {
3030 config . context = targetProject
3131 config . output . path = targetBuild
3232 config . plugins = [
33- new GitRevisionPlugin ( { gitWorkTree : targetProject } )
33+ new GitRevisionPlugin ( {
34+ gitWorkTree : targetProject ,
35+ branch : true
36+ } )
3437 ]
3538
3639 webpack ( config , function ( ) {
@@ -52,17 +55,24 @@ describe('git-revision-webpack-plugin (integration)', function () {
5255 expect ( COMMITHASH . toString ( ) ) . to . eql ( '9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2' )
5356 } )
5457
55- describe ( '[git-revision-version] and [git-revision-hash] templates' , function ( ) {
58+ it ( 'should create the BRANCH file' , function ( ) {
59+ var branchPath = path . join ( targetBuild , 'BRANCH' )
60+ var BRANCH = fs . readFileSync ( branchPath )
61+
62+ expect ( BRANCH . toString ( ) ) . to . eql ( 'master' )
63+ } )
64+
65+ describe ( '[git-revision-version], [git-revision-hash] and [git-revision-branch] templates' , function ( ) {
5666 it ( 'should support templates in the output.filename' , function ( ) {
57- var versionPath = path . join ( targetBuild , 'main-v1.0.0-1-g9a15b3b.js' )
67+ var versionPath = path . join ( targetBuild , 'main-master- v1.0.0-1-g9a15b3b.js' )
5868 fs . readFileSync ( versionPath )
5969 } )
6070
6171 it ( 'should support setting the public path' , function ( ) {
62- var versionPath = path . join ( targetBuild , 'main-v1.0.0-1-g9a15b3b.js' )
72+ var versionPath = path . join ( targetBuild , 'main-master- v1.0.0-1-g9a15b3b.js' )
6373 var mainJs = fs . readFileSync ( versionPath )
6474
65- var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
75+ var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/ v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
6676
6777 expect ( mainJs . indexOf ( expectedPublicPath ) !== - 1 ) . to . eql ( true )
6878 } )
@@ -78,6 +88,11 @@ describe('git-revision-webpack-plugin (integration)', function () {
7888 var plugin = new GitRevisionPlugin ( { gitWorkTree : targetProject } )
7989 expect ( plugin . version ( ) ) . to . eql ( 'v1.0.0-1-g9a15b3b' )
8090 } )
91+
92+ it ( 'should expose the branch' , ( ) => {
93+ var plugin = new GitRevisionPlugin ( { gitWorkTree : targetProject } )
94+ expect ( plugin . branch ( ) ) . to . eql ( 'master' )
95+ } )
8196 } )
8297} )
8398
@@ -96,7 +111,11 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
96111 config . context = targetProject
97112 config . output . path = targetBuild
98113 config . plugins = [
99- new GitRevisionPlugin ( { gitWorkTree : targetProject , lightweightTags : true } )
114+ new GitRevisionPlugin ( {
115+ gitWorkTree : targetProject ,
116+ lightweightTags : true ,
117+ branch : true
118+ } )
100119 ]
101120
102121 webpack ( config , function ( ) {
@@ -118,17 +137,24 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
118137 expect ( COMMITHASH . toString ( ) ) . to . eql ( '9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2' )
119138 } )
120139
121- describe ( '[git-revision-version] and [git-revision-hash] templates' , function ( ) {
140+ it ( 'should create the BRANCH file' , function ( ) {
141+ var branchPath = path . join ( targetBuild , 'BRANCH' )
142+ var BRANCH = fs . readFileSync ( branchPath )
143+
144+ expect ( BRANCH . toString ( ) ) . to . eql ( 'master' )
145+ } )
146+
147+ describe ( '[git-revision-version], [git-revision-hash] and [git-revision-branch] templates' , function ( ) {
122148 it ( 'should support templates in the output.filename' , function ( ) {
123- var versionPath = path . join ( targetBuild , 'main-v2.0.0-beta.js' )
149+ var versionPath = path . join ( targetBuild , 'main-master- v2.0.0-beta.js' )
124150 fs . readFileSync ( versionPath )
125151 } )
126152
127153 it ( 'should support setting the public path' , function ( ) {
128- var versionPath = path . join ( targetBuild , 'main-v2.0.0-beta.js' )
154+ var versionPath = path . join ( targetBuild , 'main-master- v2.0.0-beta.js' )
129155 var mainJs = fs . readFileSync ( versionPath )
130156
131- var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
157+ var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/ v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
132158
133159 expect ( mainJs . indexOf ( expectedPublicPath ) !== - 1 ) . to . eql ( true )
134160 } )
@@ -144,6 +170,55 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
144170 var plugin = new GitRevisionPlugin ( { gitWorkTree : targetProject , lightweightTags : true } )
145171 expect ( plugin . version ( ) ) . to . eql ( 'v2.0.0-beta' )
146172 } )
173+
174+ it ( 'should expose the branch' , ( ) => {
175+ var plugin = new GitRevisionPlugin ( { gitWorkTree : targetProject , lightweightTags : true } )
176+ expect ( plugin . branch ( ) ) . to . eql ( 'master' )
177+ } )
147178 } )
148179} )
149180
181+ describe ( 'git-revision-webpack-plugin without branch option' , function ( ) {
182+ beforeEach ( function ( done ) {
183+ fs . emptyDirSync ( targetProject )
184+ fs . copySync ( sourceProject , targetProject )
185+
186+ fs . emptyDirSync ( targetGitRepository )
187+ fs . copySync ( sourceGitRepository , targetGitRepository )
188+
189+ fs . remove ( targetBuild )
190+
191+ var config = require ( targetProjectConfig )
192+
193+ config . context = targetProject
194+ config . output . path = targetBuild
195+ config . plugins = [
196+ new GitRevisionPlugin ( {
197+ gitWorkTree : targetProject
198+ } )
199+ ]
200+
201+ webpack ( config , function ( ) {
202+ done ( )
203+ } )
204+ } )
205+
206+ it ( 'should create the VERSION file' , function ( ) {
207+ var versionPath = path . join ( targetBuild , 'VERSION' )
208+ var VERSION = fs . readFileSync ( versionPath )
209+
210+ expect ( VERSION . toString ( ) ) . to . eql ( 'v1.0.0-1-g9a15b3b' )
211+ } )
212+
213+ it ( 'should create the COMMITHASH file' , function ( ) {
214+ var versionPath = path . join ( targetBuild , 'COMMITHASH' )
215+ var COMMITHASH = fs . readFileSync ( versionPath )
216+
217+ expect ( COMMITHASH . toString ( ) ) . to . eql ( '9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2' )
218+ } )
219+
220+ it ( 'should not create the BRANCH file' , function ( ) {
221+ var branchPath = path . join ( targetBuild , 'BRANCH' )
222+ expect ( fs . existsSync ( branchPath ) ) . to . eql ( false )
223+ } )
224+ } )
0 commit comments