Skip to content

Commit 18624d8

Browse files
committed
Add branch name tests
1 parent 14e3a53 commit 18624d8

3 files changed

Lines changed: 63 additions & 12 deletions

File tree

fixtures/project/webpack.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module.exports = {
22
entry: './index.js',
33

44
output: {
5-
publicPath: 'http://cdn.com/assets/[git-revision-version]/[git-revision-hash]',
6-
filename: '[name]-[git-revision-version].js'
5+
publicPath: 'http://cdn.com/assets/[git-revision-branch]/[git-revision-version]/[git-revision-hash]',
6+
filename: '[name]-[git-revision-branch]-[git-revision-version].js'
77
},
88

99
module: {
1010
loaders: [
1111
{
1212
test: /\.(txt)$/,
13-
loader: 'file?name=[name][git-revision-version].[ext]'
13+
loader: 'file?name=[name]-[git-revision-branch]-[git-revision-version].[ext]'
1414
}
1515
]
1616
}

lib/index.integration.spec.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,24 @@ describe('git-revision-webpack-plugin (integration)', function () {
5252
expect(COMMITHASH.toString()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2')
5353
})
5454

55-
describe('[git-revision-version] and [git-revision-hash] templates', function () {
55+
it('should create the BRANCH file', function () {
56+
var branchPath = path.join(targetBuild, 'BRANCH')
57+
var BRANCH = fs.readFileSync(branchPath)
58+
59+
expect(BRANCH.toString()).to.eql('master')
60+
})
61+
62+
describe('[git-revision-version], [git-revision-hash] and [git-revision-branch] templates', function () {
5663
it('should support templates in the output.filename', function () {
57-
var versionPath = path.join(targetBuild, 'main-v1.0.0-1-g9a15b3b.js')
64+
var versionPath = path.join(targetBuild, 'main-master-v1.0.0-1-g9a15b3b.js')
5865
fs.readFileSync(versionPath)
5966
})
6067

6168
it('should support setting the public path', function () {
62-
var versionPath = path.join(targetBuild, 'main-v1.0.0-1-g9a15b3b.js')
69+
var versionPath = path.join(targetBuild, 'main-master-v1.0.0-1-g9a15b3b.js')
6370
var mainJs = fs.readFileSync(versionPath)
6471

65-
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
72+
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
6673

6774
expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true)
6875
})
@@ -78,6 +85,11 @@ describe('git-revision-webpack-plugin (integration)', function () {
7885
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject })
7986
expect(plugin.version()).to.eql('v1.0.0-1-g9a15b3b')
8087
})
88+
89+
it('should expose the branch', () => {
90+
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject })
91+
expect(plugin.branch()).to.eql('master')
92+
})
8193
})
8294
})
8395

@@ -118,17 +130,24 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
118130
expect(COMMITHASH.toString()).to.eql('9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2')
119131
})
120132

121-
describe('[git-revision-version] and [git-revision-hash] templates', function () {
133+
it('should create the BRANCH file', function () {
134+
var branchPath = path.join(targetBuild, 'BRANCH')
135+
var BRANCH = fs.readFileSync(branchPath)
136+
137+
expect(BRANCH.toString()).to.eql('master')
138+
})
139+
140+
describe('[git-revision-version], [git-revision-hash] and [git-revision-branch] templates', function () {
122141
it('should support templates in the output.filename', function () {
123-
var versionPath = path.join(targetBuild, 'main-v2.0.0-beta.js')
142+
var versionPath = path.join(targetBuild, 'main-master-v2.0.0-beta.js')
124143
fs.readFileSync(versionPath)
125144
})
126145

127146
it('should support setting the public path', function () {
128-
var versionPath = path.join(targetBuild, 'main-v2.0.0-beta.js')
147+
var versionPath = path.join(targetBuild, 'main-master-v2.0.0-beta.js')
129148
var mainJs = fs.readFileSync(versionPath)
130149

131-
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
150+
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
132151

133152
expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true)
134153
})
@@ -144,6 +163,10 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
144163
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject, lightweightTags: true })
145164
expect(plugin.version()).to.eql('v2.0.0-beta')
146165
})
166+
167+
it('should expose the branch', () => {
168+
var plugin = new GitRevisionPlugin({ gitWorkTree: targetProject, lightweightTags: true })
169+
expect(plugin.branch()).to.eql('master')
170+
})
147171
})
148172
})
149-

lib/index.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,32 @@ describe('git-revision-webpack-plugin (unit)', function () {
7272
expect(runGitCommand.args[0][1]).to.eql('custom version command')
7373
})
7474
})
75+
76+
describe('on setting custom branch command', function () {
77+
it('should run the build on .apply', function () {
78+
var buildFile = sinon.spy()
79+
GitRevisionPlugin.__set__('buildFile', buildFile)
80+
81+
new GitRevisionPlugin({
82+
branchCommand: 'custom branch command'
83+
}).apply()
84+
85+
var branchCall = buildFile.args.find(function (calls) {
86+
return calls[4] === 'BRANCH'
87+
})
88+
89+
expect(branchCall[2]).to.eql('custom branch command')
90+
})
91+
92+
it('should run the custom git command on .version', function () {
93+
var runGitCommand = sinon.spy()
94+
GitRevisionPlugin.__set__('runGitCommand', runGitCommand)
95+
96+
new GitRevisionPlugin({
97+
branchCommand: 'custom branch command'
98+
}).branch()
99+
100+
expect(runGitCommand.args[0][1]).to.eql('custom branch command')
101+
})
102+
})
75103
})

0 commit comments

Comments
 (0)